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