OSDN Git Service

素材製作台(減算処理・NBT処理抜き)を製作
[chemicraft/chemicraft.git] / common / chemicraft / container / ContainerChemicalCraftingTable.java
1 package chemicraft.container;
2
3 import net.minecraft.src.Container;
4 import net.minecraft.src.EntityPlayer;
5 import net.minecraft.src.IInventory;
6 import net.minecraft.src.ItemStack;
7 import net.minecraft.src.Slot;
8 import net.minecraft.src.World;
9 import chemicraft.ChemiCraft;
10 import chemicraft.ChemiCraftAPI;
11 import chemicraft.inventory.InventoryChemicalCraftingMaterial;
12 import chemicraft.inventory.InventoryChemicalCraftingNBT;
13 import chemicraft.inventory.InventoryChemicalCraftingResult;
14 import chemicraft.slot.SlotChemicalCraftingResult;
15 import chemicraft.tileentity.TileEntityChemicalCraftingTable;
16 import chemicraft.util.ChemicalNBTRecipe;
17
18 public class ContainerChemicalCraftingTable extends Container {
19
20         /**
21          * Worldのインスタンス
22          */
23         private World worldObj;
24
25
26         /**
27          * BlockのX, Y, Z座標
28          */
29         private int posX;
30         private int posY;
31         private int posZ;
32
33
34         /**
35          * the TileEntity.
36          */
37         private TileEntityChemicalCraftingTable tileEntity;
38
39
40         private InventoryChemicalCraftingMaterial invm;
41         private InventoryChemicalCraftingResult invr;
42         private InventoryChemicalCraftingNBT invn;
43
44         private ChemicalNBTRecipe useNBT;
45
46
47
48         public ContainerChemicalCraftingTable(EntityPlayer par1EntityPlayer, TileEntityChemicalCraftingTable par2)
49         {
50                 super();
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;
59                 //GenerateInventory
60                 this.generateSlots(this.invm, this.invr, this.invn);
61                 //GeneratePlayerInventory
62                 int var3;
63
64                 for (var3 = 0; var3 < 3; ++var3)
65                 {
66                         for (int var4 = 0; var4 < 9; ++var4)
67                         {
68                                 this.addSlotToContainer(new Slot(par1EntityPlayer.inventory, var4 + var3 * 9 + 9, 8 + var4 * 18, 85 + var3 * 18));
69                         }
70                 }
71
72                 for (var3 = 0; var3 < 9; ++var3)
73                 {
74                         this.addSlotToContainer(new Slot(par1EntityPlayer.inventory, var3, 8 + var3 * 18, 143));
75                 }
76
77                 this.invm.setEventHandler(this);
78                 this.invr.setEventHandler(this);
79                 this.invn.setEventHandler(this);
80                 this.onCraftMatrixChanged(invm);
81         }
82
83
84
85         @Override
86         public void onCraftMatrixChanged(IInventory par1IInventory){
87                 ChemiCraftAPI.instance.getCraftingManager().chemicalCrafting(this.invm, this.invr, this.invn);
88         }
89
90         @Override
91         public void onCraftGuiClosed(EntityPlayer par1EntityPlayer){
92                 super.onCraftGuiClosed(par1EntityPlayer);
93         }
94
95
96
97         @Override
98         public boolean canInteractWith(EntityPlayer par1EntityPlayer){
99                 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;
100         }
101
102
103
104         @Override
105         public ItemStack transferStackInSlot(int par1){
106                 return null;
107         }
108
109
110
111         private void generateSlots(IInventory materialInv, IInventory resultInv, IInventory nbtInv){
112                 for(int i = 0;i < 3;i++){
113                         this.addSlotToContainer(new Slot(invn, i, 30 + 18 * i, 7));
114                 }
115                 for(int i = 0;i < 3;i++){
116                         for(int j = 0;j < 3;j++){
117                                 this.addSlotToContainer(new Slot(invm, i * 3 + j, 30 + 18 * j, 27 + 18 * i));
118                         }
119                 }
120                 this.addSlotToContainer(new SlotChemicalCraftingResult(invr, 0, 123, 33));
121         }
122 }