OSDN Git Service

修正・変更
[chemicraft/chemicraft.git] / common / pcc / chemicraft / core / container / ContainerChemicalCombinationTable.java
1 package pcc.chemicraft.core.container;
2
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.core.ChemiCraftAPI;
10 import pcc.chemicraft.core.ChemiCraftCore;
11 import pcc.chemicraft.core.inventory.InventoryChemicalCombinationTableMaterial;
12 import pcc.chemicraft.core.inventory.InventoryChemicalCombinationTableResult;
13 import pcc.chemicraft.core.slot.SlotAtoms;
14 import pcc.chemicraft.core.slot.SlotResult;
15 import pcc.chemicraft.core.tileentity.TileEntityChemicalCombinationTable;
16 import cpw.mods.fml.common.network.PacketDispatcher;
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 SlotAtoms(this.invm, i * 3 + j, i * 18 + 16, j * 18 + 15));
62                         }
63                 }
64                 this.addSlotToContainer(new SlotResult(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.instance().getCraftingManager().getChemicalCombinationResult(this.tileentity.getAtomsList(), this.tileentity.getAtomsAmountList()));
90                 if (par1IInventory instanceof InventoryChemicalCombinationTableResult) {
91                         PacketDispatcher.sendPacketToServer(this.tileentity.getDescriptionPacket());
92                 }
93         }
94
95         public void onCraftGuiClosed(EntityPlayer par1EntityPlayer)
96         {
97                 super.onCraftGuiClosed(par1EntityPlayer);
98         }
99
100         @Override
101         public boolean canInteractWith(EntityPlayer par1EntityPlayer){
102                 return this.worldObj.getBlockId(this.posX, this.posY, this.posZ) != ChemiCraftCore.instance.chemicalConbinationTableID ? false : par1EntityPlayer.getDistanceSq((double)this.posX + 0.5D, (double)this.posY + 0.5D, (double)this.posZ + 0.5D) <= 64.0D;
103         }
104
105         @Override
106         public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
107                 ItemStack var3 = null;
108                 Slot var4 = (Slot)this.inventorySlots.get(par2);
109                 Slot var6 = (Slot)this.inventorySlots.get(0);
110
111                 if (var4 != null && var4.getHasStack()) {
112                         ItemStack var5 = var4.getStack();
113                         var3 = var5.copy();
114                         if (par2 >= 0 && par2 < 16) {
115                                 if (!this.mergeItemStack(var5, 16, 52, false)) {
116                                         return null;
117                                 }
118                         } else if (par2 >= 16 && par2 < 53) {
119                                 if (var6.isItemValid(var3)) {
120                                         if (!this.mergeItemStack(var5, 0, 15, false)) {
121                                                 return null;
122                                         }
123                                 }
124                         } else if(par2 == 16) {
125                                 if (!this.mergeItemStack(var5, 16, 52, false)) {
126                                         return null;
127                                 }
128                         }
129
130                         if (var5.stackSize == 0) {
131                                 var4.putStack((ItemStack)null);
132                         } else {
133                                 var4.onSlotChanged();
134                         }
135
136                         if (var5.stackSize == var3.stackSize) {
137                                 return null;
138                         }
139
140                         var4.onPickupFromSlot(par1EntityPlayer, var5);
141                 }
142
143                 return var3;
144         }
145
146         @Override
147         public ItemStack slotClick(int par1, int par2, int par3, EntityPlayer par4EntityPlayer) {
148                 if (par1 == 15) {
149                         if (this.invr.getStackInSlot(0) != null) {
150                                 this.tileentity.emptytoAtomsList();
151                         }
152                 }
153                 return super.slotClick(par1, par2, par3, par4EntityPlayer);
154         }
155
156 }