OSDN Git Service

誰かEntityAtomGrenadeを登録してくれ...
[chemicraft/chemicraft.git] / common / chemicraft / container / ContainerChemicalCombinationTable.java
1 package chemicraft.container;
2
3 import cpw.mods.fml.common.network.PacketDispatcher;
4 import net.minecraft.src.Container;
5 import net.minecraft.src.EntityPlayer;
6 import net.minecraft.src.IInventory;
7 import net.minecraft.src.ItemStack;
8 import net.minecraft.src.Slot;
9 import net.minecraft.src.TileEntity;
10 import net.minecraft.src.World;
11 import chemicraft.ChemiCraft;
12 import chemicraft.ChemiCraftAPI;
13 import chemicraft.inventory.InventoryChemicalCombinationTableMaterial;
14 import chemicraft.inventory.InventoryChemicalCombinationTableResult;
15 import chemicraft.slot.SlotChemicalCombinationTableMaterial;
16 import chemicraft.slot.SlotChemicalCombinationTableResult;
17 import chemicraft.tileentity.TileEntityChemicalCombinationTable;
18
19 public class ContainerChemicalCombinationTable extends Container {
20
21         /**
22          * the world.
23          */
24         private World worldObj;
25
26         /**
27          * the TileEntity of Position.
28          */
29         private int posX;
30         private int posY;
31         private int posZ;
32
33         /**
34          * the TileEntity.
35          */
36         private TileEntityChemicalCombinationTable tileentity;
37
38         /**
39          * the Inventory's.
40          */
41         private InventoryChemicalCombinationTableMaterial invm;
42         private InventoryChemicalCombinationTableResult invr;
43
44         /**
45          * the EntityPlayer.
46          */
47         private EntityPlayer entityplayer;
48
49         public ContainerChemicalCombinationTable(EntityPlayer par1EntityPlayer, TileEntityChemicalCombinationTable par2) {
50                 super();
51                 this.entityplayer = par1EntityPlayer;
52                 this.tileentity = par2;
53                 this.worldObj = tileentity.worldObj;
54                 this.posX = tileentity.xCoord;
55                 this.posY = tileentity.yCoord;
56                 this.posZ = tileentity.zCoord;
57                 this.invm = this.tileentity.getInvMaterial();
58                 this.invr = this.tileentity.getInvResult();
59
60                 for(int i = 0;i < 5;i++){
61                         for(int j = 0;j < 3;j++){
62                                 this.addSlotToContainer(new SlotChemicalCombinationTableMaterial(this.invm, i * 3 + j, i * 18 + 16, j * 18 + 15));
63                         }
64                 }
65                 this.addSlotToContainer(new SlotChemicalCombinationTableResult(invr, 0, 123, 34));
66
67
68                 int var3;
69                 for (var3 = 0; var3 < 3; ++var3)
70                 {
71                         for (int var4 = 0; var4 < 9; ++var4)
72                         {
73                                 this.addSlotToContainer(new Slot(par1EntityPlayer.inventory, var4 + var3 * 9 + 9, 8 + var4 * 18, 121 + var3 * 18));
74                         }
75                 }
76
77                 for (var3 = 0; var3 < 9; ++var3)
78                 {
79                         this.addSlotToContainer(new Slot(par1EntityPlayer.inventory, var3, 8 + var3 * 18, 179));
80                 }
81
82                 this.invm.setEventHandler(this);
83                 this.onCraftMatrixChanged(invm);
84         }
85
86
87
88         @Override
89         public void onCraftMatrixChanged(IInventory par1IInventory){
90                 this.invr.setInventorySlotContents(0, ChemiCraftAPI.getInstance().getCraftingManager().getChemicalCombinationResult(this.tileentity.getAtomsList(), this.tileentity.getAtomsAmountList()));
91         }
92
93         @Override
94         public boolean canInteractWith(EntityPlayer par1EntityPlayer){
95                 return this.worldObj.getBlockId(this.posX, this.posY, this.posZ) != ChemiCraft.instance.chemicalConbinationTableID ? false : par1EntityPlayer.getDistanceSq((double)this.posX + 0.5D, (double)this.posY + 0.5D, (double)this.posZ + 0.5D) <= 64.0D;
96         }
97
98         @Override
99         public ItemStack transferStackInSlot(int par1){
100                 return null;
101         }
102
103         @Override
104         public ItemStack slotClick(int par1, int par2, boolean par3, EntityPlayer par4EntityPlayer) {
105                 if (par1 == 16) {
106                         if (this.invr.getStackInSlot(0) != null) {
107                                 this.tileentity.emptytoAtomsList();
108                                 return super.slotClick(par1, par2, par3, par4EntityPlayer);
109                         }
110                 }
111                 return super.slotClick(par1, par2, par3, par4EntityPlayer);
112         }
113
114         @Override
115         public void onCraftGuiClosed(EntityPlayer par1EntityPlayer){
116                 super.onCraftGuiClosed(par1EntityPlayer);
117         }
118
119 }