Posted November 16, 20195 yr I have coded a custom generator and it functions 100% correctly apart from one issue. When a hopper is attached and fuel items fed in, the first item is consumed without producing any energy. This does not happen when fuel items are added via the inventory. The relevant code: public class TileEntityGenerator extends TileEntity implements ITickable { public ItemStackHandler handler = new ItemStackHandler(1); public EnergyStorage storage = new EnergyStorage(100000); // energy is used as an easy means of saving level of storage to NBT. public int energy = storage.getEnergyStored(); public int burnTime = 0; public int maxItemBurnTime = 0; public int producingEnergy; @Override public void update() { if (burnTime == 0 && !handler.getStackInSlot(0).isEmpty() ) { maxItemBurnTime = getItemMaxBurnTime(handler.getStackInSlot(0)); } IBlockState iblockstate = world.getBlockState(pos); final int FLAGS = 3; // Block update + send change to clients. world.notifyBlockUpdate(pos, iblockstate, iblockstate, FLAGS); producingEnergy = 0; if ( maxItemBurnTime > 0 && !(storage.getEnergyStored() == storage.getMaxEnergyStored()) ) { if (burnTime == 0) {handler.getStackInSlot(0).shrink(1);} producingEnergy = 1; burnTime++; storage.receiveEnergy(20, false); energy += 20; if (burnTime >= maxItemBurnTime) { burnTime = 0; maxItemBurnTime = 0; } } } // returns the number of ticks the given item will burn. Returns 0 if the given item is not a valid fuel public static short getItemMaxBurnTime(ItemStack stack) { int burntime = TileEntityFurnace.getItemBurnTime(stack); // just use the vanilla values return (short)MathHelper.clamp(burntime, 0, Short.MAX_VALUE); } If I remove the line: if (burnTime == 0) {handler.getStackInSlot(0).shrink(1);} The item is actually fed in from the hopper, which seems to indicate that the issue is with my code block rather than with Item Handlers, etc. My Capabilities just in case: @SuppressWarnings("unchecked") @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if(capability == CapabilityEnergy.ENERGY) return (T)this.storage; if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return (T)this.handler; return super.getCapability(capability, facing); } @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if(capability == CapabilityEnergy.ENERGY) return true; if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return true; return super.hasCapability(capability, facing); } This is my first forray into using Capabilities, but my limited understanding looking through the hopper code tells me that it drives the fuel item insert, so I wonder if this could cause an issue. I welcome any help, as I'm stumped with this one at the moment.
November 16, 20195 yr Author Thanks for pointing those out, I will rethink & rewrite with both points in mind. This illustrates once again the danger of using popular modding guides/examples to model ones code on, as all 3 I looked through do this ItemStack modification & run the update code on both client & server.
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.