Guest User

My Container

a guest
Nov 10th, 2015
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.78 KB | None | 0 0
  1. package me.misterfrogger.quintuplinator.client;
  2.  
  3. import me.misterfrogger.quintuplinator.SlotRestricted;
  4. import me.misterfrogger.quintuplinator.TileEntityPurificationChamber;
  5. import net.minecraft.entity.player.EntityPlayer;
  6. import net.minecraft.entity.player.InventoryPlayer;
  7. import net.minecraft.inventory.Container;
  8. import net.minecraft.inventory.Slot;
  9. import net.minecraft.item.ItemStack;
  10.  
  11. public class ContainerPurificationChamber extends Container {
  12.     private TileEntityPurificationChamber te;
  13.    
  14.     public ContainerPurificationChamber(InventoryPlayer player, TileEntityPurificationChamber entity){
  15.         this.te = entity;
  16.        
  17.         for(int x = 0;x < 9;x++){
  18.             addSlotToContainer(new Slot(player, x, 8 + x * 18, 142));
  19.         }
  20.        
  21.         for(int y = 0;y < 3;y++){
  22.             for(int x = 0;x < 9;x++){
  23.                 addSlotToContainer(new Slot(player, 9 + x + y * 9, 8 + x * 18, 84 + y * 18));
  24.             }
  25.         }
  26.        
  27.         addSlotToContainer(new Slot(te, 0, 56, 35));
  28.         addSlotToContainer(new SlotRestricted(te, 1, 116, 35));
  29.     }
  30.    
  31.     @Override
  32.     public boolean canInteractWith(EntityPlayer player){
  33.         return te.isUseableByPlayer(player);
  34.     }
  35.    
  36.     @Override
  37.     public ItemStack transferStackInSlot(EntityPlayer player, int i){
  38.         if(te.worldObj.isRemote) return null;
  39.         Slot slot = getSlot(i);
  40.        
  41.         if(slot != null && slot.getHasStack()){
  42.             ItemStack stack = slot.getStack();
  43.             ItemStack result = stack.copy();
  44.            
  45.             if(i >= 36){
  46.                 if(!mergeItemStack(stack, 0, 36, false)){
  47.                     return null;
  48.                 }
  49.             }else if(!mergeItemStack(stack, 36, 36 + te.getSizeInventory(), false)){
  50.                 return null;
  51.             }
  52.            
  53.             if(stack.stackSize == 0){
  54.                 slot.putStack(null);
  55.             }else{
  56.                 slot.onSlotChanged();
  57.             }
  58.            
  59.             slot.onPickupFromSlot(player, stack);
  60.             te.onInventoryChanged();
  61.             return result;
  62.         }
  63.        
  64.         return null;
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment