Guest User

ContainerMoriumWorkbench.java

a guest
Apr 21st, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.07 KB | None | 0 0
  1. package com.tristanvo.mod;
  2.  
  3. import net.minecraft.entity.player.EntityPlayer;
  4. import net.minecraft.entity.player.InventoryPlayer;
  5. import net.minecraft.inventory.Container;
  6. import net.minecraft.inventory.IInventory;
  7. import net.minecraft.inventory.InventoryCraftResult;
  8. import net.minecraft.inventory.InventoryCrafting;
  9. import net.minecraft.inventory.Slot;
  10. import net.minecraft.inventory.SlotCrafting;
  11. import net.minecraft.item.ItemStack;
  12. import net.minecraft.world.World;
  13.  
  14. public class ContainerMoriumWorkbench extends Container {
  15.  
  16.     public InventoryCrafting craftMatrix;
  17.     public IInventory craftResult;
  18.     private World worldObj;
  19.     private int posX;
  20.     private int posY;
  21.     private int posZ;
  22.    
  23.    
  24.     public ContainerMoriumWorkbench(InventoryPlayer player, World world, int x, int y, int z) {
  25.         craftMatrix = new InventoryCrafting(this, 5, 5);
  26.         craftResult = new InventoryCraftResult();
  27.         worldObj = world;
  28.         posX = x;
  29.         posY = y;
  30.         posZ = z;
  31.        
  32.         this.addSlotToContainer(new SlotCrafting(player.player, craftMatrix, craftResult, 0, 131, 36));
  33.        
  34.         for(int i = 0; i < 5; i++)
  35.         {
  36.             for(int k = 0; k < 5; k++)
  37.             {
  38.                 this.addSlotToContainer(new Slot(craftMatrix, k = i * 5, 4 + k * 18, 3 + i * 18));
  39.             }
  40.         }
  41.        
  42.         for (int i = 0; i < 3; i++)
  43.         {
  44.             for (int k = 0; k < 9; k++)
  45.             {
  46.                 this.addSlotToContainer(new Slot(player, k + i * 9 + 9, 8 + k * 18, 94 + i * 18));
  47.             }
  48.         }
  49.        
  50.         for (int i = 0; i < 9; i++)
  51.         {
  52.             this.addSlotToContainer(new Slot(player, i, 8 + i * 18, 148));
  53.         }
  54.        
  55.     onCraftMatrixChanged(craftMatrix);
  56.     }
  57.    
  58.     public void onCraftMatrixChanged(IInventory inventory) {
  59.         //craftResult.setInventorySlotContents(0, WorkSurfaceCraftingManager.getInstance().findMatchingRecipe(craftMatrix, worldObj));
  60.     }
  61.  
  62.     @Override
  63.     public boolean canInteractWith(EntityPlayer player) {
  64.         if (worldObj.getBlock(posX, posY, posZ) != mod.blockMoriumWorkbench)
  65.         {
  66.             return false;
  67.         }
  68.         else
  69.         {
  70.             return player.getDistanceSq((double)posX + 0.5D, (double)posY + 0.5D, (double)posZ + 0.5D) <= 64.0D;
  71.         }
  72.     }
  73.    
  74.     public void onContainerClosed(EntityPlayer player)
  75.     {
  76.         super.onContainerClosed(player);
  77.  
  78.         if (!this.worldObj.isRemote)
  79.         {
  80.             for (int i = 0; i < 9; ++i)
  81.             {
  82.                 ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i);
  83.  
  84.                 if (itemstack != null)
  85.                 {
  86.                     player.dropPlayerItemWithRandomChoice(itemstack, false);
  87.                 }
  88.             }
  89.         }
  90.     }
  91.    
  92.     public ItemStack transferStackInSlot(EntityPlayer player, int par2)
  93.     {
  94.         ItemStack itemstack = null;
  95.         Slot slot = (Slot)this.inventorySlots.get(par2);
  96.  
  97.         if (slot != null && slot.getHasStack())
  98.         {
  99.             ItemStack itemstack1 = slot.getStack();
  100.             itemstack = itemstack1.copy();
  101.  
  102.             if (par2 == 0)
  103.             {
  104.                 if (!this.mergeItemStack(itemstack1, 10, 46, true))
  105.                 {
  106.                     return null;
  107.                 }
  108.  
  109.                 slot.onSlotChange(itemstack1, itemstack);
  110.             }
  111.             else if (par2 >= 10 && par2 < 37)
  112.             {
  113.                 if (!this.mergeItemStack(itemstack1, 37, 46, false))
  114.                 {
  115.                     return null;
  116.                 }
  117.             }
  118.             else if (par2 >= 37 && par2 < 46)
  119.             {
  120.                 if (!this.mergeItemStack(itemstack1, 10, 37, false))
  121.                 {
  122.                     return null;
  123.                 }
  124.             }
  125.             else if (!this.mergeItemStack(itemstack1, 10, 46, false))
  126.             {
  127.                 return null;
  128.             }
  129.  
  130.             if (itemstack1.stackSize == 0)
  131.             {
  132.                 slot.putStack((ItemStack)null);
  133.             }
  134.             else
  135.             {
  136.                 slot.onSlotChanged();
  137.             }
  138.  
  139.             if (itemstack1.stackSize == itemstack.stackSize)
  140.             {
  141.                 return null;
  142.             }
  143.  
  144.             slot.onPickupFromSlot(player, itemstack1);
  145.         }
  146.  
  147.         return itemstack;
  148.     }
  149.  
  150. }
Add Comment
Please, Sign In to add comment