Guest User

Untitled

a guest
Sep 23rd, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.54 KB | None | 0 0
  1. package melonslise.runicinscription.common.container;
  2.  
  3. import melonslise.runicinscription.common.crafting.RecipesRuneInscription;
  4. import melonslise.runicinscription.common.inventory.InventoryRuneInscription;
  5. import melonslise.runicinscription.common.inventory.SlotRuneInscription;
  6. import net.minecraft.entity.player.EntityPlayer;
  7. import net.minecraft.entity.player.InventoryPlayer;
  8. import net.minecraft.init.Items;
  9. import net.minecraft.inventory.Container;
  10. import net.minecraft.inventory.Slot;
  11. import net.minecraft.item.ItemStack;
  12. import net.minecraft.world.World;
  13.  
  14. public class ContainerRuneInscription extends Container
  15. {
  16.     private static final int Input = 0;
  17.     private static final int Output = 1;
  18.     public boolean grid[][] = new boolean[5][7];
  19.     private InventoryRuneInscription inventoryInscription = new InventoryRuneInscription(this);
  20.     private World worldobj;
  21.     private int posX;
  22.     private int posY;
  23.     private int posZ;
  24.    
  25.     public ContainerRuneInscription(InventoryPlayer inventoryPlayer, World world, int x, int y, int z)
  26.     {
  27.         this.worldobj = world;
  28.         this.posX = x;
  29.         this.posY = y;
  30.         this.posZ = z;
  31.        
  32.         this.addSlots(inventoryPlayer);
  33.     }
  34.    
  35.     public void addSlots(InventoryPlayer inventoryPlayer)
  36.     {
  37.         this.addSlotToContainer(new SlotRuneInscription(inventoryInscription, this, Input, 8, 47));
  38.         this.addSlotToContainer(new SlotRuneInscription(inventoryInscription, this, Output, 152, 47));
  39.        
  40.         for (int i = 0; i < 3; ++i)
  41.         {
  42.             for (int k = 0; k < 9; ++k)
  43.             {
  44.                 this.addSlotToContainer(new Slot(inventoryPlayer, k + i * 9 + 9, 8 + k * 18, 124 + i * 18));
  45.             }
  46.         }
  47.        
  48.         for (int i = 0; i < 9; ++i)
  49.         {
  50.             this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 182));
  51.         }
  52.     }
  53.    
  54.     public void onMatrixChanged()
  55.     {
  56.         inventoryInscription.setInventorySlotContents(1, RecipesRuneInscription.getInstance().findMatchingRecipe(this.inventoryInscription, this.grid));
  57.         System.out.println("Setting output to " + RecipesRuneInscription.getInstance().findMatchingRecipe(this.inventoryInscription, this.grid));
  58.     }
  59.    
  60.     public void onContainerClosed(EntityPlayer player)
  61.     {
  62.         super.onContainerClosed(player);
  63.        
  64.         for(int x = 0; x < 5; ++x)
  65.         {
  66.             for(int y = 0; y < 7; ++y)
  67.             {
  68.                 grid[x][y] = false;
  69.             }
  70.         }
  71.        
  72.         if(!this.worldobj.isRemote)
  73.         {
  74.             ItemStack itemStack = this.inventoryInscription.getStackInSlotOnClosing(0);
  75.            
  76.             if (itemStack != null)
  77.             {
  78.                 player.dropPlayerItemWithRandomChoice(itemStack, false);
  79.             }
  80.         }
  81.     }
  82.    
  83.     @Override
  84.     public boolean canInteractWith(EntityPlayer player)
  85.     {
  86.         return true;
  87.     }
  88.    
  89.     @Override
  90.     public ItemStack transferStackInSlot(EntityPlayer player, int fromSlot)
  91.     {
  92.         ItemStack itemStack = null;
  93.         Slot slot = (Slot)this.inventorySlots.get(fromSlot);
  94.  
  95.         if (slot != null && slot.getHasStack())
  96.         {
  97.             ItemStack itemStack1 = slot.getStack();
  98.             itemStack = itemStack1.copy();
  99.            
  100.             if(fromSlot == 1)
  101.             {
  102.                 if (!this.mergeItemStack(itemStack1, this.Output + 1, this.Output + 36 + 1, true))
  103.                 {
  104.                     return null;
  105.                 }
  106.             }
  107.             else if(fromSlot != 0 && fromSlot != 1)
  108.             {
  109.                 if(itemStack1.getItem() == Items.dye)
  110.                 {
  111.                     if(!this.mergeItemStack(itemStack1, this.Input, this.Input + 1, false))
  112.                     {
  113.                         return null;
  114.                     }
  115.                 }
  116.                 else if(fromSlot >= this.Output + 1 && fromSlot < this.Output + 27 + 1)
  117.                 {
  118.                     if (!this.mergeItemStack(itemStack1, this.Output + 27 + 1, this.Output + 36 + 1, false))
  119.                     {
  120.                         return null;
  121.                     }
  122.                 }
  123.                 else if(fromSlot >= this.Output + 27 + 1 && fromSlot < this.Output + 36 + 1 && !this.mergeItemStack(itemStack1, this.Output + 1, this.Output + 27 + 1, false))
  124.                 {
  125.                     return null;
  126.                 }
  127.             }
  128.             else if (!this.mergeItemStack(itemStack1, this.Output + 1, this.Output + 36 + 1, false))
  129.             {
  130.                 return null;
  131.             }
  132.            
  133.             if (itemStack1.stackSize == 0)
  134.             {
  135.                 slot.putStack((ItemStack)null);
  136.             }
  137.             else
  138.             {
  139.                 slot.onSlotChanged();
  140.             }
  141.  
  142.             if (itemStack1.stackSize == itemStack.stackSize)
  143.             {
  144.                 return null;
  145.             }
  146.  
  147.             slot.onPickupFromSlot(player, itemStack1);
  148.         }
  149.  
  150.         return itemStack;
  151.     }
  152. }
Add Comment
Please, Sign In to add comment