Jump to content

[1.7.2][unsolved]3 input furnace only looks at first item in crafting recipe


dude22072

Recommended Posts

So I tried make a 3 input furnace. When it smelts things it only looks at the first item in the crafting recipe, the other two slots can be anything. I don't know how to fix this as I don't know how tile entities work.

 

FYI: the inputs are slot 0, 3, and 4. Output is slot 1. I haven't got around to fixing this yet.

 

[spoiler=FermenterRecipes]

package dudesmods.fermentation.tileentity;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import dudesmods.fermentation.FermentationMod;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFishFood;
import net.minecraft.item.ItemStack;

public class FermenterRecipes
{
    private static final FermenterRecipes smeltingBase = new FermenterRecipes();
    /** The list of smelting results. */
    private Map smeltingList = new HashMap();
    private Map experienceList = new HashMap();
    private static final String __OBFID = "CL_00000085";
    
    /**
     * Used to call methods addSmelting and getSmeltingResult.
     */
    public static FermenterRecipes smelting()
    {
        return smeltingBase;
    }

    /**
     * Contains the recipes
     */
    private FermenterRecipes()
    {
    	this.addItemStackSmelting(new ItemStack(FermentationMod.vodka, 1), 0.5F, new Object[]{Items.potato, Items.potionitem, FermentationMod.yeastItem});
    	this.addItemStackSmelting(new ItemStack(FermentationMod.beer, 1), 0.5F, new Object[]{Blocks.reeds, Items.potionitem, FermentationMod.yeastItem});
    }
    
    public void addBlockSmelting(Block block, ItemStack itemstack, float XP)
    {
        this.addItemSmelting(Item.getItemFromBlock(block), itemstack, XP);
    }

    public void addItemSmelting(Item item, ItemStack itemstack, float XP)
    {
        this.addItemStackSmelting(itemstack, XP, new ItemStack(item, 1, 32767));
    }

    public void addItemStackSmelting(ItemStack itemstackOUT, float XP, Object ... itemstackInArray)
    {
        this.smeltingList.put(itemstackInArray, itemstackOUT);
        this.experienceList.put(itemstackOUT, Float.valueOf(XP));
    }

    /**
     * Returns the smelting result of an item.
     */
    public ItemStack getSmeltingResult(Object ... input1)
    {
        Iterator iterator = this.smeltingList.entrySet().iterator();
        Entry entry;

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

            entry = (Entry)iterator.next();
        }
        while (!this.func_151397_a());

        return (ItemStack)entry.getValue();
    }

    private boolean func_151397_a()
    {
        return true;
    }

    public Map getSmeltingList()
    {
        return this.smeltingList;
    }

    public float func_151398_b(ItemStack p_151398_1_)
    {
        float ret = p_151398_1_.getItem().getSmeltingExperience(p_151398_1_);
        if (ret != -1) return ret;

        Iterator iterator = this.experienceList.entrySet().iterator();
        Entry entry;

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

            entry = (Entry)iterator.next();
        }
        while (!this.func_151397_a());

        return ((Float)entry.getValue()).floatValue();
    }
}

 

 

[spoiler=TileEntityFermenter]

package dudesmods.fermentation.tileentity;

import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import cpw.mods.fml.common.registry.GameRegistry;
import dudesmods.fermentation.block.Fermenter;

