Advertisement
TristanvO

ContainerModTileEntity.java

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