TheTorchMod/com/bernard/torch/gui/TorchRechargerContainer.java

103 lines
3.7 KiB
Java

/* */ package com.bernard.torch.gui;
/* */
/* */ import com.bernard.torch.api.ITorchRechargable;
/* */ import com.bernard.torch.blocks.tileentities.TorchRechargerTileEntity;
/* */ import com.bernard.torch.init.CoalStickAndTorchesRegister;
/* */ import java.util.List;
/* */ import net.minecraft.entity.player.EntityPlayer;
/* */ import net.minecraft.entity.player.InventoryPlayer;
/* */ import net.minecraft.inventory.Container;
/* */ import net.minecraft.inventory.IInventory;
/* */ import net.minecraft.inventory.Slot;
/* */ import net.minecraft.item.ItemStack;
/* */
/* */ public class TorchRechargerContainer extends Container
/* */ {
/* */ TorchRechargerTileEntity tile;
/* */
/* */ public TorchRechargerContainer(TorchRechargerTileEntity te, InventoryPlayer inventory)
/* */ {
/* 20 */ this.tile = te;
/* 21 */ this.tile.openChest();
/* 22 */ addSlotToContainer(new InputSlot(this.tile, 0, 14, 33));
/* 23 */ addSlotToContainer(new OutputSlot(this.tile, 1, 138, 33));
/* 24 */ bindPlayerInventory(inventory);
/* */ }
/* */
/* */ public void bindPlayerInventory(InventoryPlayer inventory)
/* */ {
/* 29 */ for (int i = 0; i < 3; i++) {
/* 30 */ for (int j = 0; j < 9; j++) {
/* 31 */ addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
/* */ }
/* */ }
/* 34 */ for (i = 0; i < 9; i++) {
/* 35 */ addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 142));
/* */ }
/* */ }
/* */
/* */ public boolean canInteractWith(EntityPlayer player)
/* */ {
/* 41 */ return this.tile.isUseableByPlayer(player);
/* */ }
/* */
/* */ public void onContainerClosed(EntityPlayer player)
/* */ {
/* 46 */ super.onContainerClosed(player);
/* 47 */ this.tile.closeChest();
/* */ }
/* */
/* */ public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex)
/* */ {
/* 52 */ ItemStack stack = null;
/* 53 */ Slot slot = (Slot)this.inventorySlots.get(slotIndex);
/* 54 */ if ((slot != null) && (slot.getHasStack())) {
/* 55 */ ItemStack stackBis = slot.getStack();
/* 56 */ stack = stackBis.copy();
/* 57 */ if (slotIndex < this.tile.getSizeInventory()) {
/* 58 */ if (!mergeItemStack(stackBis, this.tile.getSizeInventory(), this.inventorySlots.size(), true)) {
/* 59 */ return null;
/* */ }
/* 61 */ } else if (!mergeItemStack(stackBis, 0, this.tile.getSizeInventory(), false)) {
/* 62 */ return null;
/* */ }
/* 64 */ if (stackBis.stackSize == 0) {
/* 65 */ slot.putStack((ItemStack)null);
/* */ } else {
/* 67 */ slot.onSlotChanged();
/* */ }
/* */ }
/* 70 */ return stack;
/* */ }
/* */
/* */ public class InputSlot extends Slot
/* */ {
/* */ public InputSlot(IInventory inventory, int i, int j, int k) {
/* 76 */ super(i, j, k);
/* */ }
/* */
/* */ public boolean isItemValid(ItemStack stack)
/* */ {
/* 81 */ if (stack == null)
/* 82 */ return false;
/* 83 */ return CoalStickAndTorchesRegister.isRegistered(stack.getItem());
/* */ }
/* */ }
/* */
/* */ public class OutputSlot extends Slot
/* */ {
/* */ public OutputSlot(IInventory inventory, int i, int j, int k) {
/* 90 */ super(i, j, k);
/* */ }
/* */
/* */ public boolean isItemValid(ItemStack stack)
/* */ {
/* 95 */ if (stack == null)
/* 96 */ return false;
/* 97 */ return stack.getItem() instanceof ITorchRechargable;
/* */ }
/* */ }
/* */ }