package thinh.eligibleadapter.tile.inventory; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.items.ItemStackHandler; import thinh.eligibleadapter.tile.TileSolderingStation; public class ItemHandlerBase extends ItemStackHandler { private final TileEntity tile; public ItemHandlerBase(int size, TileEntity tile) { super(size); this.tile = tile; } @Override public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { if (!this.canInsert(slot, stack)) { return stack; } return super.insertItem(slot, stack, simulate); } @Override public ItemStack extractItem(int slot, int amount, boolean simulate) { if (!this.canExtract(slot, this.getStackInSlot(slot))) { return null; } return super.extractItem(slot, amount, simulate); } @Override protected void onContentsChanged(int slot) { super.onContentsChanged(slot); if (this.tile != null) { this.tile.markDirty(); } } @Override protected int getStackLimit(int slot, ItemStack stack) { return this.getStackLimit(); } @Override public ItemStack getStackInSlot(int slot) { assert this.tile != null; if (this.tile instanceof TileSolderingStation) { if (slot >= TileSolderingStation.contents.getSlots()) { return TileSolderingStation.craftMatrix.getStackInSlot(slot - TileSolderingStation.contents.getSlots()); } } return super.getStackInSlot(slot); } @Override public void setStackInSlot(int slot, ItemStack stack) { assert this.tile != null; if (this.tile instanceof TileSolderingStation) { if (slot >= TileSolderingStation.contents.getSlots()) { TileSolderingStation solderingStation = (TileSolderingStation) this.tile; solderingStation.craftMatrix.setStackInSlot(slot - TileSolderingStation.contents.getSlots(), stack); solderingStation.updateInput(); } } super.setStackInSlot(slot, stack); } public int getStackLimit() { return 64; } public boolean canInsert(int slot, ItemStack stack) { return true; } public boolean canExtract(int slot, ItemStack stack) { return true; } }