public class TileEntityFermenter extends TileEntity implements ISidedInventory {

private String localizedName;

private static final int[] slots_top = new int[]{0};
private static final int[] slots_bottom = new int[]{2, 1};
private static final int[] slots_side = new int[]{1};

private ItemStack[] slots = new ItemStack [5];

public int furnaceSpeed = 150;
public int burnTime;
public int currentItemBurnTime;
public int cookTime;

public void setGuiDisplayName(String displayName) {
	this.localizedName = displayName;
}

public String getInventoryName() {
	return this.hasCustomInventoryName() ? this.localizedName : "container.fermenter";
}

public boolean hasCustomInventoryName() {
	return this.localizedName != null && this.localizedName.length() > 0;
}

public int getSizeInventory() {
	return this.slots.length;
}

@Override
public ItemStack getStackInSlot(int var1) {
	return this.slots[var1];
}

@Override
public ItemStack decrStackSize(int var1, int var2) {
	if(this.slots[var1] != null) {
		ItemStack itemstack;

		if(this.slots[var1].stackSize <= var2 ){
			itemstack = this.slots[var1];
			this.slots[var1] = null;
			return itemstack;
		}else{
			itemstack = this.slots[var1].splitStack(var2);

			if(this.slots[var1].stackSize == 0){
				this.slots[var1] = null;
			}

			return itemstack;
		}
	}else {
		return null;
	}
}

@Override
public ItemStack getStackInSlotOnClosing(int var1) {
	if(this.slots[var1] != null) {
		ItemStack itemstack = this.slots[var1];
		this.slots[var1] = null;
		return itemstack;
	}
	return null;
}

@Override
public void setInventorySlotContents(int var1, ItemStack var2) {
	this.slots[var1] = var2;

	if(var2 != null && var2.stackSize > this.getInventoryStackLimit()) {
		var2.stackSize = this.getInventoryStackLimit();
	}
}

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

@Override
public boolean isUseableByPlayer(EntityPlayer var1) {
	return this.worldObj.getTileEntity(xCoord, yCoord, zCoord) != this ? false : var1.getDistanceSq((double)xCoord +0.5D, (double)yCoord + 0.5D, (double)zCoord + 0.5D) <= 64.0D;
}

@Override
public void openInventory() {

}

@Override
public void closeInventory() {

}

@Override
public boolean isItemValidForSlot(int var1, ItemStack var2) {
	return  var1 == 2 ? false : (var1 == 1 ? isItemFuel(var2) : true);
}

public static boolean isItemFuel(ItemStack var1) {
	return getItemBurnTime(var1) > 0;
}

private static int getItemBurnTime(ItemStack var1) {
	if(var1 == null){
		return 0;
	}else{
		Item item = var1.getItem();

		if(item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air) {
			Block block = Block.getBlockFromItem(item);

			if(block == Blocks.sapling) return 100;
			if(block == Blocks.coal_block) return 14400;
		}
		if(item == Items.coal) return 1600;
		if(item == Items.stick) return 100;
		if(item == Items.lava_bucket) return 20000;
		if(item == Items.blaze_rod) return 2400;

	}
	return GameRegistry.getFuelValue(var1);
}

public void updateEntity() {
	boolean flag = this.burnTime > 0;
	boolean flag1 = false;

	if(this.isBurning()) {
		this.burnTime--;
	}
	if(!this.worldObj.isRemote) {
		if(this.burnTime == 0 && this.canSmelt()) {
			this.currentItemBurnTime = this.burnTime = getItemBurnTime(this.slots[1]);

			if(this.isBurning()){
				flag1 = true;

				if(this.slots[1] != null) {
					this.slots[1].stackSize--;

					if(this.slots[1].stackSize == 0) {
						this.slots[1] = this.slots[1].getItem().getContainerItem(this.slots[1]);
					}
				}
			}
		}
	}

	if(this.isBurning() && this.canSmelt()) {
		this.cookTime++;

		if(this.cookTime == this.furnaceSpeed) {
			this.cookTime = 0;
			this.smeltItem();
			flag1 = true;
		}else{

		}
		if(flag != this.isBurning()) {
			flag1 = true;
			Fermenter.updateFermenterBlockState(this.burnTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
		}
	}

	if(this.slots[0] == null) {
		this.cookTime = 0;
	}

	if(flag1) {
		this.markDirty();
	}
}

public boolean canSmelt() {
	if(this.slots[0] == null || this.slots[3] == null || this.slots[4] == null) {
		return false;
	}else{
		ItemStack itemstack = FermenterRecipes.smelting().getSmeltingResult(this.slots[0], this.slots[3], this.slots[4]);

		if(itemstack == null) {return false;}
		if(this.slots[2] == null) {return true;}
		if(!this.slots[2].isItemEqual(itemstack)) {return false;}

		int result = this.slots[2].stackSize + itemstack.stackSize;

		return (result <= getInventoryStackLimit() && result <= this.slots[2].getMaxStackSize());
	}
}

public void smeltItem() {
	if(this.canSmelt() == false) {

	}
	if (this.canSmelt() == true) {
		ItemStack itemstack = FermenterRecipes.smelting().getSmeltingResult(new Object[]{this.slots[0], this.slots[3], this.slots[4]});
		System.out.println(itemstack);
		if(this.slots[2] == null) {
			this.slots[2] = itemstack.copy();
		}else if(this.slots[2].getItem() == itemstack.getItem()) {
			this.slots[2].stackSize += itemstack.stackSize;
		}

		this.slots[0].stackSize--;this.slots[3].stackSize--;this.slots[4].stackSize--;

		if (this.slots[0].stackSize <= 0) {
			this.slots[0] = null;
		}
		if (this.slots[3].stackSize <= 0) {
			this.slots[3] = null;
		}
		if (this.slots[4].stackSize <= 0) {
			this.slots[4] = null;
		}
	}
}

public boolean isBurning() {
	return this.burnTime > 0;
}

@Override
public int[] getAccessibleSlotsFromSide(int var1) {
	return var1 == 0 ? slots_bottom : (var1 == 1 ? slots_top : slots_side);
}

@Override
public boolean canInsertItem(int var1, ItemStack var2, int var3) {
	return this.isItemValidForSlot(var1, var2);
}

@Override
public boolean canExtractItem(int var1, ItemStack var2, int var3) {
	return var3 != 0 || var1 != 1 || var2.getItem() == Items.bucket;
}

public int getBurnTimeRemainingScaled(int i) {
	if(this.currentItemBurnTime == 0) {
		this.currentItemBurnTime = this.furnaceSpeed;
	}
	return this.burnTime * i / this.currentItemBurnTime;
}

public int getCookProgressScaled(int i) {
	return this.cookTime * i / this.furnaceSpeed;
}

public void readFromNBT(NBTTagCompound nbt) {
	super.readFromNBT(nbt);

	NBTTagList list = nbt.getTagList("Items", 10);
	this.slots = new ItemStack[this.getSizeInventory()];

	for(int i = 0; i < list.tagCount(); i++) {
		NBTTagCompound compound = (NBTTagCompound) list.getCompoundTagAt(i);
		byte b = compound.getByte("Slot");

		if(b >= 0 && b < this.slots.length) {
			this.slots[b] = ItemStack.loadItemStackFromNBT(compound);
		}
	}

	this.burnTime = (int)nbt.getShort("BurnTime");
	this.cookTime = (int)nbt.getShort("CookTime");
	this.currentItemBurnTime = (int)nbt.getShort("CurrentBurnTime");

	if(nbt.hasKey("CustomName")) {
		this.localizedName = nbt.getString("CustomName");
	}
}

public void writeToNBT(NBTTagCompound nbt) {
	super.writeToNBT(nbt);

	nbt.setShort("BurnTime", (short)this.burnTime);
	nbt.setShort("CookTime", (short)this.cookTime);
	nbt.setShort("CurrentBurnTime", (short)this.currentItemBurnTime);

	NBTTagList list = new NBTTagList();

	for(int i = 0; i< this.slots.length; i++) {
		if(this.slots[i] != null) {
			NBTTagCompound compound = new NBTTagCompound();
			compound.setByte("Slot", (byte)i);
			this.slots[i].writeToNBT(compound);
			list.appendTag(compound);
		}
	}

	nbt.setTag("Items", list);

	if(this.hasCustomInventoryName()) {
		nbt.setString("CustomName", this.localizedName);
	}
}
}

 

 

[spoiler=ContainerFermenter]

package dudesmods.fermentation.container;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotFurnace;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.tileentity.TileEntityFurnace;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dudesmods.fermentation.tileentity.TileEntityFermenter;

public class ContainerFermenter extends Container {

private TileEntityFermenter fermenter;

public int lastBurnTime;
public int lastCurrentItemBurnTime;
public int lastCookTime;

public ContainerFermenter(InventoryPlayer inventory, TileEntityFermenter tileentity) {
	this.fermenter = tileentity;

	this.addSlotToContainer(new Slot(tileentity, 0, 56, 17));
	this.addSlotToContainer(new Slot(tileentity, 1, 56, 53));
	this.addSlotToContainer(new SlotFurnace(inventory.player, tileentity,  2, 116, 35));
	this.addSlotToContainer(new Slot(tileentity, 3, 37, 17));
	this.addSlotToContainer(new Slot(tileentity, 4, 75, 17));

	for(int i = 0; i < 3; i++) {
		for(int j = 0; j < 9; j++){
			this.addSlotToContainer(new Slot(inventory, j + i*9 + 9, 8 + j*18, 84 + i * 18));
		}
	}

	for(int i = 0; i < 9; i++) {
		this.addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 142));
	}
}

