-
Notifications
You must be signed in to change notification settings - Fork 755
/
TileEntityLandmine.java
266 lines (227 loc) · 6.62 KB
/
TileEntityLandmine.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
package tconstruct.blocks.logic;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.*;
import net.minecraft.network.*;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
/**
*
* @author fuj1n
*
*/
public class TileEntityLandmine extends TileEntity implements IInventory
{
private ItemStack[] inventory = new ItemStack[getSizeInventory()];
private String containerName;
public int soundcountythingmax = 10;
public int soundcountything = 0;
private boolean shouldUpdateLogic = true;
public int triggerType;
public boolean isExploding = false;
public int getSizeTriggerInventory ()
{
return 3;
}
@Override
public int getSizeInventory ()
{
return 4;
}
@Override
public void func_145841_b (NBTTagCompound par1NBTTagCompound)
{
super.func_145841_b(par1NBTTagCompound);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.inventory.length; ++i)
{
if (this.inventory[i] != null)
{
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte) i);
this.inventory[i].writeToNBT(nbttagcompound1);
nbttaglist.appendTag(nbttagcompound1);
}
}
par1NBTTagCompound.setTag("Items", nbttaglist);
par1NBTTagCompound.setInteger("triggerType", triggerType);
if (this.isInvNameLocalized())
{
par1NBTTagCompound.setString("CustomName", this.containerName);
}
}
@Override
public void func_145839_a (NBTTagCompound par1NBTTagCompound)
{
super.func_145839_a(par1NBTTagCompound);
NBTTagList nbttaglist = par1NBTTagCompound.getTagList("Items");
this.inventory = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.func_150305_b(i);
byte b0 = nbttagcompound1.getByte("Slot");
if (b0 >= 0 && b0 < this.inventory.length)
{
this.inventory[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
}
}
triggerType = par1NBTTagCompound.getInteger("triggerType");
if (par1NBTTagCompound.hasKey("CustomName"))
{
this.containerName = par1NBTTagCompound.getString("CustomName");
}
}
@Override
public Packet func_145844_m ()
{
NBTTagCompound nbt = new NBTTagCompound();
func_145841_b(nbt);
return new S35PacketUpdateTileEntity(field_145851_c, field_145848_d, field_145849_e, 0, nbt);
}
@Override
public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity packet)
{
func_145839_a(packet.func_148857_g());
}
@Override
public ItemStack getStackInSlot (int i)
{
if (i < inventory.length)
{
return inventory[i];
}
else
{
return null;
}
}
@Override
public ItemStack decrStackSize (int par1, int par2)
{
if (par1 < inventory.length)
{
if (inventory[par1] != null)
{
ItemStack itemstack;
if (inventory[par1].stackSize <= par2)
{
itemstack = inventory[par1];
inventory[par1] = null;
return itemstack;
}
else
{
itemstack = inventory[par1].splitStack(par2);
if (inventory[par1].stackSize == 0)
{
inventory[par1] = null;
}
return itemstack;
}
}
else
{
return null;
}
}
else
{
return null;
}
}
@Override
public ItemStack getStackInSlotOnClosing (int i)
{
if (i < inventory.length && this.inventory[i] != null)
{
ItemStack itemstack = this.inventory[i];
this.inventory[i] = null;
return itemstack;
}
else
{
return null;
}
}
@Override
public void setInventorySlotContents (int i, ItemStack itemstack)
{
if (i < inventory.length)
{
inventory[i] = itemstack;
}
}
@Override
public String getInvName ()
{
return this.isInvNameLocalized() ? this.containerName : "Landmine";
}
@Override
public boolean isInvNameLocalized ()
{
return containerName != null && containerName.length() > 0;
}
@Override
public int getInventoryStackLimit ()
{
return 64;
}
public void setGuiDisplayName (String par1Str)
{
this.containerName = par1Str;
}
@Override
public boolean isUseableByPlayer (EntityPlayer par1EntityPlayer)
{
return this.field_145850_b.func_147438_o(this.field_145851_c, this.field_145848_d, this.field_145849_e) != this ? false : par1EntityPlayer.getDistanceSq((double) this.field_145851_c + 0.5D, (double) this.field_145848_d + 0.5D,
(double) this.field_145849_e + 0.5D) <= 64.0D;
}
@Override
public void openChest ()
{
}
@Override
public void closeChest ()
{
}
@Override
public void onInventoryChanged ()
{
super.onInventoryChanged();
this.field_145850_b.func_147471_g(field_145851_c, field_145848_d, field_145849_e);
}
@Override
public boolean isItemValidForSlot (int i, ItemStack itemstack)
{
//Should automatic camo insertion be allowed.
if (i == 3)
{
return false;
}
else
{
//Here for mDiyo to decide if he wants automation for insertion/extraction of the items to be an option.
//Would be useful for building automated mine laying machines.
return false;
}
}
public void setSoundPlayed ()
{
soundcountythingmax = 35;
soundcountything = soundcountythingmax;
}
@Override
public void func_145845_h ()
{
if (shouldUpdateLogic)
{
field_145850_b.func_147479_m(field_145851_c, field_145848_d, field_145849_e);
shouldUpdateLogic = false;
}
if (soundcountything > 0)
{
soundcountything--;
}
}
}