Posted October 25, 201410 yr I'm having some problems with my custom furnace's inventory. The idea is that cobblestone goes in the bottom slot and fills up a meter. Items go in the slot above that and different items come out the other side. Recipes are working with it, however the cobblestone system is very broken (won't ever accept the last piece of cobblestone, if you take the last piece out it treats it weirdly and when you stack it with any other cobblestone it just deletes the other half of the stack, meaning you will always have 1 piece of cobblestone). I'd also like to try and make it so that nothing can be placed in the output slot and only cobblestone can be placed in the cobblestone slot, which so far I have failed at. Here is the code for my tileentity: package roboguy99.foodTech.common.tile; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import roboguy99.foodTech.GrindstoneRecipes; public class TileGrindstone extends TileEntity implements ISidedInventory { private ItemStack[] slot = new ItemStack[3]; //TODO: Remove stone system as it makes no sense public int maxStone = 16; public int stone = 0; public String customName; public void updateEntity() { ItemStack slotStone = getStackInSlot(1); //Check for stone in buffer and fill from itemstack in bottom slot if(slotStone != null && slotStone.getItem() == Item.getItemFromBlock(Blocks.cobblestone) && stone < maxStone) { this.stone++; slotStone.stackSize--; if (slotStone.stackSize <= 0) { slotStone = null; this.stone = 0; } } //Check for inventory contents and process any items if(!worldObj.isRemote && this.canProcess()) { this.processItem(); } } public int getStoneScaled(int scaled) { return (int) (this.stone * scaled / this.maxStone); } public ItemStack decrStackSize(int i, int j) { if(this.slot[i] != null) { ItemStack itemStack; if(this.slot[i].stackSize <= j) { itemStack = this.slot[i]; this.slot[i] = null; return itemStack; } else { itemStack = this.slot[i].splitStack(j); if(this.slot[i].stackSize == 0) { this.slot[i] = null; } return itemStack; } } return null; } public int getSizeInventory() { return this.slot.length; } public ItemStack getStackInSlot(int i) { return this.slot[i]; } public ItemStack getStackInSlotOnClosing(int i) { if(this.slot[i] != null) { ItemStack itemStack = this.slot[i]; this.slot[i] = null; return itemStack; } return null; } public String getInventoryName() { return this.hasCustomInventoryName() ? this.customName : "container.grindstone"; } public boolean hasCustomInventoryName() { return this.customName != null && this.customName.length() > 0; } public void closeInventory() { } public int getInventoryStackLimit() { return 64; } public boolean isItemValidForSlot(int slot, ItemStack itemStack) { return slot == 2 ? false : true; } public boolean isUseableByPlayer(EntityPlayer entityPlayer) { return true; } public void openInventory() { } public void setInventorySlotContents(int i, ItemStack itemStack) { this.slot[i] = itemStack; if(itemStack != null && itemStack.stackSize > this.getInventoryStackLimit()) { itemStack.stackSize = this.getInventoryStackLimit(); } } public boolean canExtractItem(int i, ItemStack var2, int j) { return true; } public boolean canInsertItem(int slot, ItemStack itemStack, int side) { return this.isItemValidForSlot(slot, itemStack); } public int[] getAccessibleSlotsFromSide(int i) { return null; } public static void addRecipe() { //TODO add recipes } /** * Returns true if the grindstone can smelt an item, i.e. has a source item, destination stack isn't full, etc. */ private boolean canProcess() { if (this.slot[0] == null || this.stone == 0) { return false; } else { ItemStack itemstack = GrindstoneRecipes.processing().getProcessResult(this.slot[0]); if (itemstack == null) return false; if (this.slot[2] == null) return true; if (!this.slot[2].isItemEqual(itemstack)) return false; int result = slot[2].stackSize + itemstack.stackSize; return result <= getInventoryStackLimit() && result <= this.slot[2].getMaxStackSize(); //Forge BugFix: Make it respect stack sizes properly. } } /** * Turn one item from the grindstone source stack into the appropriate processed item in the furnace result stack */ public void processItem() { if (this.canProcess()) { ItemStack itemstack = GrindstoneRecipes.processing().getProcessResult(this.slot[0]); if (this.slot[2] == null) { this.slot[2] = itemstack.copy(); } else if (this.slot[2].getItem() == itemstack.getItem()) { this.slot[2].stackSize += itemstack.stackSize; // Forge BugFix: Results may have multiple items } --this.slot[0].stackSize; --this.stone; System.out.println(this.stone); if (this.slot[0].stackSize <= 0) { this.slot[0] = null; } } } } I have no idea what I'm doing.
October 25, 201410 yr Remove the this.stone=0; line in your updateEntity() method, because else you will set the stone to 0 if the slot is emptied. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
October 25, 201410 yr Author Well this made stone act normally, but the last one in the stack still eternally remains and eternally fills up the meter. Thanks so far though. I have no idea what I'm doing.
October 25, 201410 yr Author Your stackSize == 0 check is broken. You only set the slotStone variable to null, but not the slot itself. You need to call setInventorySlotContents. Also you should call markDirty when the stack size changes (you don't need to do that if you reach 0, because setInventorySlotContents will call it). Ok I've tried this but I've got the same problem I had to start with. Here's my code now: package roboguy99.foodTech.common.tile; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import roboguy99.foodTech.GrindstoneRecipes; public class TileGrindstone extends TileEntity implements ISidedInventory { private ItemStack[] slot = new ItemStack[3]; private static final int MAX_STONE = 16; public int stone = 0; public String customName; public void updateEntity() { ItemStack slotStone = getStackInSlot(1); //Check for stone in buffer and fill from itemstack in bottom slot if(slotStone != null && slotStone.getItem() == Item.getItemFromBlock(Blocks.cobblestone) && stone < MAX_STONE) { this.stone += MAX_STONE; //1 cobblestone = 1 full tank slotStone.stackSize--; if (slotStone.stackSize <= 0) { slotStone = null; } } //Check for inventory contents and process any items if(!worldObj.isRemote && this.canProcess() && this.stone >= 1) { this.processItem(); this.markDirty(); } } public int getStoneScaled(int scaled) { return (int) (this.stone * scaled / TileGrindstone.MAX_STONE); } public ItemStack decrStackSize(int i, int j) { if(this.slot[i] != null) { ItemStack itemStack; if(this.slot[i].stackSize <= j) { itemStack = this.slot[i]; this.slot[i] = null; return itemStack; } else { itemStack = this.slot[i].splitStack(j); if(this.slot[i].stackSize == 0) { this.slot[i] = null; this.setInventorySlotContents(i, itemStack); } return itemStack; } } return null; } public ItemStack getStackInSlot(int i) { return this.slot[i]; } public ItemStack getStackInSlotOnClosing(int i) { if(this.slot[i] != null) { ItemStack itemStack = this.slot[i]; this.slot[i] = null; return itemStack; } return null; } public boolean isItemValidForSlot(int slot, ItemStack itemStack) { return slot == 2 ? false : true; } public boolean isUseableByPlayer(EntityPlayer entityPlayer) { return true; } public void setInventorySlotContents(int i, ItemStack itemStack) { this.slot[i] = itemStack; if(itemStack != null && itemStack.stackSize > this.getInventoryStackLimit()) { itemStack.stackSize = this.getInventoryStackLimit(); } } public boolean canExtractItem(int i, ItemStack var2, int j) { return true; } public boolean canInsertItem(int slot, ItemStack itemStack, int side) { return this.isItemValidForSlot(slot, itemStack); } public int[] getAccessibleSlotsFromSide(int i) { return null; } /** * Returns true if the grindstone can smelt an item, i.e. has a source item, destination stack isn't full, etc. */ private boolean canProcess() { if (this.slot[0] == null || this.stone == 0) { return false; } else { ItemStack itemstack = GrindstoneRecipes.processing().getProcessResult(this.slot[0]); if (itemstack == null) return false; if (this.slot[2] == null) return true; if (!this.slot[2].isItemEqual(itemstack)) return false; int result = slot[2].stackSize + itemstack.stackSize; return result <= getInventoryStackLimit() && result <= this.slot[2].getMaxStackSize(); //Forge BugFix: Make it respect stack sizes properly. } } /** * Turn one item from the grindstone source stack into the appropriate processed item in the furnace result stack */ public void processItem() { if (this.canProcess()) { ItemStack itemstack = GrindstoneRecipes.processing().getProcessResult(this.slot[0]); if (this.slot[2] == null) { this.slot[2] = itemstack.copy(); } else if (this.slot[2].getItem() == itemstack.getItem()) { this.slot[2].stackSize += itemstack.stackSize; // Forge BugFix: Results may have multiple items } --this.slot[0].stackSize; --this.stone; System.out.println(this.stone); if (this.slot[0].stackSize <= 0) { this.slot[0] = null; } } } public String getInventoryName() { return this.hasCustomInventoryName() ? this.customName : "container.grindstone"; } public boolean hasCustomInventoryName() { return this.customName != null && this.customName.length() > 0; } public int getInventoryStackLimit() { return 64; } public int getSizeInventory() { return this.slot.length; } public void openInventory() {} public void closeInventory() {} } I have no idea what I'm doing.
October 25, 201410 yr Your stackSize == 0 check is broken. You only set the slotStone variable to null, but not the slot itself. You need to call setInventorySlotContents. Also you should call markDirty when the stack size changes (you don't need to do that if you reach 0, because setInventorySlotContents will call it). Ok I've tried this but I've got the same problem I had to start with. Here's my code now: snip I believe he is referring to the check in updateEntity() if (slotStone.stackSize <= 0) { slotStone = null; } Should be if (slotStone.stackSize <= 0) { slotStone = null; this.setInventorySlotContents(1, null); } looks right but I could be wrong. HOLD A MOMENT ok he was probably referring to decrStackSize. notice, you put this.setInventorySlotContents(i, itemStack); it should be this.setInventorySlotContents(i, null); that sound right to the code gods? even though he didn't mention updateEntity() i think you should probably do that anyway. An average guy who mods Minecraft. If you need help and are willing to use your brain, don't be afraid to ask. Also, check out the Unofficial Minecraft Coder Pack (MCP) Prerelease Center for the latest from the MCP Team! Was I helpful? Leave some karma/thanks!
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.