Guest User

Untitled

a guest
Aug 9th, 2016
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.05 KB | None | 0 0
  1. package Fatal1tyGC.BitofTuts.container;
  2.  
  3. import net.minecraft.entity.player.EntityPlayer;
  4. import net.minecraft.inventory.Container;
  5. import net.minecraft.inventory.IInventory;
  6. import net.minecraft.inventory.Slot;
  7. import net.minecraft.item.ItemStack;
  8. import Fatal1tyGC.BitofTuts.tileentities.TileEntityBigChest;
  9. import Fatal1tyGC.BitofTuts.tileentities.TileEntityMiniChest;
  10.  
  11. public class ContainerBigChest extends Container{
  12.  
  13.     private TileEntityBigChest te;
  14.    
  15.     public ContainerBigChest(IInventory playerInv, TileEntityBigChest te) {
  16.         this.te = te;
  17.         //Custom Slots
  18.         for (int y = 0; y < 11; ++y) {
  19.             for (int x = 0; x < 9; ++x) {
  20.                 this.addSlotToContainer(new Slot(te, x+y*11, 8 + x * 18, 14 + y * 18));
  21.             }
  22.         }
  23.         /*
  24.         //Player Inventory
  25.         for (int y = 0; y < 3; ++y) {
  26.             for (int x = 0; x < 9; ++x) {
  27.                 this.addSlotToContainer(new Slot(playerInv, x + y * 9 + 9, 8 + x * 18, 41 + y * 18));
  28.             }
  29.         }*/
  30.         //Player Hotbar
  31.         for (int x = 0; x < 9; ++x) {
  32.             this.addSlotToContainer(new Slot(playerInv, x, 8 + x * 18, 225));
  33.         }
  34.        
  35.     }
  36.    
  37.     @Override
  38.     public boolean canInteractWith(EntityPlayer playerIn) {
  39.         return this.te.isUseableByPlayer(playerIn);
  40.     }
  41.    
  42.    
  43.     @Override
  44.     public ItemStack transferStackInSlot(EntityPlayer playerIn, int fromSlot) {
  45.         ItemStack previous = null;
  46.         Slot slot = (Slot) this.inventorySlots.get(fromSlot);
  47.  
  48.         if (slot != null && slot.getHasStack()) {
  49.             ItemStack current = slot.getStack();
  50.                 previous = current.copy();
  51.  
  52.                 if (fromSlot < 1) {
  53.                 // From TE Inventory to Player Inventory
  54.                     if (!this.mergeItemStack(current, 1, this.inventorySlots.size(), true)){
  55.                                 return null;
  56.                         }
  57.                 } else {
  58.                     // From Player Inventory to TE Inventory
  59.                     if (!this.mergeItemStack(current, 0, 1, false))
  60.                         return null;
  61.                 }
  62.  
  63.                 if (current.stackSize == 0)
  64.                     slot.putStack((ItemStack) null);
  65.                 else
  66.                     slot.onSlotChanged();
  67.             }
  68.             return previous;
  69.     }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment