RovkirHexus

ContainerHexianOresTileEntity.java

May 9th, 2016
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1. package com.HexianMods.HexianOres.guicontainer;
  2.  
  3. import com.HexianMods.HexianOres.tileentity.HexianOresTileEntity;
  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 ContainerHexianOresTileEntity extends Container{
  12.    
  13.     private HexianOresTileEntity te;
  14.    
  15.     public ContainerHexianOresTileEntity(IInventory playerInv, HexianOresTileEntity te){
  16.         this.te = te;
  17.        
  18.         int y1 = 17;
  19.        
  20.         for (int x = 0; x < 3; ++x) {
  21.             this.addSlotToContainer(new Slot(te, x + y1 * 3, 62 + x * 18, 17 + y1 * 18));
  22.             y1++;
  23.         }
  24.        
  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, 84 + y * 18));
  28.             }
  29.         }
  30.        
  31.         for (int x = 0; x < 9; ++x) {
  32.             this.addSlotToContainer(new Slot(playerInv, x, 8 + x * 18, 142));
  33.         }
  34.     }
  35.    
  36.     @Override
  37.     public ItemStack transferStackInSlot(EntityPlayer playerIn, int fromSlot){
  38.         ItemStack previous = null;
  39.         Slot slot = (Slot) this.inventorySlots.get(fromSlot);
  40.        
  41.         if(slot != null && slot.getHasStack()){
  42.             ItemStack current = slot.getStack();
  43.             previous = current.copy();
  44.            
  45.             if(fromSlot < 3){
  46.                 if(!this.mergeItemStack(current, 3, 39, true)){
  47.                     return null;
  48.                 }
  49.             }else{
  50.                 if(!this.mergeItemStack(current, 0, 3, false)){
  51.                     return null;
  52.                 }
  53.             }
  54.            
  55.             if(current.stackSize == 0){
  56.                 slot.putStack((ItemStack) null);
  57.             }else{
  58.                 slot.onSlotChanged();
  59.             }
  60.            
  61.             if(current.stackSize == previous.stackSize){
  62.                 return null;
  63.             }
  64.            
  65.             slot.onPickupFromSlot(playerIn, current);
  66.         }
  67.         return previous;
  68.     }
  69.    
  70.     @Override
  71.     public boolean canInteractWith(EntityPlayer playerIn){
  72.         return this.te.isUseableByPlayer(playerIn);
  73.     }
  74.  
  75. }
Add Comment
Please, Sign In to add comment