public void addCrafingToCrafters (ICrafting icrafting) {
	super.addCraftingToCrafters(icrafting);
	icrafting.sendProgressBarUpdate(this, 0, this.fermenter.cookTime);
	icrafting.sendProgressBarUpdate(this, 1, this.fermenter.burnTime);
	icrafting.sendProgressBarUpdate(this, 2, this.fermenter.currentItemBurnTime);
}

public void detectAndSendChanges() {
	super.detectAndSendChanges();
	for(int i = 0; i < this.crafters.size(); i++) {
		ICrafting icrafting = (ICrafting) this.crafters.get(i);

		if(this.lastCookTime != this.fermenter.cookTime) {
			icrafting.sendProgressBarUpdate(this, 0, this.fermenter.cookTime);
		}
		if(this.lastBurnTime != this.fermenter.burnTime) {
			icrafting.sendProgressBarUpdate(this, 1, this.fermenter.burnTime);
		}
		if(this.lastCurrentItemBurnTime != this.fermenter.currentItemBurnTime) {
			icrafting.sendProgressBarUpdate(this, 2, this.fermenter.currentItemBurnTime);
		}
	}

	this.lastCookTime = this.fermenter.cookTime;
	this.lastBurnTime = this.fermenter.burnTime;
	this.lastCurrentItemBurnTime = this.fermenter.currentItemBurnTime;
}

