OSDN Git Service

化学作業台のBlock画像追加
[chemicraft/chemicraft.git] / common / chemicraft / TileEntityChemicalCraftingTable.java
1 package chemicraft;
2
3 import java.io.DataOutputStream;
4
5 import net.minecraft.src.IInventory;
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 net.minecraft.src.WorldClient;
12 import net.minecraft.src.WorldServer;
13
14 import com.google.common.io.ByteArrayDataInput;
15
16 import cpw.mods.fml.common.network.PacketDispatcher;
17
18 public class TileEntityChemicalCraftingTable extends TileEntity {
19
20         /**
21          * DecompositionのInventory
22          */
23         public IInventory decompositionInv = new InventoryDecomposition();
24
25         /**
26          * ActiveなTabの名前
27          */
28         private String activeTab;
29
30
31         public TileEntityChemicalCraftingTable() {
32                 super();
33                 // ActiveTabのデフォルトを設定
34                 this.activeTab = "Decomposition";
35         }
36
37         int time = 0;
38         @Override
39         public void updateEntity() {
40                 super.updateEntity();
41         }
42
43
44         @Override
45         public void readFromNBT(NBTTagCompound par1) {
46                 super.readFromNBT(par1);
47
48                 this.activeTab = par1.getString("activeTab");
49
50                 NBTTagList var2 = par1.getTagList("Items");
51                 for (int var3 = 0; var3 < var2.tagCount(); ++var3)
52                 {
53                         NBTTagCompound var4 = (NBTTagCompound)var2.tagAt(var3);
54                         int var5 = var4.getByte("Slot") & 255;
55
56                         if (var5 >= 0 && var5 < this.decompositionInv.getSizeInventory())
57                         {
58                                 this.decompositionInv.setInventorySlotContents(var5, ItemStack.loadItemStackFromNBT(var4));
59                         }
60                 }
61         }
62
63
64         @Override
65         public void writeToNBT(NBTTagCompound par1) {
66                 super.writeToNBT(par1);
67
68                 par1.setString("activeTab", this.activeTab);
69
70                 NBTTagList var2 = new NBTTagList();
71                 for (int var3 = 0; var3 < this.decompositionInv.getSizeInventory(); ++var3)
72                 {
73                         if (this.decompositionInv.getStackInSlot(var3) != null)
74                         {
75                                 NBTTagCompound var4 = new NBTTagCompound();
76                                 var4.setByte("Slot", (byte)var3);
77                                 this.decompositionInv.getStackInSlot(var3).writeToNBT(var4);
78                                 var2.appendTag(var4);
79                         }
80                 }
81                 par1.setTag("Items", var2);
82         }
83
84
85         public String getActiveTab() {
86                 return this.activeTab;
87         }
88
89
90         public void setActiveTab(String activeTab) {
91                 this.activeTab = activeTab;
92                 PacketDispatcher.sendPacketToServer(this.getDescriptionPacket());
93         }
94
95
96         public IInventory getActiveInventory(){
97                 if(this.activeTab.equals("Decomposition")){
98                         return this.decompositionInv;
99                 }else{
100                         return null;
101                 }
102         }
103
104
105         @Override
106         public Packet getDescriptionPacket() {
107                 return PacketHandler.getPacket(this);
108         }
109
110
111         public void readPacket(ByteArrayDataInput data) {
112                 try {
113                         this.activeTab = data.readUTF();
114                         for(int i = 0;i < this.decompositionInv.getSizeInventory();i++){
115                                 int id = data.readInt();
116                                 int damage = data.readInt();
117                                 int size = data.readInt();
118                                 if(id != 0){
119                                         this.decompositionInv.setInventorySlotContents(i, new ItemStack(id, size, damage));
120                                 }
121                         }
122                 } catch (Exception e) {
123                         e.printStackTrace();
124                 }
125         }
126
127
128         public void writePacket(DataOutputStream dos){
129                 try {
130                         dos.writeUTF(this.activeTab);
131                         for(int i = 0;i < this.decompositionInv.getSizeInventory();i++){
132                                 if(this.decompositionInv.getStackInSlot(i) != null){
133                                         dos.writeInt(this.decompositionInv.getStackInSlot(i).itemID);
134                                         dos.writeInt(this.decompositionInv.getStackInSlot(i).getItemDamage());
135                                         dos.writeInt(this.decompositionInv.getStackInSlot(i).stackSize);
136                                 }else{
137                                         dos.writeInt(0);
138                                         dos.writeInt(0);
139                                         dos.writeInt(0);
140                                 }
141                         }
142                 } catch (Exception e) {
143                         e.printStackTrace();
144                 }
145         }
146
147 }