Jump to content

Random furnace output


Jeerdus

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;
	}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;
	}

Link to comment
Share on other sites

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



×
×
  • Create New...

Important Information

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