21
21
22
22
import com .google .common .collect .ImmutableList ;
23
23
import com .google .common .collect .ImmutableMap ;
24
- import com .sk89q .worldedit .util .NbtUtils ;
25
- import com .sk89q .worldedit .util .nbt .BinaryTag ;
26
- import com .sk89q .worldedit .util .nbt .BinaryTagTypes ;
27
- import com .sk89q .worldedit .util .nbt .CompoundBinaryTag ;
28
- import com .sk89q .worldedit .util .nbt .IntBinaryTag ;
29
- import com .sk89q .worldedit .util .nbt .ListBinaryTag ;
30
- import com .sk89q .worldedit .util .nbt .ShortBinaryTag ;
31
- import com .sk89q .worldedit .util .nbt .StringBinaryTag ;
24
+ import com .sk89q .jnbt .CompoundTag ;
25
+ import com .sk89q .jnbt .IntTag ;
26
+ import com .sk89q .jnbt .ListTag ;
27
+ import com .sk89q .jnbt .NBTUtils ;
28
+ import com .sk89q .jnbt .ShortTag ;
29
+ import com .sk89q .jnbt .StringTag ;
30
+ import com .sk89q .jnbt .Tag ;
32
31
import com .sk89q .worldedit .world .block .BaseBlock ;
33
32
import com .sk89q .worldedit .world .block .BlockState ;
34
33
import com .sk89q .worldedit .world .storage .InvalidFormatException ;
35
34
35
+ import java .util .HashMap ;
36
+ import java .util .Map ;
37
+
36
38
/**
37
39
* A mob spawner block.
40
+ *
41
+ * @deprecated WorldEdit does not handle interpreting NBT,
42
+ * deprecated for removal without replacement
38
43
*/
44
+ @ Deprecated
39
45
public class MobSpawnerBlock extends BaseBlock {
40
46
41
47
private String mobType ;
@@ -44,8 +50,8 @@ public class MobSpawnerBlock extends BaseBlock {
44
50
// advanced mob spawner features
45
51
private short spawnCount = 4 ;
46
52
private short spawnRange = 4 ;
47
- private CompoundBinaryTag spawnData ;
48
- private ListBinaryTag spawnPotentials ;
53
+ private CompoundTag spawnData ;
54
+ private ListTag spawnPotentials ;
49
55
private short minSpawnDelay = 200 ;
50
56
private short maxSpawnDelay = 800 ;
51
57
private short maxNearbyEntities = 6 ;
@@ -108,7 +114,7 @@ public void setDelay(short delay) {
108
114
}
109
115
110
116
@ Override
111
- public boolean hasNbt () {
117
+ public boolean hasNbtData () {
112
118
return true ;
113
119
}
114
120
@@ -118,52 +124,50 @@ public String getNbtId() {
118
124
}
119
125
120
126
@ Override
121
- public CompoundBinaryTag getNbt () {
122
- CompoundBinaryTag . Builder values = CompoundBinaryTag . builder ();
123
- values .put ("Delay" , ShortBinaryTag . of (delay ));
124
- values .put ("SpawnCount" , ShortBinaryTag . of (spawnCount ));
125
- values .put ("SpawnRange" , ShortBinaryTag . of (spawnRange ));
126
- values .put ("MinSpawnDelay" , ShortBinaryTag . of (minSpawnDelay ));
127
- values .put ("MaxSpawnDelay" , ShortBinaryTag . of (maxSpawnDelay ));
128
- values .put ("MaxNearbyEntities" , ShortBinaryTag . of (maxNearbyEntities ));
129
- values .put ("RequiredPlayerRange" , ShortBinaryTag . of (requiredPlayerRange ));
127
+ public CompoundTag getNbtData () {
128
+ Map < String , Tag > values = new HashMap <> ();
129
+ values .put ("Delay" , new ShortTag (delay ));
130
+ values .put ("SpawnCount" , new ShortTag (spawnCount ));
131
+ values .put ("SpawnRange" , new ShortTag (spawnRange ));
132
+ values .put ("MinSpawnDelay" , new ShortTag (minSpawnDelay ));
133
+ values .put ("MaxSpawnDelay" , new ShortTag (maxSpawnDelay ));
134
+ values .put ("MaxNearbyEntities" , new ShortTag (maxNearbyEntities ));
135
+ values .put ("RequiredPlayerRange" , new ShortTag (requiredPlayerRange ));
130
136
if (spawnData == null ) {
131
- values .put ("SpawnData" , CompoundBinaryTag . builder (). put ("id" , StringBinaryTag . of (mobType )). build ( ));
137
+ values .put ("SpawnData" , new CompoundTag ( ImmutableMap . of ("id" , new StringTag (mobType ))));
132
138
} else {
133
- values .put ("SpawnData" , spawnData );
139
+ values .put ("SpawnData" , new CompoundTag ( spawnData . getValue ()) );
134
140
}
135
141
if (spawnPotentials == null ) {
136
- values .put ("SpawnPotentials" , ListBinaryTag .of (
137
- BinaryTagTypes .COMPOUND ,
138
- ImmutableList .of (CompoundBinaryTag .from (ImmutableMap .of (
139
- "Weight" , IntBinaryTag .of (1 ),
140
- "Entity" , CompoundBinaryTag .from (ImmutableMap .of ("id" , StringBinaryTag .of (mobType )))
141
- )))
142
- ));
142
+ values .put ("SpawnPotentials" , new ListTag (CompoundTag .class , ImmutableList .of (
143
+ new CompoundTag (ImmutableMap .of ("Weight" , new IntTag (1 ), "Entity" ,
144
+ new CompoundTag (ImmutableMap .of ("id" , new StringTag (mobType ))))))));
143
145
} else {
144
- values .put ("SpawnPotentials" , spawnPotentials );
146
+ values .put ("SpawnPotentials" , new ListTag ( CompoundTag . class , spawnPotentials . getValue ()) );
145
147
}
146
148
147
- return values . build ( );
149
+ return new CompoundTag ( values );
148
150
}
149
151
150
152
@ Override
151
- public void setNbt ( CompoundBinaryTag rootTag ) {
153
+ public void setNbtData ( CompoundTag rootTag ) {
152
154
if (rootTag == null ) {
153
155
return ;
154
156
}
155
157
156
- BinaryTag t = rootTag .get ("id" );
157
- if (!(t instanceof StringBinaryTag ) || !((StringBinaryTag ) t ).value ().equals (getNbtId ())) {
158
+ Map <String , Tag > values = rootTag .getValue ();
159
+
160
+ Tag t = values .get ("id" );
161
+ if (!(t instanceof StringTag ) || !((StringTag ) t ).getValue ().equals (getNbtId ())) {
158
162
throw new RuntimeException (String .format ("'%s' tile entity expected" , getNbtId ()));
159
163
}
160
164
161
- CompoundBinaryTag spawnDataTag ;
165
+ CompoundTag spawnDataTag ;
162
166
String mobType ;
163
- ShortBinaryTag delayTag ;
167
+ ShortTag delayTag ;
164
168
165
169
try {
166
- spawnDataTag = NbtUtils .getChildTag (rootTag , "SpawnData" , CompoundBinaryTag .class );
170
+ spawnDataTag = NBTUtils .getChildTag (values , "SpawnData" , CompoundTag .class );
167
171
mobType = spawnDataTag .getString ("id" );
168
172
if (mobType .equals ("" )) {
169
173
throw new InvalidFormatException ("No spawn id." );
@@ -174,68 +178,68 @@ public void setNbt(CompoundBinaryTag rootTag) {
174
178
throw new RuntimeException ("Invalid mob spawner data: no SpawnData and/or no Delay" );
175
179
}
176
180
try {
177
- delayTag = NbtUtils .getChildTag (rootTag , "Delay" , ShortBinaryTag .class );
178
- this .delay = delayTag .value ();
181
+ delayTag = NBTUtils .getChildTag (values , "Delay" , ShortTag .class );
182
+ this .delay = delayTag .getValue ();
179
183
} catch (InvalidFormatException ignored ) {
180
184
this .delay = -1 ;
181
185
}
182
186
183
- ShortBinaryTag spawnCountTag = null ;
184
- ShortBinaryTag spawnRangeTag = null ;
185
- ShortBinaryTag minSpawnDelayTag = null ;
186
- ShortBinaryTag maxSpawnDelayTag = null ;
187
- ShortBinaryTag maxNearbyEntitiesTag = null ;
188
- ShortBinaryTag requiredPlayerRangeTag = null ;
189
- ListBinaryTag spawnPotentialsTag = null ;
187
+ ShortTag spawnCountTag = null ;
188
+ ShortTag spawnRangeTag = null ;
189
+ ShortTag minSpawnDelayTag = null ;
190
+ ShortTag maxSpawnDelayTag = null ;
191
+ ShortTag maxNearbyEntitiesTag = null ;
192
+ ShortTag requiredPlayerRangeTag = null ;
193
+ ListTag spawnPotentialsTag = null ;
190
194
try {
191
- spawnCountTag = NbtUtils .getChildTag (rootTag , "SpawnCount" , ShortBinaryTag .class );
195
+ spawnCountTag = NBTUtils .getChildTag (values , "SpawnCount" , ShortTag .class );
192
196
} catch (InvalidFormatException ignored ) {
193
197
}
194
198
try {
195
- spawnRangeTag = NbtUtils .getChildTag (rootTag , "SpawnRange" , ShortBinaryTag .class );
199
+ spawnRangeTag = NBTUtils .getChildTag (values , "SpawnRange" , ShortTag .class );
196
200
} catch (InvalidFormatException ignored ) {
197
201
}
198
202
try {
199
- minSpawnDelayTag = NbtUtils .getChildTag (rootTag , "MinSpawnDelay" , ShortBinaryTag .class );
203
+ minSpawnDelayTag = NBTUtils .getChildTag (values , "MinSpawnDelay" , ShortTag .class );
200
204
} catch (InvalidFormatException ignored ) {
201
205
}
202
206
try {
203
- maxSpawnDelayTag = NbtUtils .getChildTag (rootTag , "MaxSpawnDelay" , ShortBinaryTag .class );
207
+ maxSpawnDelayTag = NBTUtils .getChildTag (values , "MaxSpawnDelay" , ShortTag .class );
204
208
} catch (InvalidFormatException ignored ) {
205
209
}
206
210
try {
207
- maxNearbyEntitiesTag = NbtUtils .getChildTag (rootTag , "MaxNearbyEntities" , ShortBinaryTag .class );
211
+ maxNearbyEntitiesTag = NBTUtils .getChildTag (values , "MaxNearbyEntities" , ShortTag .class );
208
212
} catch (InvalidFormatException ignored ) {
209
213
}
210
214
try {
211
- requiredPlayerRangeTag = NbtUtils .getChildTag (rootTag , "RequiredPlayerRange" , ShortBinaryTag .class );
215
+ requiredPlayerRangeTag = NBTUtils .getChildTag (values , "RequiredPlayerRange" , ShortTag .class );
212
216
} catch (InvalidFormatException ignored ) {
213
217
}
214
218
try {
215
- spawnPotentialsTag = NbtUtils .getChildTag (rootTag , "SpawnPotentials" , ListBinaryTag .class );
219
+ spawnPotentialsTag = NBTUtils .getChildTag (values , "SpawnPotentials" , ListTag .class );
216
220
} catch (InvalidFormatException ignored ) {
217
221
}
218
222
219
223
if (spawnCountTag != null ) {
220
- this .spawnCount = spawnCountTag .value ();
224
+ this .spawnCount = spawnCountTag .getValue ();
221
225
}
222
226
if (spawnRangeTag != null ) {
223
- this .spawnRange = spawnRangeTag .value ();
227
+ this .spawnRange = spawnRangeTag .getValue ();
224
228
}
225
229
if (minSpawnDelayTag != null ) {
226
- this .minSpawnDelay = minSpawnDelayTag .value ();
230
+ this .minSpawnDelay = minSpawnDelayTag .getValue ();
227
231
}
228
232
if (maxSpawnDelayTag != null ) {
229
- this .maxSpawnDelay = maxSpawnDelayTag .value ();
233
+ this .maxSpawnDelay = maxSpawnDelayTag .getValue ();
230
234
}
231
235
if (maxNearbyEntitiesTag != null ) {
232
- this .maxNearbyEntities = maxNearbyEntitiesTag .value ();
236
+ this .maxNearbyEntities = maxNearbyEntitiesTag .getValue ();
233
237
}
234
238
if (requiredPlayerRangeTag != null ) {
235
- this .requiredPlayerRange = requiredPlayerRangeTag .value ();
239
+ this .requiredPlayerRange = requiredPlayerRangeTag .getValue ();
236
240
}
237
241
if (spawnPotentialsTag != null ) {
238
- this .spawnPotentials = spawnPotentialsTag ;
242
+ this .spawnPotentials = new ListTag ( CompoundTag . class , spawnPotentialsTag . getValue ()) ;
239
243
}
240
244
}
241
245
0 commit comments