Advertisement
Guest User

ContainerNetherrackBoiler.java

a guest
Jul 6th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.74 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 net.minecraftforge.fml.relauncher.Side;
  9. import net.minecraftforge.fml.relauncher.SideOnly;
  10. import qwertyasdef.alchemtrans.tile.TileNetherrackBoiler;
  11.  
  12. public class ContainerNetherrackBoiler extends Container {
  13.  
  14.     private TileNetherrackBoiler tileEntity;
  15.  
  16.     public ContainerNetherrackBoiler(IInventory playerInv, TileNetherrackBoiler tileEntity) {
  17.         this.tileEntity = tileEntity;
  18.         /*
  19.         SLOTS:
  20.         Tile Entity: 0-2
  21.         Player Inventory: 3-29
  22.         Player Hotbar: 30-38
  23.          */
  24.  
  25.         // Fluid container input
  26.         this.addSlotToContainer(new Slot(tileEntity, 0, 44, 17));
  27.         // Fluid container output
  28.         this.addSlotToContainer(new Slot(tileEntity, 1, 44, 48));
  29.         // Smelting output
  30.         this.addSlotToContainer(new Slot(tileEntity, 2, 133, 35));
  31.  
  32.         // Player inventory
  33.         for (int i = 0; i < 3; ++i){
  34.             for (int j = 0; j < 9; ++j) {
  35.                 this.addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
  36.             }
  37.         }
  38.  
  39.         // Player hotbar
  40.         for (int k = 0; k < 9; ++k){
  41.             this.addSlotToContainer(new Slot(playerInv, k, 8 + k * 18, 142));
  42.         }
  43.     }
  44.  
  45.     @Override
  46.     public ItemStack transferStackInSlot(EntityPlayer playerIn, int fromSlot) {
  47.         ItemStack previous = ItemStack.EMPTY;
  48.         Slot slot = this.inventorySlots.get(fromSlot);
  49.  
  50.         if (slot != null && slot.getHasStack()) {
  51.             ItemStack current = slot.getStack();
  52.             previous = current.copy();
  53.  
  54.             // [...] Custom behaviour
  55.             if (fromSlot < 3) {
  56.                 // From TE Inventory to Player Inventory
  57.                 if (!this.mergeItemStack(current, 2, 38, true)) {
  58.                     return ItemStack.EMPTY;
  59.                 }
  60.             } else {
  61.                 // From Player Inventory to TE Inventory
  62.                 if (!this.mergeItemStack(current, 0, 1, false)) {
  63.                     return ItemStack.EMPTY;
  64.                 }
  65.             }
  66.  
  67.  
  68.             if (current.isEmpty()) {
  69.                 slot.putStack(ItemStack.EMPTY);
  70.             } else {
  71.                 slot.onSlotChanged();
  72.             }
  73.         }
  74.  
  75.         return previous;
  76.     }
  77.  
  78.     @Override
  79.     public boolean canInteractWith(EntityPlayer playerIn) {
  80.         return true;
  81.     }
  82.  
  83.     @Override
  84.     @SideOnly(Side.CLIENT)
  85.     public void updateProgressBar(int id, int data) {
  86.         this.tileEntity.setField(id, data);
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement