1 package pcc.chemicraft.container;
3 import net.minecraft.entity.player.EntityPlayer;
4 import net.minecraft.inventory.Container;
5 import net.minecraft.inventory.IInventory;
6 import net.minecraft.inventory.Slot;
7 import net.minecraft.item.ItemStack;
8 import net.minecraft.world.World;
9 import pcc.chemicraft.ChemiCraft;
10 import pcc.chemicraft.ChemiCraftAPI;
11 import pcc.chemicraft.inventory.InventoryChemicalCraftingMaterial;
12 import pcc.chemicraft.inventory.InventoryChemicalCraftingNBT;
13 import pcc.chemicraft.inventory.InventoryChemicalCraftingResult;
14 import pcc.chemicraft.slot.SlotChemicalCraftingTableResult;
15 import pcc.chemicraft.tileentity.TileEntityChemicalCraftingTable;
16 import pcc.chemicraft.util.ChemicalNBTRecipe;
18 public class ContainerChemicalCraftingTable extends Container {
23 private World worldObj;
37 private TileEntityChemicalCraftingTable tileEntity;
40 private InventoryChemicalCraftingMaterial invm;
41 private InventoryChemicalCraftingResult invr;
42 private InventoryChemicalCraftingNBT invn;
44 private ChemicalNBTRecipe useNBT;
48 public ContainerChemicalCraftingTable(EntityPlayer par1EntityPlayer, TileEntityChemicalCraftingTable par2)
51 this.worldObj = par2.worldObj;
52 this.posX = par2.xCoord;
53 this.posY = par2.yCoord;
54 this.posZ = par2.zCoord;
55 this.tileEntity = par2;
56 this.invm = (InventoryChemicalCraftingMaterial) this.tileEntity.chemicalCraftingInvMaterial;
57 this.invr = (InventoryChemicalCraftingResult) this.tileEntity.chemicalCraftingInvResult;
58 this.invn = (InventoryChemicalCraftingNBT) this.tileEntity.chemicalCraftingInvNBT;
60 this.generateSlots(this.invm, this.invr, this.invn);
61 //GeneratePlayerInventory
64 for (var3 = 0; var3 < 3; ++var3)
66 for (int var4 = 0; var4 < 9; ++var4)
68 this.addSlotToContainer(new Slot(par1EntityPlayer.inventory, var4 + var3 * 9 + 9, 8 + var4 * 18, 85 + var3 * 18));
72 for (var3 = 0; var3 < 9; ++var3)
74 this.addSlotToContainer(new Slot(par1EntityPlayer.inventory, var3, 8 + var3 * 18, 143));
77 this.invm.setEventHandler(this);
78 this.invr.setEventHandler(this);
79 this.invn.setEventHandler(this);
80 this.onCraftMatrixChanged(invm);
86 public void onCraftMatrixChanged(IInventory par1IInventory){
87 this.useNBT = ChemiCraftAPI.instance().getCraftingManager().chemicalCrafting(this.invm, this.invr, this.invn);
91 public void onCraftGuiClosed(EntityPlayer par1EntityPlayer){
92 super.onCraftGuiClosed(par1EntityPlayer);
96 public ItemStack slotClick(int par1, int par2, int par3, EntityPlayer par4EntityPlayer)
99 if(this.invr.getStackInSlot(0) == null) return super.slotClick(par1, par2, par3, par4EntityPlayer);
100 ItemStack var1 = par4EntityPlayer.inventory.getItemStack();
102 if(var1.stackSize + this.invr.getStackInSlot(0).stackSize >= var1.getMaxStackSize()) return super.slotClick(par1, par2, par3, par4EntityPlayer);
104 for(int i = 0;i < this.invm.getSizeInventory();i++){
105 if(this.invm.getStackInSlot(i) != null){
106 if(this.invm.getStackInSlot(i).stackSize > 1){
107 this.invm.getStackInSlot(i).stackSize--;
109 this.invm.setInventorySlotContents(i, null);
113 ItemStack[] matchNBT = new ItemStack[this.invn.getSizeInventory()];
114 for(int i = 0;i < this.invn.getSizeInventory();i++){
115 matchNBT[i] = this.invn.getStackInSlot(i);
117 if(this.useNBT == null) return super.slotClick(par1, par2, par3, par4EntityPlayer);
118 ItemStack[] useItems = this.useNBT.getMatchItems(matchNBT);
119 for(int i = 0;i < useItems.length;i++){
120 if(useItems[i] != null){
121 this.invn.setInventorySlotContents(i, null);
125 return super.slotClick(par1, par2, par3, par4EntityPlayer);
129 public boolean canInteractWith(EntityPlayer par1EntityPlayer){
130 return this.worldObj.getBlockId(this.posX, this.posY, this.posZ) != ChemiCraft.instance.chemicalCraftingTableID ? false : par1EntityPlayer.getDistanceSq((double)this.posX + 0.5D, (double)this.posY + 0.5D, (double)this.posZ + 0.5D) <= 64.0D;
136 public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2){
142 private void generateSlots(IInventory materialInv, IInventory resultInv, IInventory nbtInv){
143 for(int i = 0;i < 3;i++){
144 this.addSlotToContainer(new Slot(invn, i, 30 + 18 * i, 7));
146 for(int i = 0;i < 3;i++){
147 for(int j = 0;j < 3;j++){
148 this.addSlotToContainer(new Slot(invm, i * 3 + j, 30 + 18 * j, 27 + 18 * i));
151 this.addSlotToContainer(new SlotChemicalCraftingTableResult(invr, 0, 123, 33));