Jump to content

Recommended Posts

Posted

Good day,

I made a fully functional double input furnace. Except now I want to make it so it creates random output. I suppose that I will need to make the output slot have maximum stack of 1, but in inventory I want for the items to stack.

So I am asking for your help:

How do I make the output slot have maximum stack of 1 and how to create the random output?

Posted

You want the results to be different (and random) and stack?

 

These two statements do not go together.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

He's asking how to limit the stack size to 1, so it wouldn't be stackable in the slot, while vanilla stacking behavior would still be in effect in the normal player inventory.

 

Since it's a furnace, you should have a TileEntity with this method in it already (assuming you implemented ISidedInventory, which you should have if you're making a furnace):

@Override
public int getInventoryStackLimit() {
return 64;
}

Do I need to say more?  :P

 

For the random output, how are you storing your recipes? Does it matter what the inputs are at all, or should it be totally random? If it's totally random, then one option would be to make a List of ItemStacks and use list.get(rand.nextInt(list.size())) to return a random stack from within the list.

Posted

Tried that, it limits all the slots (even the coal one)

Basicly I want to not stack it in the output slot, but stack it outside the slot (in inventory)

EDIT: And about those recipes, I'll show you an example:

Slot 1 = Item.arrow

Slot 2 = Item.bone

Output slot = 25% Item.ingotGold, 10% Item.ingotGold, 5% Item.diamond, 60% Block.cobblestone

And becouse the item couldn't stack, I want to limit only the output slot to 1 item at a time.

 

My recipes look like this:

private static ItemStack getOutput(int i, int j)
	{
		if (i == Elementum.uraniumItem.itemID && j == Elementum.ironCell.itemID)
		{
			return new ItemStack(Elementum.uraniumCell, 1);
		}
		return null;
	}

Posted

Then it's a matter of just not processing input when the output slot isn't null, and the disallowing of the player putting items in the output slot (which you can do in the Container).

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

Posted

I really recommend not making it hardcoded and creating a recipe list instead (unless the random items are the same for every input item off course).

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

Posted

So create a custom output slot with this method:

@Override
public int getSlotStackLimit() {
   return 1;
}

When adding slots to your Container, be sure to use your custom slot only for your output.

 

Look through the Slot class to see the other methods mentioned by MineMaarten - you will need them to prevent the player from putting things into the slot.

 

From your recipe code, it didn't look random at all. It's still a recipe requiring two specific items to return a specific output... I'd suggest you take a good look at the vanilla FurnaceRecipes class. Do you see where it returns the smelting result? Well, instead of returning a specific ItemStack, store a custom int or whatever in the HashMap that tells you what random list to pull the item from:

// I'll modify the vanilla for 2 itemstacks
public ItemStack getSmeltingResult(ItemStack item1, ItemStack item2) 
    {
        if (item1 == null || item2 == null) { return null; }

        int randomList = -1;

        if (metaSmeltingList.containsKey(Arrays.asList(item1.itemID, item1.getItemDamage(), item2.itemID, item2.getItemDamage()))
        randomList = metaSmeltingList.get(Arrays.asList(item1.itemID, item1.getItemDamage(), item2.itemID, item2.getItemDamage()));
        
        ItemStack output = null;

        switch(randomList) {
        case 1: // you put in an arrow and a stick or whatever
             // output = select from random list one containing gold, cobblestone, etc.
        case 2: // you put in dirt and gunpowder or whatever
             // output = select from random list two
        default: // for value of -1 or other unhandled cases

        return output;
       }
}

Something of that nature should work.

Posted

Alright. Fixed it now! Thank you everyone for your help :)

Used:

private static ItemStack getOutput(int i, int j)
	{
		if (i == Item.clay.itemID && j == Item.paper.itemID)
		{
			Random rand = new Random();
			int randNum = rand.nextInt(10);
			if(randNum == 1){
				return new ItemStack(Item.bone, 1);
			}
			if(randNum == 2){
				return new ItemStack(Item.stick, 1);
			}
			else{
			return new ItemStack(Item.arrow, 1);
			}
		}
		return null;
	}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • i managed to fix it by reinstalling the modpack and re-add all the extra mods I've had previously.
    • Ah, it appears I spoke too soon, I still need a little help here. I now have the forceloading working reliably.  However, I've realized it's not always the first tick that loads the entity.  I've seen it take anywhere from 2-20ish to actually go through, in which time my debugging has revealed that the chunk is loaded, but during which time calling  serverLevelIn.getEntity(uuidIn) returns a null result.  I suspect this has to do with queuing and how entities are loaded into the game.  While not optimal, it's acceptable, and I don't think there's a whole ton I can do to avoid it. However, my concern is that occasionally teleporting an entity in this manner causes a lag spike.  It's not every time and gives the appearance of being correlated with when other chunks are loading in.  It's also not typically a long spike, but can last a second or two, which is less than ideal.  The gist of how I'm summoning is here (although I've omitted some parts that weren't relevant.  The lag occurs before the actual summon so I'm pretty confident it's the loading, and not the actual summon call). ChunkPos chunkPos = new ChunkPos(entityPosIn); if (serverLevelIn.areEntitiesLoaded(chunkPos.toLong())) { boolean isSummoned = // The method I'm using for actual summoning is called here. Apart from a few checks, the bulk of it is shown later on. if (isSummoned) { // Code that runs here just notifies the player of the summon, clears it from the queue, and removes the forceload } } else { // I continue forcing the chunk until the summon succeeds, to make sure it isn't inadvertently cleared ForgeChunkManager.forceChunk(serverLevelIn, MODID, summonPosIn, chunkPos.x, chunkPos.z, true, true); } The summon code itself uses serverLevelIn.getEntity(uuidIn) to retrieve the entity, and moves it as such.  It is then moved thusly: if (entity.isAlive()) { entity.moveTo(posIn.getX(), posIn.getY(), posIn.getZ()); serverLevelIn.playSound(null, entity, SoundEvents.ENDERMAN_TELEPORT, SoundSource.NEUTRAL, 1.0F, 1.0F); return true; } I originally was calling .getEntity() more frequently and didn't have the check for whether or not entities were loaded in place to prevent unnecessary code calls, but even with those safety measures in place, the lag still persists.  Could this just be an issue with 1.18's lack of optimization in certain areas?  Is there anything I can do to mitigate it?  Is there a performance boosting mod I could recommend alongside my own to reduce the chunk loading lag? At the end of the day, it does work, and I'm putting measures in place to prevent players from abusing the system to cause lag (i.e. each player can only have one queued summon at a time-- trying to summon another replaces the first call).  It's also not an unacceptable level of lag, IMO, given the infrequency of such calls, and the fact that I'm providing the option to toggle off the feature if server admins don't want it used.  However, no amount of lag is ideal, so if possible I'd love to find a more elegant solution-- or at least a mod recommendation to help improve it. Thanks!
    • When i start my forge server its on but when i try to join its come a error Internal Exception: java.lang.OutOfMemoryError: Requested array size exceeds VM limit Server infos: Linux Minecraft version 1.20.1 -Xmx11G -Xms8G
    • Also add the latest.log from your logs-folder
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.