14
14
import net .minecraft .entity .item .EntityItem ;
15
15
import net .minecraft .entity .player .EntityPlayer ;
16
16
import net .minecraft .item .ItemStack ;
17
+ import net .minecraft .nbt .NBTTagCompound ;
18
+ import net .minecraft .nbt .NBTTagIntArray ;
19
+ import net .minecraft .nbt .NBTTagList ;
17
20
import net .minecraft .util .AxisAlignedBB ;
18
21
import net .minecraft .util .DamageSource ;
19
22
import net .minecraft .util .MathHelper ;
22
25
import net .minecraft .world .Explosion ;
23
26
import net .minecraft .world .World ;
24
27
28
+ import net .minecraftforge .common .util .Constants ;
29
+
25
30
import java .util .ArrayList ;
26
31
import java .util .HashSet ;
27
32
import java .util .List ;
33
38
@ Getter
34
39
public abstract class GT_Explosion <TierType extends Enum <TierType > & IGT_ExplosiveTier <TierType >> extends Explosion {
35
40
36
- protected final List <ItemStack > harvested = new ArrayList <>();
37
-
38
- protected final Set <ChunkPosition > seen = new HashSet <>(), targeted = new HashSet <>();
41
+ protected final Set <ChunkPosition > targeted = new HashSet <>();
39
42
40
43
private final GT_Entity_Explosive gtExplosive ;
41
44
@@ -52,6 +55,33 @@ public GT_Explosion(
52
55
this .isSmoking = true ;
53
56
}
54
57
58
+ public NBTTagCompound serializeNBT () {
59
+ val nbt = new NBTTagCompound ();
60
+ val targeted = new NBTTagList ();
61
+ nbt .setTag ("targeted" , targeted );
62
+ for (val pos : this .targeted ) {
63
+ targeted .appendTag (new NBTTagIntArray (serializePos (pos )));
64
+ }
65
+ return nbt ;
66
+ }
67
+
68
+ public void deserializeNBT (NBTTagCompound nbt ) {
69
+ targeted .clear ();
70
+ val t = nbt .getTagList ("targeted" , Constants .NBT .TAG_INT_ARRAY );
71
+ int length = t .tagCount ();
72
+ for (int i = 0 ; i < length ; i ++) {
73
+ targeted .add (deserializePos (t .func_150306_c (i )));
74
+ }
75
+ }
76
+
77
+ public static int [] serializePos (final ChunkPosition pos ) {
78
+ return new int []{pos .chunkPosX , pos .chunkPosY , pos .chunkPosZ };
79
+ }
80
+
81
+ public static ChunkPosition deserializePos (final int [] nbt ) {
82
+ return new ChunkPosition (nbt [0 ], nbt [1 ], nbt [2 ]);
83
+ }
84
+
55
85
public int getX () {
56
86
return (int ) explosionX ;
57
87
}
@@ -122,6 +152,7 @@ public void doExplosionB(final boolean shouldDoParticles) {
122
152
} else {
123
153
blocksToDestroy = targeted ;
124
154
}
155
+ val harvested = new HashSet <ItemStack >();
125
156
for (ChunkPosition position : blocksToDestroy ) {
126
157
int i , j , k , meta ;
127
158
Block block ;
@@ -136,12 +167,12 @@ public void doExplosionB(final boolean shouldDoParticles) {
136
167
}
137
168
if (block .getMaterial () != Material .air ) {
138
169
if (block .canDropFromExplosion (this )) {
139
- getDrops (block , i , j , k , meta );
170
+ getDrops (harvested , block , i , j , k , meta );
140
171
}
141
172
destroyBlock (block , i , j , k );
142
173
}
143
174
}
144
- processDrops ();
175
+ processDrops (harvested );
145
176
}
146
177
147
178
protected void explosionPost () {
@@ -240,7 +271,7 @@ protected void doParticles(final float x, final float y, final float z) {
240
271
pubWorld .spawnParticle ("smoke" , d0 , d1 , d2 , d3 , d4 , d5 );
241
272
}
242
273
243
- protected void getDrops (final Block block , final int x , final int y , final int z , final int metadata ) {
274
+ protected void getDrops (Set < ItemStack > harvested , final Block block , final int x , final int y , final int z , final int metadata ) {
244
275
if (!pubWorld .isRemote ) {
245
276
final float chance = getDropChance (block );
246
277
ArrayList <ItemStack > items = block .getDrops (pubWorld , x , y , z , metadata , getFortune ());
@@ -252,7 +283,7 @@ protected void destroyBlock(final Block block, final int i, final int j, final i
252
283
block .onBlockExploded (pubWorld , i , j , k , this );
253
284
}
254
285
255
- protected void processDrops () {
286
+ protected void processDrops (Set < ItemStack > harvested ) {
256
287
harvested .forEach (this ::spawnItem );
257
288
}
258
289
@@ -291,7 +322,7 @@ protected boolean hasEncountered(final int x, final int y, final int z) {
291
322
}
292
323
293
324
protected boolean hasEncountered (final ChunkPosition pos ) {
294
- return seen . contains ( pos ) || targeted .contains (pos );
325
+ return targeted .contains (pos );
295
326
}
296
327
297
328
protected float getRayPower () {
0 commit comments