package mekanism.common.inventory.container; import javax.annotation.Nonnull; import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge; import mekanism.common.tile.TileEntityDigitalMiner; import mekanism.common.util.ChargeUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; public class ContainerDigitalMiner extends ContainerMekanism { public ContainerDigitalMiner(InventoryPlayer inventory, TileEntityDigitalMiner tile) { super(tile, inventory); } @Nonnull @Override public ItemStack transferStackInSlot(EntityPlayer player, int slotID) { ItemStack stack = ItemStack.EMPTY; Slot currentSlot = inventorySlots.get(slotID); if (currentSlot != null && currentSlot.getHasStack()) { ItemStack slotStack = currentSlot.getStack(); stack = slotStack.copy(); if (ChargeUtils.canBeDischarged(slotStack)) { if (slotID > 27) { if (!mergeItemStack(slotStack, 27, 28, false)) { return ItemStack.EMPTY; } } else { if (!mergeItemStack(slotStack, 28, inventorySlots.size(), true)) { return ItemStack.EMPTY; } } } else { if (slotID < 27) { if (!mergeItemStack(slotStack, 28, inventorySlots.size(), true)) { return ItemStack.EMPTY; } } else if (!mergeItemStack(slotStack, 0, 27, false)) { return ItemStack.EMPTY; } } if (slotStack.getCount() == 0) { currentSlot.putStack(ItemStack.EMPTY); } else { currentSlot.onSlotChanged(); } if (slotStack.getCount() == stack.getCount()) { return ItemStack.EMPTY; } currentSlot.onTake(player, slotStack); } return stack; } @Override protected void addSlots() { for (int slotY = 0; slotY < 3; slotY++) { for (int slotX = 0; slotX < 9; slotX++) { addSlotToContainer(new Slot(tileEntity, slotX + slotY * 9, 8 + slotX * 18, 80 + slotY * 18)); } } addSlotToContainer(new SlotDischarge(tileEntity, 27, 152, 6)); } @Override protected int getInventoryOffset() { return 148; } }