Advertisement
Guest User

ContainerReadableBookshelf

a guest
Nov 11th, 2015
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.05 KB | None | 0 0
  1. package io.github.hsyyid.wilsonsmp.containers;
  2.  
  3. import io.github.hsyyid.wilsonsmp.tileentities.TileEntityReadableBookshelf;
  4. import net.minecraft.entity.player.EntityPlayer;
  5. import net.minecraft.inventory.Container;
  6. import net.minecraft.inventory.IInventory;
  7. import net.minecraft.inventory.Slot;
  8. import net.minecraft.item.ItemStack;
  9.  
  10. public class ContainerReadableBookshelf extends Container
  11. {
  12.     public IInventory inventory;
  13.     public EntityPlayer player;
  14.     public TileEntityReadableBookshelf bookshelf;
  15.  
  16.     public ContainerReadableBookshelf(EntityPlayer player, TileEntityReadableBookshelf bookshelf)
  17.     {  
  18.         this.inventory = bookshelf.inventory;
  19.         this.player = player;
  20.         this.bookshelf = bookshelf;
  21.         this.initialize();
  22.     }
  23.    
  24.     public void initialize()
  25.     {
  26.         this.addSlotToContainer(new Slot(inventory, 0, 14, 26));
  27.        
  28.         for (byte x = 0; x < 9; x++)
  29.         {
  30.             addSlotToContainer(new Slot(player.inventory, x, 5 + (18 * x), 182));
  31.         }
  32.     }
  33.  
  34.     @Override
  35.     public void onCraftMatrixChanged(IInventory iinventory)
  36.     {
  37.         super.onCraftMatrixChanged(iinventory);
  38.     }
  39.  
  40.     @Override
  41.     public void onContainerClosed(EntityPlayer par1EntityPlayer)
  42.     {
  43.         super.onContainerClosed(par1EntityPlayer);
  44.  
  45.         this.bookshelf.inventory = this.inventory;
  46.     }
  47.  
  48.     @Override
  49.     public ItemStack transferStackInSlot(EntityPlayer player, int i)
  50.     {
  51.         Slot slot = getSlot(i);
  52.  
  53.         if (slot != null && slot.getHasStack())
  54.         {
  55.             ItemStack stack = slot.getStack();
  56.             ItemStack result = stack.copy();
  57.  
  58.             if (i >= 36)
  59.             {
  60.                 if (!super.mergeItemStack(stack, 0, 36, false))
  61.                 {
  62.                     return null;
  63.  
  64.                 }
  65.             }
  66.             else if (i != 36 || !this.mergeItemStack(stack, 36, 36 + (this.inventory.getSizeInventory() - 1), false))
  67.             {
  68.                 return null;
  69.  
  70.             }
  71.             else
  72.             {
  73.                 return null;
  74.             }
  75.  
  76.             if (stack.stackSize == 0)
  77.             {
  78.                 slot.putStack(null);
  79.             }
  80.             else
  81.             {
  82.                 slot.onSlotChanged();
  83.             }
  84.  
  85.             slot.onPickupFromSlot(null, stack);
  86.  
  87.             return result;
  88.         }
  89.  
  90.         return null;
  91.     }
  92.  
  93.     @Override
  94.     public boolean canInteractWith(EntityPlayer player)
  95.     {
  96.         return true;
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement