OSDN Git Service

文字化け用
[chemicraft/chemicraft.git] / common / chemicraft / TileEntityDecompositionTable.java
1 package chemicraft;
2
3 import java.io.DataOutputStream;
4
5 import net.minecraft.src.EntityPlayer;
6 import net.minecraft.src.IInventory;
7 import net.minecraft.src.ItemStack;
8 import net.minecraft.src.NBTTagCompound;
9 import net.minecraft.src.NBTTagList;
10 import net.minecraft.src.Packet;
11 import net.minecraft.src.TileEntity;
12 import net.minecraft.src.WorldServer;
13
14 import com.google.common.io.ByteArrayDataInput;
15
16 public class TileEntityDecompositionTable extends TileEntity {
17
18         private IInventory decompositionInv = new InventoryDecomposition();
19
20         private boolean isItemDrop = false;
21
22         public TileEntityDecompositionTable() {
23                 super();
24         }
25
26         @Override
27         public void updateEntity() {
28                 super.updateEntity();
29         }
30
31
32         @Override
33         public void readFromNBT(NBTTagCompound par1) {
34                 super.readFromNBT(par1);
35
36                 NBTTagList var2 = par1.getTagList("Items");
37                 for (int var3 = 0; var3 < var2.tagCount(); ++var3)
38                 {
39                         NBTTagCompound var4 = (NBTTagCompound)var2.tagAt(var3);
40                         int var5 = var4.getByte("Slot") & 255;
41
42                         if (var5 >= 0 && var5 < this.decompositionInv.getSizeInventory())
43                         {
44                                 this.decompositionInv.setInventorySlotContents(var5, ItemStack.loadItemStackFromNBT(var4));
45                         }
46                 }
47         }
48
49
50         @Override
51         public void writeToNBT(NBTTagCompound par1) {
52                 super.writeToNBT(par1);
53
54                 NBTTagList var2 = new NBTTagList();
55                 for (int var3 = 0; var3 < this.decompositionInv.getSizeInventory(); ++var3)
56                 {
57                         if (this.decompositionInv.getStackInSlot(var3) != null)
58                         {
59                                 NBTTagCompound var4 = new NBTTagCompound();
60                                 var4.setByte("Slot", (byte)var3);
61                                 this.decompositionInv.getStackInSlot(var3).writeToNBT(var4);
62                                 var2.appendTag(var4);
63                         }
64                 }
65                 par1.setTag("Items", var2);
66         }
67
68
69         public InventoryDecomposition getInventorys(){
70                 return (InventoryDecomposition) this.decompositionInv;
71         }
72
73
74         public void setItemDrop(boolean par1){
75                 this.isItemDrop = par1;
76         }
77
78
79         @Override
80         public Packet getDescriptionPacket() {
81                 return PacketHandler.getPacket(this);
82         }
83
84
85         public void readPacket(ByteArrayDataInput data, EntityPlayer entityPlayer) {
86                 int id;
87                 int damage;
88                 int size;
89                 try {
90
91                         this.isItemDrop = data.readBoolean();
92
93                         for(int i = 0;i < 16;i++){
94                                 id = data.readInt();
95                                 damage = data.readInt();
96                                 size = data.readInt();
97                                 if(id != 0){
98                                         if(!this.isItemDrop){
99                                                 entityPlayer.inventory.addItemStackToInventory(new ItemStack(id, size, damage));
100                                         }else{
101                                                 entityPlayer.dropPlayerItem(new ItemStack(id, size, damage));
102                                         }
103                                 }
104                         }
105                         id = data.readInt();
106                         damage = data.readInt();
107                         size = data.readInt();
108                         if(id != 0){
109                                 if(entityPlayer.worldObj instanceof WorldServer){
110                                         this.decompositionInv.setInventorySlotContents(16, new ItemStack(id, --size, damage));
111                                 }
112                         }
113                 } catch (Exception e) {
114                         e.printStackTrace();
115                 }
116         }
117
118
119         public void writePacket(DataOutputStream dos){
120                 try {
121
122                         dos.writeBoolean(this.isItemDrop);
123
124                         for(int i = 0;i < this.decompositionInv.getSizeInventory();i++){
125                                 if(this.decompositionInv.getStackInSlot(i) != null){
126                                         dos.writeInt(this.decompositionInv.getStackInSlot(i).itemID);
127                                         dos.writeInt(this.decompositionInv.getStackInSlot(i).getItemDamage());
128                                         dos.writeInt(this.decompositionInv.getStackInSlot(i).stackSize);
129                                 }else{
130                                         dos.writeInt(0);
131                                         dos.writeInt(0);
132                                         dos.writeInt(0);
133                                 }
134                         }
135
136                 } catch (Exception e) {
137                         e.printStackTrace();
138                 }
139         }
140
141 }