@SideOnly(Side.CLIENT)
public void updateProgressBar(int slot, int newValue) {
	if (slot == 0) {
		this.fermenter.cookTime = newValue;
	}

	if (slot == 1) {
		this.fermenter.burnTime = newValue;
	}

	if (slot == 2) {
		this.fermenter.currentItemBurnTime = newValue;
	}
}

 public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
    {
        ItemStack itemstack = null;
        Slot slot = (Slot)this.inventorySlots.get(par2);

        if (slot != null && slot.getHasStack())
        {
            ItemStack itemstack1 = slot.getStack();
            itemstack = itemstack1.copy();

            if (par2 == 2)
            {
                if (!this.mergeItemStack(itemstack1, 3, 39, true))
                {
                    return null;
                }

                slot.onSlotChange(itemstack1, itemstack);
            }
            else if (par2 != 1 && par2 != 0)
            {
                if (FurnaceRecipes.smelting().getSmeltingResult(itemstack1) != null)
                {
                    if (!this.mergeItemStack(itemstack1, 0, 1, false))
                    {
                        return null;
                    }
                }
                else if (TileEntityFurnace.isItemFuel(itemstack1))
                {
                    if (!this.mergeItemStack(itemstack1, 1, 2, false))
                    {
                        return null;
                    }
                }
                else if (par2 >= 3 && par2 < 30)
                {
                    if (!this.mergeItemStack(itemstack1, 30, 39, false))
                    {
                        return null;
                    }
                }
                else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
                {
                    return null;
                }
            }
            else if (!this.mergeItemStack(itemstack1, 3, 39, false))
            {
                return null;
            }

            if (itemstack1.stackSize == 0)
            {
                slot.putStack((ItemStack)null);
            }
            else
            {
                slot.onSlotChanged();
            }

            if (itemstack1.stackSize == itemstack.stackSize)
            {
                return null;
            }

            slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
        }

        return itemstack;
    }

@Override
public boolean canInteractWith(EntityPlayer var1) {
	return true;
}

}

 

 

Legend of Zelda Mod[updated September 20th to 3.1.1]

Extra Achievements(Minecraft 1.8!)[updated April 3rd to 2.3.0]

Fancy Cheeses[updated May 8th to 0.5.0]

Link to comment
Share on other sites

public ItemStack getSmeltingResult(Object ... input1)
    {
        Iterator iterator = this.smeltingList.entrySet().iterator();
        Entry entry;

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

            entry = (Entry)iterator.next();
        }
        while (!this.func_151397_a());

        return (ItemStack)entry.getValue();
    }

    private boolean func_151397_a()
    {
        return true;
    }

 

So... retrieve the first recipe and set it to "entry". If func_151397_a returns false repeat until..., but func_151397_a always returns true so we never repeat.

Now that we are no longer in the do... while loop we return entry.getValue().

 

Maybe you should compare the "entry" to that "input1" Object array you pass in? Or did I miss something vital in your code?

Link to comment
Share on other sites

public ItemStack getSmeltingResult(Object ... input1)
    {
        Iterator iterator = this.smeltingList.entrySet().iterator();
        Entry entry;

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

            entry = (Entry)iterator.next();
        }
        while (!this.func_151397_a());

        return (ItemStack)entry.getValue();
    }

    private boolean func_151397_a()
    {
        return true;
    }

 

So... retrieve the first recipe and set it to "entry". If func_151397_a returns false repeat until..., but func_151397_a always returns true so we never repeat.

Now that we are no longer in the do... while loop we return entry.getValue().

 

Maybe you should compare the "entry" to that "input1" Object array you pass in? Or did I miss something vital in your code?

 

Idk. I never worked with tile entitys before. I got a 1-input working so i tried to see if i could make it a 3. I have no experience with these things...

Legend of Zelda Mod[updated September 20th to 3.1.1]

Extra Achievements(Minecraft 1.8!)[updated April 3rd to 2.3.0]

Fancy Cheeses[updated May 8th to 0.5.0]

Link to comment
Share on other sites

You can just make a if statement too, that worked for me.

It is not the exact code I used, but it looks like it.

This code is just written in the browser.

 

public static Item getResult(Item item, Item item2, Item item3)
{ //change Item to Block if you want
     if(inputstacks.getItem() == item && inputstacks.getItem() == item2 && inputstacks.getItem() == item3)
     {//inputstacks are the inputs, you can use the getItemBlock (ore something like that) to get the block
            return something;
      }
      return null;
}

Coding, Testing, Smiling, Publishing!

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.