Guest User

Untitled

a guest
Sep 23rd, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.77 KB | None | 0 0
  1. package melonslise.runicinscription.common.inventory;
  2.  
  3. import melonslise.runicinscription.common.container.ContainerRuneInscription;
  4. import net.minecraft.entity.player.EntityPlayer;
  5. import net.minecraft.inventory.IInventory;
  6. import net.minecraft.item.ItemStack;
  7.  
  8. public class InventoryRuneInscription implements IInventory
  9. {
  10.     private ItemStack[] inventory = new ItemStack[2];
  11.     private ContainerRuneInscription containerInscription;
  12.     private String name = "Rune Inscription";
  13.    
  14.     public InventoryRuneInscription(ContainerRuneInscription containerInscription)
  15.     {
  16.         this.containerInscription = containerInscription;
  17.     }
  18.    
  19.     @Override
  20.     public int getSizeInventory()
  21.     {
  22.         return this.inventory.length;
  23.     }
  24.    
  25.     @Override
  26.     public ItemStack getStackInSlot(int slot)
  27.     {
  28.         if(slot >= this.getSizeInventory())
  29.         {
  30.             return null;
  31.         }
  32.         else
  33.         {
  34.             return this.inventory[slot];
  35.         }
  36.     }
  37.  
  38.     @Override
  39.     public ItemStack decrStackSize(int slot, int amount)
  40.     {
  41.         if(this.inventory[slot] != null)
  42.         {
  43.             ItemStack itemStack;
  44.            
  45.             if(this.inventory[slot].stackSize > amount)
  46.             {
  47.                 itemStack = this.inventory[slot].splitStack(amount);
  48.                 if (this.inventory[slot].stackSize == 0)
  49.                 {
  50.                     this.inventory[slot] = null;
  51.                 }
  52.                 if(slot == 0)
  53.                 {
  54.                     this.containerInscription.onMatrixChanged();
  55.                 }
  56.                 return itemStack;
  57.             }
  58.             else
  59.             {
  60.                 itemStack = this.inventory[slot];
  61.                 this.inventory[slot] = null;
  62.                 if(slot == 0)
  63.                 {
  64.                     this.containerInscription.onMatrixChanged();
  65.                 }
  66.                 return itemStack;
  67.             }
  68.         }
  69.         else
  70.         {
  71.             return null;
  72.         }
  73.     }
  74.    
  75.     @Override
  76.     public ItemStack getStackInSlotOnClosing(int slot)
  77.     {
  78.         if(this.inventory[slot] != null)
  79.         {
  80.             ItemStack itemStack = this.inventory[slot];
  81.             this.inventory[slot] = null;
  82.             return itemStack;
  83.         }
  84.         else
  85.         {
  86.             return null;
  87.         }
  88.     }
  89.    
  90.     @Override
  91.     public void setInventorySlotContents(int slot, ItemStack itemStack)
  92.     {
  93.         this.inventory[slot] = itemStack;
  94.         if(slot == 0)
  95.         {
  96.             this.containerInscription.onMatrixChanged();
  97.         }
  98.     }
  99.  
  100.     @Override
  101.     public String getInventoryName()
  102.     {
  103.         return this.name;
  104.     }
  105.    
  106.     @Override
  107.     public boolean hasCustomInventoryName()
  108.     {
  109.         if(this.name.length() > 0)
  110.         {
  111.             return true;
  112.         }
  113.         else
  114.         {
  115.             return false;
  116.         }
  117.     }
  118.  
  119.     @Override
  120.     public int getInventoryStackLimit()
  121.     {
  122.         return 64;
  123.     }
  124.    
  125.     @Override
  126.     public void markDirty()
  127.     {
  128.        
  129.     }
  130.    
  131.     @Override
  132.     public boolean isUseableByPlayer(EntityPlayer player)
  133.     {
  134.         return true;
  135.     }
  136.    
  137.     @Override
  138.     public void openInventory()
  139.     {
  140.        
  141.     }
  142.    
  143.     @Override
  144.     public void closeInventory()
  145.     {
  146.        
  147.     }
  148.  
  149.     @Override
  150.     public boolean isItemValidForSlot(int slot, ItemStack itemStack)
  151.     {
  152.         return true;
  153.     }
  154. }
Add Comment
Please, Sign In to add comment