package main.flowstoneenergy.core.containers; import main.flowstoneenergy.tileentities.machines.TileEntityMachineLumberMill; import main.flowstoneenergy.tileentities.recipes.RecipesLumberMill; 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.SlotFurnaceOutput; import net.minecraft.item.ItemStack; public class ContainerMachineLumberMill extends Container { public ContainerMachineLumberMill(EntityPlayer player, TileEntityMachineLumberMill entity) { createSlots(entity, player); bindPlayerInventory(player.inventory); } @Override public boolean canInteractWith(EntityPlayer player) { return this.isUseableByPlayer(player); } private boolean isUseableByPlayer(EntityPlayer player) { return true; } private void createSlots(TileEntityMachineLumberMill tile, EntityPlayer player) { addSlotToContainer(new Slot(tile, 0, 52, 16)); addSlotToContainer(new SlotFurnaceOutput(player, tile, 1, 129, 34)); } @Override 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 == 1) { if (!this.mergeItemStack(itemstack1, 2, 38, true)) { return null; } slot.onSlotChange(itemstack1, itemstack); } else if (par2 != 0) { if (RecipesLumberMill.getRecipeFromStack(itemstack1) != null) { if (!this.mergeItemStack(itemstack1, 0, 1, false)) { return null; } } else if (par2 >= 2 && par2 < 29) { if (!this.mergeItemStack(itemstack1, 29, 38, false)) { return null; } } else if (par2 >= 29 && par2 < 38 && !this.mergeItemStack(itemstack1, 2, 29, false)) { return null; } } else if (!this.mergeItemStack(itemstack1, 2, 38, 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; } public void bindPlayerInventory(InventoryPlayer inv) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 9; j++) { addSlotToContainer(new Slot(inv, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } for (int i = 0; i < 9; i++) { addSlotToContainer(new Slot(inv, i, 8 + i * 18, 142)); } } }