Advertisement
Guest User

Untitled

a guest
Jan 14th, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.27 KB | None | 0 0
  1. public class PackContainer extends Container {
  2.    
  3.     private ItemPack itemPack;
  4.  
  5.     public PackContainer(IInventory playerInventory) {
  6.         addOwnSlots();
  7.         addPlayerSlots(playerInventory);
  8.     }
  9.  
  10.     private void addPlayerSlots(IInventory playerInventory) {
  11.         // Slots for the main inventory
  12.         for (int row = 0; row < 3; ++row) {
  13.             for (int col = 0; col < 9; ++col) {
  14.                 int x = 9 + col * 18;
  15.                 int y = row * 18 + 70;
  16.                 this.addSlotToContainer(new Slot(playerInventory, col + row * 9 + 10, x, y));
  17.             }
  18.         }
  19.  
  20.         // Slots for the hotbar
  21.         for (int row = 0; row < 9; ++row) {
  22.             int x = 9 + row * 18;
  23.             int y = 58 + 70;
  24.             this.addSlotToContainer(new Slot(playerInventory, row, x, y));
  25.         }
  26.     }
  27.    
  28.     private ItemStackHandler itemStackHandler = new ItemStackHandler(9);
  29.  
  30.     private void addOwnSlots() {
  31.         IItemHandler itemHandler = itemStackHandler;
  32.         int x = 9;
  33.         int y = 6;
  34.  
  35.         // Add our own slots
  36.         int slotIndex = 0;
  37.         for (int i = 0; i < itemHandler.getSlots(); i++) {
  38.             addSlotToContainer(new SlotItemHandler(itemHandler, slotIndex, x, y));
  39.             slotIndex++;
  40.             x += 18;
  41.         }
  42.     }
  43.  
  44.     @Nullable
  45.     @Override
  46.     public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
  47.         ItemStack itemstack = null;
  48.         Slot slot = this.inventorySlots.get(index);
  49.  
  50.         if (slot != null && slot.getHasStack()) {
  51.             ItemStack itemstack1 = slot.getStack();
  52.             itemstack = itemstack1.copy();
  53.  
  54.             if (index < 9) {
  55.                 if (!this.mergeItemStack(itemstack1, 9, this.inventorySlots.size(), true)) {
  56.                     return null;
  57.                 }
  58.             } else if (!this.mergeItemStack(itemstack1, 0, 9, false)) {
  59.                 return null;
  60.             }
  61.  
  62.             if (itemstack1.isEmpty()) {
  63.                 slot.putStack(ItemStack.EMPTY);
  64.             } else {
  65.                 slot.onSlotChanged();
  66.             }
  67.         }
  68.  
  69.         return itemstack;
  70.     }
  71.    
  72.     @Override
  73.     public boolean canInteractWith(EntityPlayer playerIn) {
  74.         // TODO Auto-generated method stub
  75.         return true;
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement