Posted May 20, 201312 yr So i have a furnace. However, the recipe doesn't work. I have tried outputting canSmelt() to console, and it seems to be printing true when necessary. TileEntity package crzyguitardude.crazyfoods.gui; import cpw.mods.fml.common.registry.GameRegistry; import crzyguitardude.crazyfoods.MicrowaveRecipes; import crzyguitardude.crazyfoods.block.BlockMicrowave; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemHoe; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraft.item.ItemTool; import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; public class TileEntityMicrowave extends TileEntity implements IInventory { private ItemStack[] inv; public int furnaceBurnTime = 0; public int currentItemBurnTime = 0; /** The number of ticks that the current item has been cooking for */ public int furnaceCookTime = 0; public TileEntityMicrowave() { inv = new ItemStack[4]; } @Override public int getSizeInventory() { return inv.length; } @Override public ItemStack getStackInSlot(int slot) { return inv[slot]; } @Override public void setInventorySlotContents(int slot, ItemStack stack) { inv[slot] = stack; if (stack != null && stack.stackSize > getInventoryStackLimit()) { stack.stackSize = getInventoryStackLimit(); } } @Override public ItemStack decrStackSize(int slot, int amt) { ItemStack stack = getStackInSlot(slot); if (stack != null) { if (stack.stackSize <= amt) { setInventorySlotContents(slot, null); } else { stack = stack.splitStack(amt); if (stack.stackSize == 0) { setInventorySlotContents(slot, null); } } } return stack; } @Override public ItemStack getStackInSlotOnClosing(int slot) { ItemStack stack = getStackInSlot(slot); if (stack != null) { setInventorySlotContents(slot, null); } return stack; } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64; } @Override public void openChest() {} @Override public void closeChest() {} @Override public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); NBTTagList tagList = tagCompound.getTagList("Inventory"); for (int i = 0; i < tagList.tagCount(); i++) { NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i); byte slot = tag.getByte("Slot"); if (slot >= 0 && slot < inv.length) { inv[slot] = ItemStack.loadItemStackFromNBT(tag); } } } @Override public void writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); NBTTagList itemList = new NBTTagList(); for (int i = 0; i < inv.length; i++) { ItemStack stack = inv[i]; if (stack != null) { NBTTagCompound tag = new NBTTagCompound(); tag.setByte("Slot", (byte) i); stack.writeToNBT(tag); itemList.appendTag(tag); } } tagCompound.setTag("Inventory", itemList); } public int getCookProgressScaled(int par1) { return this.furnaceCookTime * par1 / 200; } public int getBurnTimeRemainingScaled(int par1) { if (this.currentItemBurnTime == 0) { this.currentItemBurnTime = 200; } return this.furnaceBurnTime * par1 / this.currentItemBurnTime; } public boolean isBurning() { return this.furnaceBurnTime > 0; } public void updateEntity() { boolean flag = this.furnaceBurnTime > 0; boolean flag1 = false; if (this.furnaceBurnTime > 0) { --this.furnaceBurnTime; } if (!this.worldObj.isRemote) { if (this.furnaceBurnTime == 0 && this.canSmelt()) { this.currentItemBurnTime = this.furnaceBurnTime = getItemBurnTime(this.inv[1]); if (this.furnaceBurnTime > 0) { flag1 = true; if (this.inv[1] != null && this.inv[3] != null) { --this.inv[1].stackSize; --this.inv[3].stackSize; if (this.inv[1].stackSize == 0 && this.inv[3].stackSize == 0) { this.inv[1] = this.inv[1].getItem().getContainerItemStack(inv[1]); this.inv[3] = this.inv[3].getItem().getContainerItemStack(inv[3]); } } } } if (this.isBurning() && this.canSmelt()) { ++this.furnaceCookTime; if (this.furnaceCookTime == 200) { this.furnaceCookTime = 0; this.smeltItem(); flag1 = true; } } else { this.furnaceCookTime = 0; } if (flag != this.furnaceBurnTime > 0) { flag1 = true; BlockMicrowave.updateFurnaceBlockState(this.furnaceBurnTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord); } } if (flag1) { this.onInventoryChanged(); } System.out.println(this.canSmelt()); } /** * Returns true if the furnace can smelt an item, i.e. has a source item, destination stack isn't full, etc. */ private boolean canSmelt() { if (this.inv[0] == null) { return false; } else { if(this.inv[1] != null && this.inv[3] != null) { ItemStack itemstack = MicrowaveRecipes.cooking().getCookingResult(this.inv[1].getItem().itemID, this.inv[3].getItem().itemID); if (itemstack == null) return false; if (this.inv[2] == null) return true; if (!this.inv[2].isItemEqual(itemstack)) return false; int result = inv[2].stackSize + itemstack.stackSize; return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize()); } return false; } } /** * Turn one item from the furnace source stack into the appropriate smelted item in the furnace result stack */ public void smeltItem() { if (this.canSmelt()) { ItemStack itemstack = MicrowaveRecipes.cooking().getCookingResult(this.inv[1].getItem().itemID, this.inv[3].getItem().itemID); if (this.inv[2] == null) { this.inv[2] = itemstack.copy(); } else if (this.inv[2].isItemEqual(itemstack)) { inv[2].stackSize += itemstack.stackSize; } --this.inv[0].stackSize; if (this.inv[0].stackSize <= 0) { this.inv[0] = null; } } } /** * Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if the item isn't * fuel */ public static int getItemBurnTime(ItemStack itemstack) { if(itemstack == null) { return 0; } int i = itemstack.getItem().itemID; if (i == Item.redstone.itemID) { return 400; } else { return 0; } } /** * Return true if item is a fuel source (getItemBurnTime() > 0). */ public static boolean isItemFuel(ItemStack par0ItemStack) { return getItemBurnTime(par0ItemStack) > 0; } @Override public String getInvName() { return "crazyfoods.tileentitymicrowave"; } @Override public boolean isInvNameLocalized() { return false; } @Override public boolean isStackValidForSlot(int i, ItemStack itemstack) { return false; } } Container package crzyguitardude.crazyfoods.gui; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.inventory.SlotFurnace; import net.minecraft.item.ItemStack; public class ContainerMicrowave extends Container { protected TileEntityMicrowave tileEntity; public ContainerMicrowave (InventoryPlayer par1InventoryPlayer, TileEntityMicrowave te) { tileEntity = te; //right = positive, down = positive //fuel addSlotToContainer(new Slot(te, 0, 46, 53)); //right input addSlotToContainer(new Slot(te, 1, 56, 17)); //left input addSlotToContainer(new Slot(te, 3, 37, 17)); //output addSlotToContainer(new SlotMicrowave(par1InventoryPlayer.player, te, 2, 116, 35)); //commonly used vanilla code that adds the player's inventory bindPlayerInventory(par1InventoryPlayer); } @Override public boolean canInteractWith(EntityPlayer player) { return tileEntity.isUseableByPlayer(player); } protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 9; j++) { addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } for (int i = 0; i < 9; i++) { addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142)); } } @Override public ItemStack transferStackInSlot(EntityPlayer player, int slot) { ItemStack stack = null; Slot slotObject = (Slot) inventorySlots.get(slot); //null checks and checks if the item can be stacked (maxStackSize > 1) if (slotObject != null && slotObject.getHasStack()) { ItemStack stackInSlot = slotObject.getStack(); stack = stackInSlot.copy(); //merges the item into player inventory since its in the tileEntity if (slot < 9) { if (!this.mergeItemStack(stackInSlot, 9, 45, true)) { return null; } } //places it into the tileEntity is possible since its in the player inventory else if (!this.mergeItemStack(stackInSlot, 0, 9, false)) { return null; } if (stackInSlot.stackSize == 0) { slotObject.putStack(null); } else { slotObject.onSlotChanged(); } if (stackInSlot.stackSize == stack.stackSize) { return null; } slotObject.onPickupFromSlot(player, stackInSlot); } return stack; } } MicrowaveRecipes // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov. // Jad home page: http://www.kpdus.com/jad.html // Decompiler options: packimports(3) braces deadcode package crzyguitardude.crazyfoods; import java.util.HashMap; import java.util.Map; import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; // Referenced classes of package net.minecraft.src: // Block, ItemStack, Item public class MicrowaveRecipes { public static final MicrowaveRecipes cooking() { return cookingBase; } private MicrowaveRecipes() { cookingList = new HashMap(); addCooking(Item.bucketMilk.itemID, Item.bucketEmpty.itemID, new ItemStack(Block.blockDiamond)); } public void addCooking(int input1, int input2, ItemStack output) { // StringBuffer to create the unique key StringBuffer sb= new StringBuffer(32); // create a String in case of the stone-gras->diamond recipe it would be 1_2 // note: (addInfusingRecipe(1,2,new ItemStack (Item.diamond)))==(addInfusingRecipe(2,1,new ItemStack (Item.diamond))) // so you don`t have to worry about the order of the 1st and 2nd input sb.append(Math.min(input1,input2)).append("_").append(Math.max(input1,input2)); cookingList.put(sb.toString(), output); } public ItemStack getCookingResult(int input1, int input2) { StringBuffer sb= new StringBuffer(32); // gets the resulting ItemStack of the recipe sb.append(Math.min(input1,input2)).append("_").append(Math.max(input1,input2)); return (ItemStack) cookingList.get(sb.toString()); } public Map getCookingList() { return cookingList; } private static final MicrowaveRecipes cookingBase = new MicrowaveRecipes(); private Map cookingList; } Any help is appreciated.
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.