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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • The crash log keeps saying something about the tick rate. Can someone please help me fix?   ---- Minecraft Crash Report ---- // Everything's going to plan. No, really, that was supposed to happen. Time: 2024-06-21 16:24:55 Description: Exception in server tick loop java.lang.NullPointerException: Cannot invoke "com.cobblemon.mod.common.api.conditional.RegistryLikeCondition.fits(Object, net.minecraft.core.Registry)" because "condition" is null at com.cobblemon.mod.common.api.spawning.condition.SpawningCondition.fits(SpawningCondition.java:85) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.condition.AreaTypeSpawningCondition.fits(AreaTypeSpawningCondition.java:30) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.condition.GroundedTypeSpawningCondition.fits(GroundedTypeSpawningCondition.java:28) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.condition.GroundedTypeSpawningCondition.fits(GroundedTypeSpawningCondition.java:24) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.condition.SpawningCondition.isSatisfiedBy(SpawningCondition.java:68) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.detail.SpawnDetail.isSatisfiedBy(SpawnDetail.java:78) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.spawner.Spawner$DefaultImpls.getMatchingSpawns(Spawner.java:42) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.spawner.TickingSpawner.getMatchingSpawns(TickingSpawner.java:31) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.selection.FlatContextWeightedSelector.getSelectionData(FlatContextWeightedSelector.java:79) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.selection.FlatContextWeightedSelector.select(FlatContextWeightedSelector.java:106) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.spawner.AreaSpawner.run(AreaSpawner.java:94) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.spawner.TickingSpawner.tick(TickingSpawner.java:71) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.spawning.SpawnerManager.onServerTick(SpawnerManager.java:58) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.events.ServerTickHandler.onTick(ServerTickHandler.java:20) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.Cobblemon$initialize$7.invoke(Cobblemon.java:368) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.Cobblemon$initialize$7.invoke(Cobblemon.java:368) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.reactive.ObservableSubscription.handle(ObservableSubscription.java:16) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.common.api.reactive.SimpleObservable.emit(SimpleObservable.java:39) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.forge.event.ForgePlatformEventHandler.onTick(ForgePlatformEventHandler.kt:172) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading} at com.cobblemon.mod.forge.event.__ForgePlatformEventHandler_onTick_ServerTickEvent.invoke(.dynamic) ~[Cobblemon-forge-1.5.2+1.20.1.jar%23121!/:?] {re:classloading,pl:eventbus:B} at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:73) ~[eventbus-6.0.5.jar%2352!/:?] {} at net.minecraftforge.eventbus.EventBus.post(EventBus.java:315) ~[eventbus-6.0.5.jar%2352!/:?] {} at net.minecraftforge.eventbus.EventBus.post(EventBus.java:296) ~[eventbus-6.0.5.jar%2352!/:?] {} at net.minecraftforge.event.ForgeEventFactory.onPostServerTick(ForgeEventFactory.java:950) ~[forge-1.20.1-47.2.17-universal.jar%23138!/:?] {re:classloading} at net.minecraft.server.MinecraftServer.m_5705_(MinecraftServer.java:835) ~[server-1.20.1-20230612.114412-srg.jar%23133!/:?] {re:computing_frames,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B,re:mixin,pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:661) ~[server-1.20.1-20230612.114412-srg.jar%23133!/:?] {re:computing_frames,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B,re:mixin,pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.m_206580_(MinecraftServer.java:251) ~[server-1.20.1-20230612.114412-srg.jar%23133!/:?] {re:computing_frames,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B,re:mixin,pl:accesstransformer:B} at java.lang.Thread.run(Thread.java:840) ~[?:?] {re:mixin}
    • okay i've managed to fix it. looks like i made the stupidest error known to man. i hadn't installed forge to the client, which i assumed only affected the launcher which wouldn't affect me because i used a third party one. evidently not. the more you know
    • tried a fresh install of above and beyond with java 8 installed. got a popup that says "Error: Unable to access jarfile forge-1.16.5-36.2.8.jar". every good programmer knows getting a different error means you've made progress!
    • https://paste.ee/p/Ntb3m
    • Updated Graphics drivers, Tried reinstalling forge, but all to no avail. I am using the official curseforge launcher for it, but the minecraft launcher with forge gives me the same log anyway. Crash-Log: https://paste.ee/p/8Eyzz
  • Topics

×
×
  • Create New...

Important Information

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