2121
2222import com .google .common .collect .ImmutableList ;
2323import 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 ;
3132import com .sk89q .worldedit .world .block .BaseBlock ;
3233import com .sk89q .worldedit .world .block .BlockState ;
3334import com .sk89q .worldedit .world .storage .InvalidFormatException ;
3435
35- import java .util .HashMap ;
36- import java .util .Map ;
37-
3836/**
3937 * A mob spawner block.
4038 */
@@ -46,8 +44,8 @@ public class MobSpawnerBlock extends BaseBlock {
4644 // advanced mob spawner features
4745 private short spawnCount = 4 ;
4846 private short spawnRange = 4 ;
49- private CompoundTag spawnData ;
50- private ListTag spawnPotentials ;
47+ private CompoundBinaryTag spawnData ;
48+ private ListBinaryTag spawnPotentials ;
5149 private short minSpawnDelay = 200 ;
5250 private short maxSpawnDelay = 800 ;
5351 private short maxNearbyEntities = 6 ;
@@ -110,7 +108,7 @@ public void setDelay(short delay) {
110108 }
111109
112110 @ Override
113- public boolean hasNbtData () {
111+ public boolean hasNbt () {
114112 return true ;
115113 }
116114
@@ -120,50 +118,52 @@ public String getNbtId() {
120118 }
121119
122120 @ 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 ));
132130 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 ( ));
134132 } else {
135- values .put ("SpawnData" , new CompoundTag ( spawnData . getValue ()) );
133+ values .put ("SpawnData" , spawnData );
136134 }
137135 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+ ));
141143 } else {
142- values .put ("SpawnPotentials" , new ListTag ( CompoundTag . class , spawnPotentials . getValue ()) );
144+ values .put ("SpawnPotentials" , spawnPotentials );
143145 }
144146
145- return new CompoundTag ( values );
147+ return values . build ( );
146148 }
147149
148150 @ Override
149- public void setNbtData ( CompoundTag rootTag ) {
151+ public void setNbt ( CompoundBinaryTag rootTag ) {
150152 if (rootTag == null ) {
151153 return ;
152154 }
153155
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 ())) {
158158 throw new RuntimeException (String .format ("'%s' tile entity expected" , getNbtId ()));
159159 }
160160
161- CompoundTag spawnDataTag ;
161+ CompoundBinaryTag spawnDataTag ;
162162 String mobType ;
163- ShortTag delayTag ;
163+ ShortBinaryTag delayTag ;
164164
165165 try {
166- spawnDataTag = NBTUtils .getChildTag (values , "SpawnData" , CompoundTag .class );
166+ spawnDataTag = NbtUtils .getChildTag (rootTag , "SpawnData" , CompoundBinaryTag .class );
167167 mobType = spawnDataTag .getString ("id" );
168168 if (mobType .equals ("" )) {
169169 throw new InvalidFormatException ("No spawn id." );
@@ -174,68 +174,68 @@ public void setNbtData(CompoundTag rootTag) {
174174 throw new RuntimeException ("Invalid mob spawner data: no SpawnData and/or no Delay" );
175175 }
176176 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 ();
179179 } catch (InvalidFormatException ignored ) {
180180 this .delay = -1 ;
181181 }
182182
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 ;
190190 try {
191- spawnCountTag = NBTUtils .getChildTag (values , "SpawnCount" , ShortTag .class );
191+ spawnCountTag = NbtUtils .getChildTag (rootTag , "SpawnCount" , ShortBinaryTag .class );
192192 } catch (InvalidFormatException ignored ) {
193193 }
194194 try {
195- spawnRangeTag = NBTUtils .getChildTag (values , "SpawnRange" , ShortTag .class );
195+ spawnRangeTag = NbtUtils .getChildTag (rootTag , "SpawnRange" , ShortBinaryTag .class );
196196 } catch (InvalidFormatException ignored ) {
197197 }
198198 try {
199- minSpawnDelayTag = NBTUtils .getChildTag (values , "MinSpawnDelay" , ShortTag .class );
199+ minSpawnDelayTag = NbtUtils .getChildTag (rootTag , "MinSpawnDelay" , ShortBinaryTag .class );
200200 } catch (InvalidFormatException ignored ) {
201201 }
202202 try {
203- maxSpawnDelayTag = NBTUtils .getChildTag (values , "MaxSpawnDelay" , ShortTag .class );
203+ maxSpawnDelayTag = NbtUtils .getChildTag (rootTag , "MaxSpawnDelay" , ShortBinaryTag .class );
204204 } catch (InvalidFormatException ignored ) {
205205 }
206206 try {
207- maxNearbyEntitiesTag = NBTUtils .getChildTag (values , "MaxNearbyEntities" , ShortTag .class );
207+ maxNearbyEntitiesTag = NbtUtils .getChildTag (rootTag , "MaxNearbyEntities" , ShortBinaryTag .class );
208208 } catch (InvalidFormatException ignored ) {
209209 }
210210 try {
211- requiredPlayerRangeTag = NBTUtils .getChildTag (values , "RequiredPlayerRange" , ShortTag .class );
211+ requiredPlayerRangeTag = NbtUtils .getChildTag (rootTag , "RequiredPlayerRange" , ShortBinaryTag .class );
212212 } catch (InvalidFormatException ignored ) {
213213 }
214214 try {
215- spawnPotentialsTag = NBTUtils .getChildTag (values , "SpawnPotentials" , ListTag .class );
215+ spawnPotentialsTag = NbtUtils .getChildTag (rootTag , "SpawnPotentials" , ListBinaryTag .class );
216216 } catch (InvalidFormatException ignored ) {
217217 }
218218
219219 if (spawnCountTag != null ) {
220- this .spawnCount = spawnCountTag .getValue ();
220+ this .spawnCount = spawnCountTag .value ();
221221 }
222222 if (spawnRangeTag != null ) {
223- this .spawnRange = spawnRangeTag .getValue ();
223+ this .spawnRange = spawnRangeTag .value ();
224224 }
225225 if (minSpawnDelayTag != null ) {
226- this .minSpawnDelay = minSpawnDelayTag .getValue ();
226+ this .minSpawnDelay = minSpawnDelayTag .value ();
227227 }
228228 if (maxSpawnDelayTag != null ) {
229- this .maxSpawnDelay = maxSpawnDelayTag .getValue ();
229+ this .maxSpawnDelay = maxSpawnDelayTag .value ();
230230 }
231231 if (maxNearbyEntitiesTag != null ) {
232- this .maxNearbyEntities = maxNearbyEntitiesTag .getValue ();
232+ this .maxNearbyEntities = maxNearbyEntitiesTag .value ();
233233 }
234234 if (requiredPlayerRangeTag != null ) {
235- this .requiredPlayerRange = requiredPlayerRangeTag .getValue ();
235+ this .requiredPlayerRange = requiredPlayerRangeTag .value ();
236236 }
237237 if (spawnPotentialsTag != null ) {
238- this .spawnPotentials = new ListTag ( CompoundTag . class , spawnPotentialsTag . getValue ()) ;
238+ this .spawnPotentials = spawnPotentialsTag ;
239239 }
240240 }
241241
0 commit comments