OSDN Git Service

同期バグ修正
[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.World;
10 import chemicraft.ChemiCraft;
11 import chemicraft.ChemiCraftAPI;
12 import chemicraft.inventory.InventoryChemicalCombinationTableMaterial;
13 import chemicraft.inventory.InventoryChemicalCombinationTableResult;
14 import chemicraft.slot.SlotChemicalCombinationTableMaterial;
15 import chemicraft.slot.SlotChemicalCombinationTableResult;
16 import chemicraft.tileentity.TileEntityChemicalCombinationTable;
17
18 public class ContainerChemicalCombinationTable extends Container {
19
20         /**
21          * the world.
22          */
23         private World worldObj;
24
25         /**
26          * the TileEntity of Position.
27          */
28         private int posX;
29         private int posY;
30         private int posZ;
31
32         /**
33          * the TileEntity.
34          */
35         private TileEntityChemicalCombinationTable tileentity;
36
37         /**
38          * the Inventory's.
39          */
40         private InventoryChemicalCombinationTableMaterial invm;
41         private InventoryChemicalCombinationTableResult invr;
42
43         /**
44          * the EntityPlayer.
45          */
46         private EntityPlayer entityplayer;
47
48         public ContainerChemicalCombinationTable(EntityPlayer par1EntityPlayer, TileEntityChemicalCombinationTable par2) {
49                 super();
50                 this.entityplayer = par1EntityPlayer;
51                 this.tileentity = par2;
52                 this.worldObj = tileentity.worldObj;
53                 this.posX = tileentity.xCoord;
54                 this.posY = tileentity.yCoord;
55                 this.posZ = tileentity.zCoord;
56                 this.invm = this.tileentity.getInvMaterial();
57                 this.invr = this.tileentity.getInvResult();
58
59                 for(int i = 0;i < 5;i++){
60                         for(int j = 0;j < 3;j++){
61                                 this.addSlotToContainer(new SlotChemicalCombinationTableMaterial(this.invm, i * 3 + j, i * 18 + 16, j * 18 + 15));
62                         }
63                 }
64                 this.addSlotToContainer(new SlotChemicalCombinationTableResult(invr, 0, 123, 34));
65
66
67                 int var3;
68                 for (var3 = 0; var3 < 3; ++var3)
69                 {
70                         for (int var4 = 0; var4 < 9; ++var4)
71                         {
72                                 this.addSlotToContainer(new Slot(par1EntityPlayer.inventory, var4 + var3 * 9 + 9, 8 + var4 * 18, 121 + var3 * 18));
73                         }
74                 }
75
76                 for (var3 = 0; var3 < 9; ++var3)
77                 {
78                         this.addSlotToContainer(new Slot(par1EntityPlayer.inventory, var3, 8 + var3 * 18, 179));
79                 }
80
81                 this.invm.setEventHandler(this);
82                 this.onCraftMatrixChanged(invm);
83         }
84
85
86
87         @Override
88         public void onCraftMatrixChanged(IInventory par1IInventory){
89                 this.invr.setInventorySlotContents(0, ChemiCraftAPI.getInstance().getCraftingManager().getChemicalCombinationResult(this.tileentity.getAtomsList(), this.tileentity.getAtomsAmountList()));
90                 if (par1IInventory instanceof InventoryChemicalCombinationTableResult) {
91                         PacketDispatcher.sendPacketToServer(this.tileentity.getDescriptionPacket());
92                 }
93         }
94
95         @Override
96         public boolean canInteractWith(EntityPlayer par1EntityPlayer){
97                 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;
98         }
99
100         @Override
101         public ItemStack transferStackInSlot(int par1){
102                 return null;
103         }
104
105         @Override
106         public ItemStack slotClick(int par1, int par2, boolean par3, EntityPlayer par4EntityPlayer) {
107                 if (par1 == 15) {
108                         if (this.invr.getStackInSlot(0) != null) {
109                                 this.tileentity.emptytoAtomsList();
110                         }
111                 }
112                 return super.slotClick(par1, par2, par3, par4EntityPlayer);
113         }
114
115         @Override
116         public void onCraftGuiClosed(EntityPlayer par1EntityPlayer){
117                 super.onCraftGuiClosed(par1EntityPlayer);
118         }
119
120 }