Advertisement
Guest User

ContainerNetherrackFurnace.java

a guest
Jul 1st, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.38 KB | None | 0 0
  1. package qwertyasdef.alchemtrans.inventory;
  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 qwertyasdef.alchemtrans.Tile.TileNetherrackFurnace;
  9.  
  10. public class ContainerNetherrackFurnace extends Container {
  11.  
  12.     private TileNetherrackFurnace tileEntity;
  13.  
  14.     public ContainerNetherrackFurnace(IInventory playerInv, TileNetherrackFurnace tileEntity) {
  15.         this.tileEntity = tileEntity;
  16.  
  17.         /*
  18.         SLOTS:
  19.         Tile Entity: 0-1
  20.         Player Inventory: 2-28
  21.         Player Hotbar: 29-37
  22.          */
  23.  
  24.         // Input
  25.         this.addSlotToContainer(new Slot(tileEntity, 0, 56, 17));
  26.         // Output
  27.         this.addSlotToContainer(new Slot(tileEntity, 2, 116, 35));
  28.  
  29.         // Player inventory
  30.         for (int i = 0; i < 3; ++i){
  31.             for (int j = 0; j < 9; ++j) {
  32.                 this.addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
  33.             }
  34.         }
  35.  
  36.         // Player hotbar
  37.         for (int k = 0; k < 9; ++k){
  38.             this.addSlotToContainer(new Slot(playerInv, k, 8 + k * 18, 142));
  39.         }
  40.     }
  41.  
  42.     @Override
  43.     public ItemStack transferStackInSlot(EntityPlayer playerIn, int fromSlot) {
  44.         ItemStack previous = null;
  45.         Slot slot = this.inventorySlots.get(fromSlot);
  46.  
  47.         if (slot != null && slot.getHasStack()) {
  48.             ItemStack current = slot.getStack();
  49.             previous = current.copy();
  50.  
  51.             // [...] Custom behaviour
  52.             if (fromSlot < 2) {
  53.                 // From TE Inventory to Player Inventory
  54.                 if (!this.mergeItemStack(current, 2, 38, 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.  
  64.  
  65.             if (current.isEmpty()) {
  66.                 slot.putStack(ItemStack.EMPTY);
  67.             } else {
  68.                 slot.onSlotChanged();
  69.             }
  70.         }
  71.  
  72.         return previous;
  73.     }
  74.  
  75.     @Override
  76.     public boolean canInteractWith(EntityPlayer playerIn) {
  77.         return this.tileEntity.isUsableByPlayer(playerIn);
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement