Advertisement
Cypher121

Container

Oct 9th, 2015
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 KB | None | 0 0
  1. package com.cout970.magneticraft.container;
  2.  
  3. import com.cout970.magneticraft.tileentity.shelf.TileShelvingUnit;
  4. import com.cout970.magneticraft.util.InventoryComponent;
  5. import net.minecraft.entity.player.EntityPlayer;
  6. import net.minecraft.entity.player.InventoryPlayer;
  7. import net.minecraft.inventory.Slot;
  8. import net.minecraft.item.ItemStack;
  9. import net.minecraft.tileentity.TileEntity;
  10.  
  11. import java.util.Arrays;
  12.  
  13. import static com.cout970.magneticraft.tileentity.shelf.TileShelvingUnit.CRATE_SIZE;
  14. import static com.cout970.magneticraft.tileentity.shelf.TileShelvingUnit.MAX_CRATES;
  15.  
  16. public class ContainerShelvingUnit extends ContainerBasic {
  17.     public TileShelvingUnit shelf;
  18.  
  19.     public ContainerShelvingUnit(InventoryPlayer inv, TileEntity t) {
  20.         super(t);
  21.         shelf = (TileShelvingUnit) t;
  22.         for (int i = 0; i < TileShelvingUnit.MAX_SHELVES; i++) {
  23.             InventoryComponent tabInv = shelf.getInv(i);
  24.             tabInv.openInventory();
  25.             for (int s = 0; s < tabInv.getSizeInventory(); s++) {
  26.                 int y = s / 9;
  27.                 int x = s % 9;
  28.                 addSlotToContainer(new SlotShelvingUnit(tabInv, s, 8 + x * 18, 18 + y * 18, i));
  29.             }
  30.         }
  31.         bindPlayerInventory(inv);
  32.     }
  33.  
  34.     @Override
  35.     public void bindPlayerInventory(InventoryPlayer inventoryPlayer) {
  36.         for (int i = 0; i < 3; i++) {
  37.             for (int j = 0; j < 9; j++) {
  38.                 addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9,
  39.                         8 + j * 18, 122 + i * 18));
  40.             }
  41.         }
  42.         for (int i = 0; i < 9; i++) {
  43.             addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 180));
  44.         }
  45.  
  46.     }
  47.  
  48.     @Override
  49.     public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
  50.         int[] slots = new int[MAX_CRATES * CRATE_SIZE];
  51.         Arrays.fill(slots, 0);
  52.         Arrays.fill(slots, 0, shelf.getCrateCount() * CRATE_SIZE, 3);
  53.         return transfer(player, slot, slots);
  54.     }
  55.  
  56.     @Override
  57.     public void onContainerClosed(EntityPlayer player) {
  58.         super.onContainerClosed(player);
  59.         for (int i = 0; i < TileShelvingUnit.MAX_SHELVES; i++) {
  60.             shelf.getInv(i).closeInventory();
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement