Advertisement
Guest User

ValaniumChestContainer

a guest
Sep 23rd, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.13 KB | None | 0 0
  1. import fr.fuulys.valamod.tiles.TileValaniumChest;
  2. import java.util.List;
  3. import net.minecraft.entity.player.EntityPlayer;
  4. import net.minecraft.entity.player.InventoryPlayer;
  5. import net.minecraft.inventory.Container;
  6. import net.minecraft.inventory.Slot;
  7. import net.minecraft.item.ItemStack;
  8.  
  9. public class ValaniumChestContainer extends Container {
  10.     private TileValaniumChest tile;
  11.     private InventoryPlayer inventory;
  12.  
  13.     public ValaniumChestContainer(TileValaniumChest tile, InventoryPlayer inventory) {
  14.         this.inventory = inventory;
  15.         this.tile = tile;
  16.         tile.openInventory();
  17.         int i = 0;
  18.         for (i = 0; i < 9; i++) {
  19.             for (int j = 0; j < 12; j++) {
  20.                 addSlotToContainer(new Slot(tile, j + i * 12, 12 + j * 18, 8 + i * 18));
  21.             }
  22.         }
  23.  
  24.         bindPlayerInventory();
  25.     }
  26.  
  27.     private void bindPlayerInventory() {
  28.         for (int i = 0; i < 3; i++) {
  29.             for (int j = 0; j < 9; j++) {
  30.                 addSlotToContainer(new Slot(this.inventory, j + i * 9 + 9, 39 + j * 18, 174 + i * 18));
  31.             }
  32.         }
  33.         int i;
  34.         for (i = 0; i < 9; i++) {
  35.             addSlotToContainer(new Slot(this.inventory, i, 39 + i * 18, 232));
  36.         }
  37.     }
  38.  
  39.     public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
  40.         ItemStack stack = null;
  41.         Slot slots = (Slot) this.inventorySlots.get(slot);
  42.         if ((slots != null) && (slots.getHasStack())) {
  43.             ItemStack stack1 = slots.getStack();
  44.             stack = stack1.copy();
  45.             if (slot < 112) {
  46.                 if (!mergeItemStack(stack1, 112, 148, true)) {
  47.                     return null;
  48.                 }
  49.                 slots.onSlotChange(stack1, stack);
  50.             }
  51.             if (slot >= 112) {
  52.                 if (!mergeItemStack(stack1, 0, 108, false)) {
  53.                     return null;
  54.                 }
  55.                 slots.onSlotChange(stack1, stack);
  56.             }
  57.             if (stack1.stackSize == 0) {
  58.                 slots.putStack((ItemStack) null);
  59.             } else {
  60.                 slots.onSlotChanged();
  61.             }
  62.             if (stack1.stackSize == stack.stackSize) {
  63.                 return null;
  64.             }
  65.             slots.onPickupFromSlot(player, stack1);
  66.         }
  67.         return stack;
  68.     }
  69.  
  70.     public void onContainerClosed(EntityPlayer player) {
  71.         super.onContainerClosed(player);
  72.         this.tile.closeInventory();
  73.     }
  74.  
  75.     public boolean canInteractWith(EntityPlayer player) {
  76.         return this.tile.isUseableByPlayer(player);
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement