OSDN Git Service

文字化け用
[chemicraft/chemicraft.git] / common / chemicraft / ContainerDecompositionTable.java
1 package chemicraft;
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.InventoryPlayer;
8 import net.minecraft.src.ItemStack;
9 import net.minecraft.src.Packet;
10 import net.minecraft.src.Slot;
11 import net.minecraft.src.World;
12
13 public class ContainerDecompositionTable extends Container {
14
15         /**
16          * Worldのインスタンス
17          */
18         private World worldObj;
19
20
21         /**
22          * BlockのX, Y, Z座標
23          */
24         private int posX;
25         private int posY;
26         private int posZ;
27
28
29         /**
30          * the TileEntity.
31          */
32         private TileEntityDecompositionTable tileEntity;
33
34
35         /**
36          * the inventory.
37          */
38         private InventoryDecomposition inv;
39
40
41
42         /**
43          * the inventoryPlayer.
44          */
45         private InventoryPlayer invp;
46
47
48
49         public ContainerDecompositionTable(EntityPlayer par1EntityPlayer, TileEntityDecompositionTable par2)
50         {
51                 super();
52                 this.worldObj = par2.worldObj;
53                 this.posX = par2.xCoord;
54                 this.posY = par2.yCoord;
55                 this.posZ = par2.zCoord;
56                 this.tileEntity = par2;
57                 this.inv = par2.getInventorys();
58                 this.invp = par1EntityPlayer.inventory;
59                 //GenerateInventory
60                 this.generateSlots("Decomposition", par2.getInventorys());
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.tileEntity.getInventorys().setEventHandler(this);
78         }
79
80
81
82         @Override
83         public void onCraftMatrixChanged(IInventory par1IInventory){
84                 ((InventoryDecomposition) par1IInventory).setFlag(false);
85                 this.putStacksInSlots(ChemiCraftAPI.getCraftingManager().getDecompositionResults(par1IInventory));
86                 ((InventoryDecomposition) par1IInventory).setFlag(true);
87         }
88
89
90
91         @Override
92         public void onCraftGuiClosed(EntityPlayer par1EntityPlayer){
93                 super.onCraftGuiClosed(par1EntityPlayer);
94         }
95
96
97
98         @Override
99         public boolean canInteractWith(EntityPlayer par1EntityPlayer){
100                 return this.worldObj.getBlockId(this.posX, this.posY, this.posZ) != ChemiCraft.instance.decompositionTableID ? false : par1EntityPlayer.getDistanceSq((double)this.posX + 0.5D, (double)this.posY + 0.5D, (double)this.posZ + 0.5D) <= 64.0D;
101         }
102
103
104
105         @Override
106         public ItemStack slotClick(int par1, int par2, boolean par3, EntityPlayer par4EntityPlayer)
107         {
108                 if(par1 < 16){
109                         return null;
110                 }else{
111                         super.slotClick(par1, par2, par3, par4EntityPlayer);
112                 }
113                 return null;
114         }
115
116
117
118         @Override
119         public ItemStack transferStackInSlot(int par1){
120                 return null;
121         }
122
123
124
125         public void addPlayerInv(int par1, ItemStack par2ItemStack){
126                 this.putStackInSlot(par1, par2ItemStack);
127         }
128
129
130
131         public void onButtonClick(int par1){
132                 if(par1 == 0){
133                         for(int loop = 0;loop < 1;loop++){
134                                 if(this.inv.getStackInSlot(16) == null) break;
135                                 for(int i = 0;i < this.inv.getSizeInventory();i++){
136                                         if(i < 16 && this.inv.getStackInSlot(i) != null){
137                                                 if(this.invp.player.inventory.getFirstEmptyStack() != -1){
138                                                         this.tileEntity.setItemDrop(false);
139                                                         PacketDispatcher.sendPacketToServer(this.tileEntity.getDescriptionPacket());
140                                                 }else{
141                                                         this.tileEntity.setItemDrop(true);
142                                                         PacketDispatcher.sendPacketToServer(this.tileEntity.getDescriptionPacket());
143                                                         this.updateCraftingResults();
144                                                 }
145                                         }
146                                 }
147                         }
148                 }else if(par1 == 1){
149                         for(int loop = 0;loop < 16;loop++){
150                                 if(this.inv.getStackInSlot(16) == null) break;
151                                 for(int i = 0;i < this.inv.getSizeInventory();i++){
152                                         if(i < 16 && this.inv.getStackInSlot(i) != null){
153                                                 if(this.invp.player.inventory.getFirstEmptyStack() != -1){
154                                                         this.tileEntity.setItemDrop(false);
155                                                         PacketDispatcher.sendPacketToServer(this.tileEntity.getDescriptionPacket());
156                                                 }else{
157                                                         this.tileEntity.setItemDrop(true);
158                                                         PacketDispatcher.sendPacketToServer(this.tileEntity.getDescriptionPacket());
159                                                 }
160                                         }
161                                 }
162                         }
163                 }else if(par1 == 2){
164                         for(int loop = 0;loop < 32;loop++){
165                                 if(this.inv.getStackInSlot(16) == null) break;
166                                 for(int i = 0;i < this.inv.getSizeInventory();i++){
167                                         if(i < 16 && this.inv.getStackInSlot(i) != null){
168                                                 if(this.invp.player.inventory.getFirstEmptyStack() != -1){
169                                                         this.tileEntity.setItemDrop(false);
170                                                         PacketDispatcher.sendPacketToServer(this.tileEntity.getDescriptionPacket());
171                                                 }else{
172                                                         this.tileEntity.setItemDrop(true);
173                                                         PacketDispatcher.sendPacketToServer(this.tileEntity.getDescriptionPacket());
174                                                 }
175                                         }
176                                 }
177                         }
178                 }else if(par1 == 3){
179                         for(int loop = 0;loop < 64;loop++){
180                                 if(this.inv.getStackInSlot(16) == null) break;
181                                 for(int i = 0;i < this.inv.getSizeInventory();i++){
182                                         if(i < 16 && this.inv.getStackInSlot(i) != null){
183                                                 if(this.invp.player.inventory.getFirstEmptyStack() != -1){
184                                                         this.tileEntity.setItemDrop(false);
185                                                         PacketDispatcher.sendPacketToServer(this.tileEntity.getDescriptionPacket());
186                                                 }else{
187                                                         this.tileEntity.setItemDrop(true);
188                                                         PacketDispatcher.sendPacketToServer(this.tileEntity.getDescriptionPacket());
189                                                 }
190                                         }
191                                 }
192                         }
193                 }
194                 this.onCraftMatrixChanged(this.inv);
195         }
196
197
198
199         private void generateSlots(String activeTabs, IInventory inventorys){
200                 int count = 0;
201                 for(int i = 0;i < 4;i++){
202                         for(int j = 0;j < 4;j++){
203                                 this.addSlotToContainer(new SlotDecompositionResult(inventorys, count, 90 + 18 * j, 8 + 18 * i));
204                                 count++;
205                         }
206                 }
207                 this.addSlotToContainer(new Slot(inventorys, count, 28, 30));
208         }
209
210 }