OSDN Git Service

とりあえずコミット
[chemicraft/chemicraft.git] / common / chemicraft / tileentity / TileEntityChemicalCombinationTable.java
1 package chemicraft.tileentity;
2
3 import java.io.DataOutputStream;
4 import java.util.ArrayList;
5
6 import net.minecraft.src.ItemStack;
7 import net.minecraft.src.NBTTagCompound;
8 import net.minecraft.src.NBTTagList;
9 import net.minecraft.src.Packet;
10 import net.minecraft.src.TileEntity;
11 import chemicraft.inventory.InventoryChemicalCombinationTableMaterial;
12 import chemicraft.inventory.InventoryChemicalCombinationTableResult;
13 import chemicraft.system.PacketHandler;
14
15 import com.google.common.io.ByteArrayDataInput;
16
17 public class TileEntityChemicalCombinationTable extends TileEntity {
18
19         private InventoryChemicalCombinationTableMaterial invm = new InventoryChemicalCombinationTableMaterial();
20         private InventoryChemicalCombinationTableResult invr = new InventoryChemicalCombinationTableResult();
21
22         private ArrayList<String> atomsList = new ArrayList<String>();
23         private ArrayList<Integer> atomsAmountList = new ArrayList<Integer>();
24         private int atomsListSize = 0;
25
26         @Override
27         public void readFromNBT(NBTTagCompound par1){
28                 super.readFromNBT(par1);
29                 NBTTagList var2 = par1.getTagList("Items");
30                 for (int var3 = 0; var3 < var2.tagCount(); ++var3)
31                 {
32                         NBTTagCompound var4 = (NBTTagCompound)var2.tagAt(var3);
33                         int var5 = var4.getByte("Slot") & 255;
34
35                         if (var5 >= 0 && var5 < this.invm.getSizeInventory())
36                         {
37                                 this.invm.setInventorySlotContents(var5, ItemStack.loadItemStackFromNBT(var4));
38                         }
39                 }
40
41                 NBTTagList var6 = par1.getTagList("Items2");
42                 for (int var3 = 0; var3 < var6.tagCount(); ++var3)
43                 {
44                         NBTTagCompound var7 = (NBTTagCompound)var6.tagAt(var3);
45                         int var8 = var7.getByte("Slot2") & 255;
46
47                         if (var8 >= 0 && var8 < this.invr.getSizeInventory())
48                         {
49                                 this.invr.setInventorySlotContents(var8, ItemStack.loadItemStackFromNBT(var7));
50                         }
51                 }
52
53                 this.atomsListSize = par1.getInteger("atomsListSize");
54
55                 for(int i = 0;i < this.atomsListSize;i++){
56                         this.atomsList.add(par1.getString("atomsList") + i);
57                 }
58
59                 for(int i = 0;i < this.atomsListSize;i++){
60                         this.atomsAmountList.add(par1.getInteger("atomsAmountList") + i);
61                 }
62         }
63
64         @Override
65         public void writeToNBT(NBTTagCompound par1){
66                 super.writeToNBT(par1);
67                 NBTTagList var2 = new NBTTagList();
68                 for (int var3 = 0; var3 < this.invm.getSizeInventory(); ++var3)
69                 {
70                         if (this.invm.getStackInSlot(var3) != null)
71                         {
72                                 NBTTagCompound var4 = new NBTTagCompound();
73                                 var4.setByte("Slot", (byte)var3);
74                                 this.invm.getStackInSlot(var3).writeToNBT(var4);
75                                 var2.appendTag(var4);
76                         }
77                 }
78                 par1.setTag("Items", var2);
79
80                 NBTTagList var5 = new NBTTagList();
81                 for (int var6 = 0; var6 < this.invr.getSizeInventory(); ++var6)
82                 {
83                         if (this.invr.getStackInSlot(var6) != null)
84                         {
85                                 NBTTagCompound var7 = new NBTTagCompound();
86                                 var7.setByte("Slot2", (byte)var6);
87                                 this.invr.getStackInSlot(var6).writeToNBT(var7);
88                                 var5.appendTag(var7);
89                         }
90                 }
91                 par1.setTag("Items2", var5);
92
93                 this.atomsList.trimToSize();
94                 this.atomsAmountList.trimToSize();
95                 for(int i = 0;i < this.atomsList.size();i++){
96                         par1.setString("atoms" + i, this.atomsList.get(i));
97                 }
98                 for(int i = 0;i < this.atomsAmountList.size();i++){
99                         par1.setInteger("atomsAmount" + i, this.atomsAmountList.get(i));
100                 }
101
102                 this.atomsListSize = this.atomsList.size();
103                 par1.setInteger("atomsListSize", this.atomsListSize);
104
105         }
106
107         @Override
108         public Packet getDescriptionPacket() {
109                 return PacketHandler.getPacket(this);
110         }
111
112         public void readPacket(ByteArrayDataInput data) {
113                 try {
114                         for(int i = 0;i < this.invm.getSizeInventory();i++){
115                                 int id = data.readInt();
116                                 int size = data.readByte();
117                                 int damage = data.readInt();
118                                 if(id != 0 && size != 0){
119                                         this.invm.setInventorySlotContents(i, new ItemStack(id, size, damage));
120                                 }else{
121                                         this.invm.setInventorySlotContents(i, null);
122                                 }
123                         }
124
125                         for(int i = 0;i < this.invr.getSizeInventory();i++){
126                                 int id = data.readInt();
127                                 int size = data.readByte();
128                                 int damage = data.readInt();
129                                 if(id != 0 && size != 0){
130                                         this.invr.setInventorySlotContents(i, new ItemStack(id, size, damage));
131                                 }else{
132                                         this.invr.setInventorySlotContents(i, null);
133                                 }
134                         }
135
136                 } catch (Exception e) {
137                         e.printStackTrace();
138                 }
139         }
140
141         public void writePacket(DataOutputStream dos){
142                 try {
143                         for(int i = 0;i < this.invm.getSizeInventory();i++){
144                                 int id = 0;
145                                 int size = 0;
146                                 int damage  = 0;
147                                 ItemStack itemstack = this.invm.getStackInSlot(i);
148                                 if(itemstack != null){
149                                         id = itemstack.itemID;
150                                         size = itemstack.stackSize;
151                                         damage = itemstack.getItemDamage();
152                                         dos.writeInt(id);
153                                         dos.writeByte(size);
154                                         dos.writeInt(damage);
155                                 }else{
156                                         dos.writeInt(0);
157                                         dos.writeByte(0);
158                                         dos.writeInt(0);
159                                 }
160                         }
161
162                         for(int i = 0;i < this.invr.getSizeInventory();i++){
163                                 int id = 0;
164                                 int size = 0;
165                                 int damage  = 0;
166                                 ItemStack itemstack = this.invr.getStackInSlot(i);
167                                 if(itemstack != null){
168                                         id = itemstack.itemID;
169                                         size = itemstack.stackSize;
170                                         damage = itemstack.getItemDamage();
171                                         dos.writeInt(id);
172                                         dos.writeByte(size);
173                                         dos.writeInt(damage);
174                                 }else{
175                                         dos.writeInt(0);
176                                         dos.writeByte(0);
177                                         dos.writeInt(0);
178                                 }
179                         }
180
181                 } catch (Exception e) {
182                         e.printStackTrace();
183                 }
184         }
185
186         public void setAtoms(String par1){
187
188         }
189
190         public String getAtoms(){
191                 return this.atomsList;
192         }
193
194         public ArrayList<String> getAtomsList(){
195                 return this.atomsList;
196         }
197
198         public ArrayList<Integer> getAtomsAmountList(){
199                 return this.atomsAmountList;
200         }
201
202         protected boolean isNumber(String par1){
203                 try {
204                         int var1 = Integer.valueOf(new String(par1));
205                 } catch (Exception e) {
206                         return false;
207                 }
208                 return true;
209         }
210
211         public InventoryChemicalCombinationTableMaterial getInvMaterial(){
212                 return this.invm;
213         }
214
215         public InventoryChemicalCombinationTableResult getInvResult(){
216                 return this.invr;
217         }
218
219 }