Jump to content

[1.7.10] Furnace (machine) ItemStack input of more than one item


turbodiesel4598

Recommended Posts

Hello there,

 

I have been using copies of the vanilla FurnaceRecipes class, with additional methods to make use of the ore dictionary, but have always had the problem that the input ItemStack can only have a size of 1, unlike the output which can be as big as wanted - as an example, it seems to be impossible to have 2 sticks processed into 1 wooden plank - only 1 stick is used for the process. Is there an easy modification that can be made to the class to allow for these recipes, such as a modification to the getSmeltingResult or func_151397_a (something which I still don't fully understand anyway) methods?

 

Crusher recipe class if needed:

package com.nr.mod.crafting;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import com.nr.mod.blocks.NRBlocks;
import com.nr.mod.items.NRItems;

public class CrusherRecipes
{
    private static final CrusherRecipes smeltingBase = new CrusherRecipes();
    /** The list of smelting results. */
    private Map<ItemStack, ItemStack> smeltingList = new HashMap<ItemStack, ItemStack>();

    /**
     * Used to call methods addSmelting and getSmeltingResult.
     */
    public static CrusherRecipes smelting()
    {
        return smeltingBase;
    }

    private CrusherRecipes() {
    	//Ores to Gems and Dust
    	oreDust("Iron", 2);
    	oreDust("Gold", 2);
    	oreGem("Lapis", ;
    	oreGem("Diamond", 2);
    	oreDust("Redstone", ;
    	oreGem("Emerald", 2);
    	oreGem("Quartz", 2);
    	oreGem("Coal", 2);
    	oreDust("Copper", 2);
    	oreDust("Lead", 2);
    	oreDust("Tin", 2);
    	oreDust("Silver", 2);
    	oreDust("Lead", 2);
    	addRecipe("oreYellorite", "dustUranium", 2);
    	addRecipe("oreYellorium", "dustUranium", 2);
    	oreDust("Thorium", 2);
    	addRecipe("orePlutonium", new ItemStack(NRItems.material, 2, 33));
    	oreDust("Lithium", 2);
    	oreDust("Boron", 2);
    	oreDust("Aluminium", 2);
    	oreDust("Aluminum", 2);
    	addRecipe("oreCertusQuartz", "crystalCertusQuartz", 2);
    	addRecipe("oreCertusQuartzCharged", "crystalCertusQuartzCharged", 2);
    	oreDust("Zinc", 2);
    	oreDust("Platinum", 2);
    	oreDust("Shiny", 2);
    	oreDust("Osmium", 2);
    	oreGem("Silicon", 2);
    	oreDust("Titanium", 2);
    	oreDust("Desh", 2);
    	oreGem("Ruby", 2);
    	oreGem("Sapphire", 2);
    	oreGem("Peridot", 2);
    	oreDust("Iridium", 2);
    	oreDust("Sulphur", 2);
    	oreDust("Sulfur", 2);
    	oreDust("Saltpeter", 2);
    	oreDust("Nickel", 2);
    	oreDust("ManaInfused", 2);
    	
    	//Gems to Dust
    	gemDust("Lapis");
    	gemDust("Diamond");
    	gemDust("Emerald");
    	gemDust("Quartz");
    	gemDust("Coal");
    	gemDust("Apatite");
    	addRecipe("crystalCertusQuartz", "dustCertusQuartz", 1);
    	addRecipe("crystalCertusQuartzCharged", "dustCertusQuartz", 1);
    	addRecipe("crystalFluix", "dustFluix", 1);
    	
    	//Ingots to Dust
    	ingotDust("Iron");
    	ingotDust("Gold");
    	ingotDust("Copper");
    	ingotDust("Lead");
    	ingotDust("Tin");
    	ingotDust("Silver");
    	ingotDust("Uranium");
    	addRecipe("ingotYellorite", "dustUranium", 1);
    	addRecipe("ingotYellorium", "dustUranium", 1);
    	ingotDust("Thorium");
    	ingotDust("Bronze");
    	ingotDust("Lithium");
    	ingotDust("Boron");
    	ingotDust("Aluminium");
    	ingotDust("Aluminum");
    	ingotDust("Zinc");
    	ingotDust("Platinum");
    	ingotDust("Shiny");
    	ingotDust("Osmium");
    	ingotDust("Brass");
    	ingotDust("Electrum");
    	ingotDust("Steel");
    	ingotDust("Cyanite");
    	ingotDust("Plutonium");
    	ingotDust("Ludicrite");
    	ingotDust("Titanium");
    	ingotDust("Desh");
    	ingotDust("FluxedElectrum");
    	ingotDust("Nickel");
    	ingotDust("ManaInfused");
    	ingotDust("Invar");
    	ingotDust("Signalum");
    	ingotDust("Lumium");
    	ingotDust("Enderium");
    	
    	//Other Recipes
    	addRecipe("cobblestone", new ItemStack(Blocks.gravel, 1));
    	recipeSmelt(new ItemStack(Blocks.gravel), new ItemStack(Blocks.sand, 1));
    	addRecipe("stone", new ItemStack(Blocks.cobblestone, 1));
    	addRecipe("blockGlass", new ItemStack(Blocks.sand, 1));
    	addRecipe("sandstone", new ItemStack(Blocks.sand, 4));
    	addRecipe("glowstone", "dustGlowstone", 4);
    	recipeSmelt(new ItemStack(NRBlocks.graphiteBlock), new ItemStack(NRItems.material, 9, 14));
    	
    	//Lithium and Boron Cells
    	recipeSmelt(new ItemStack(NRItems.fuel, 1, 41), new ItemStack(NRItems.material, 1, 46));
    	recipeSmelt(new ItemStack(NRItems.fuel, 1, 42), new ItemStack(NRItems.material, 1, 47));
    	recipeSmelt(new ItemStack(NRItems.fuel, 1, 43), new ItemStack(NRItems.material, 1, 48));
    	recipeSmelt(new ItemStack(NRItems.fuel, 1, 44), new ItemStack(NRItems.material, 1, 49));
    }
    
    private void addRecipe(String ore, ItemStack out) {
    	ArrayList<ItemStack> tList = OreDictionary.getOres(ore);
    	for (int i = 0; i < tList.size(); i++) {
    	    ItemStack tStack = tList.get(i);
    	    tStack = tStack.copy();
    	    tStack.stackSize = 1;
    	    this.recipeSmelt(OreDictionary.getOres(ore).get(i), out);
    	}
    }
    
    private void addRecipe(String ore, String out, int amount) {
    	ArrayList<ItemStack> tList = OreDictionary.getOres(ore);
    	ArrayList<ItemStack> tList2 = OreDictionary.getOres(out);
    	if (tList2.size() > 0) {
    		ItemStack tStack2 = tList2.get(0);
    		tStack2 = tStack2.copy();
    		tStack2.stackSize = amount;
    		for (int i = 0; i < tList.size(); i++) {
    			ItemStack tStack = tList.get(i);
    			tStack = tStack.copy();
    			tStack.stackSize = 1;
    			this.recipeSmelt(OreDictionary.getOres(ore).get(i), tStack2);
    		}
    	}
    }
    
    private void oreDust(String type, int amount) {
    	ArrayList<ItemStack> tList = OreDictionary.getOres("ore"+type);
    	ArrayList<ItemStack> tList2 = OreDictionary.getOres("dust"+type);
    	if (tList2.size() > 0) {
    		ItemStack tStack2 = tList2.get(0);
    		tStack2 = tStack2.copy();
    		tStack2.stackSize = amount;
    		for (int i = 0; i < tList.size(); i++) {
    			ItemStack tStack = tList.get(i);
    			tStack = tStack.copy();
    			tStack.stackSize = 4;
    	    	this.recipeSmelt(OreDictionary.getOres("ore"+type).get(i), tStack2);
    		}
    	}
    }
    
    private void oreGem(String type, int amount) {
    	ArrayList<ItemStack> tList = OreDictionary.getOres("ore"+type);
    	ArrayList<ItemStack> tList2 = OreDictionary.getOres("gem"+type);
    	if (tList2.size() > 0) {
    		ItemStack tStack2 = tList2.get(0);
    		tStack2 = tStack2.copy();
    		tStack2.stackSize = amount;
    		for (int i = 0; i < tList.size(); i++) {
    			ItemStack tStack = tList.get(i);
    			tStack = tStack.copy();
    			tStack.stackSize = 1;
    			this.recipeSmelt(OreDictionary.getOres("ore"+type).get(i), tStack2);
    		}
    	}
    }
    
    private void gemDust(String type) {
    	ArrayList<ItemStack> tList = OreDictionary.getOres("gem"+type);
    	ArrayList<ItemStack> tList2 = OreDictionary.getOres("dust"+type);
    	if (tList2.size() > 0) {
    		ItemStack tStack2 = tList2.get(0);
    		tStack2 = tStack2.copy();
    		tStack2.stackSize = 1;
    		for (int i = 0; i < tList.size(); i++) {
    			ItemStack tStack = tList.get(i);
    			tStack = tStack.copy();
    			tStack.stackSize = 1;
    			this.recipeSmelt(OreDictionary.getOres("gem"+type).get(i), tStack2);
    		}
    	}
    }
    
    private void ingotDust(String type) {
    	ArrayList<ItemStack> tList = OreDictionary.getOres("ingot"+type);
    	ArrayList<ItemStack> tList2 = OreDictionary.getOres("dust"+type);
    	if (tList2.size() > 0) {
    		ItemStack tStack2 = tList2.get(0);
    		tStack2 = tStack2.copy();
    		tStack2.stackSize = 1;
    		for (int i = 0; i < tList.size(); i++) {
    			ItemStack tStack = tList.get(i);
    			tStack = tStack.copy();
    			tStack.stackSize = 1;
    			this.recipeSmelt(OreDictionary.getOres("ingot"+type).get(i), tStack2);
    		}
    	}
    }
    
    public void blockSmelt(Block block, ItemStack stack)
    {
        this.itemSmelt(Item.getItemFromBlock(block), stack);
    }

    public void itemSmelt(Item item, ItemStack itemstack)
    {
        this.recipeSmelt(new ItemStack(item, 1, 32767), itemstack);
    }

    public void recipeSmelt(ItemStack input, ItemStack output)
    {
        this.smeltingList.put(input, output);
    }

    /**
     * Returns the smelting result of an item.
     */
    public ItemStack getSmeltingResult(ItemStack stack)
    {
        Iterator<?> iterator = this.smeltingList.entrySet().iterator();
        Entry<?, ?> entry;

        do
        {
            if (!iterator.hasNext())
            {
                return null;
            }

            entry = (Entry<?, ?>)iterator.next();
        }
        while (!this.func_151397_a(stack, (ItemStack)entry.getKey()));

        return (ItemStack)entry.getValue();
    }

    private boolean func_151397_a(ItemStack input, ItemStack expected)
    {
        return expected == input && (expected.getItemDamage() == 32767 || expected.getItemDamage() == input.getItemDamage());
    }

    public Map<ItemStack, ItemStack> getSmeltingList()
    {
        return this.smeltingList;
    }
}

 

Thanks in advance for any ideas and help ;)

Link to comment
Share on other sites

Bump, and an update:

 

I have changed func_151397_a so that it also checks for the stacksize of the input, as suggested by a friend of mine:

private boolean func_151397_a(ItemStack input, ItemStack expected)
    {
        return expected.getItem() == input.getItem() && expected.stackSize == input.stackSize && (expected.getItemDamage() == 32767 || expected.getItemDamage() == input.getItemDamage());
    }

But all that has caused is only stacks of a size of 1 are processed in the machine.

Link to comment
Share on other sites

You need to write your own recipe handler to check for stack sizes.  Furnace recipes don't care how big the stack is.

 

So you'll need a way to check that a recipe is valid (ignoring stack size) and then get how big the input stack size is for the recipe and check that the slot has at least that many items and then remove that many items when it completes.

 

This is how I handled it.  It's likely not the best way, but I was working off of the vanilla furnace's handling.

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

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.