2525
2626import java .io .IOException ;
2727import java .util .*;
28- import java .util .function .Consumer ;
2928
3029/// A [parent tag][ParentTag] that holds an unordered collection of named tags.
3130///
@@ -68,25 +67,6 @@ public CompoundTag setName(String name) throws IllegalArgumentException {
6867 return this ;
6968 }
7069
71- /// Executes the given action on this compound tag.
72- ///
73- /// This method is useful for configuring the tag.
74- ///
75- /// For example:
76- ///
77- /// ```java
78- /// var parent = new CompoundTag();
79- /// parent.put("sub", new CompoundTag().tap(t -> {
80- /// t.setByte( "byte", (byte) 1);
81- /// t.setShort("short", (short) 2);
82- /// }));
83- /// ```
84- @ Contract ("_ -> this" )
85- public CompoundTag tap (Consumer <? super CompoundTag > action ) {
86- action .accept (this );
87- return this ;
88- }
89-
9070 /// Returns the subtag with the given name, or `null` if no such subtag exists.
9171 @ Contract (pure = true )
9272 public @ Nullable Tag get (String name ) {
@@ -293,7 +273,7 @@ public CompoundTag addTag(Tag tag) {
293273 ///
294274 /// If another tag with the same name already exists, the old tag will be removed.
295275 @ Contract (mutates = "this,param2" )
296- public void addTag (String name , Tag tag ) {
276+ public CompoundTag addTag (String name , Tag tag ) {
297277 @ SuppressWarnings ("unchecked" )
298278 var oldParent = (NBTParent <Tag >) tag .getParent ();
299279 if (oldParent != null ) {
@@ -302,6 +282,7 @@ public void addTag(String name, Tag tag) {
302282
303283 tag .setName0 (name );
304284 addTag (tag );
285+ return this ;
305286 }
306287
307288 @ SuppressWarnings ("unchecked" )
@@ -328,119 +309,131 @@ private <T extends Tag> T getOrPutTag(String name, TagType<T> tagType) throws Il
328309 /// If no byte tag with the given name exists, a new byte tag will be created.
329310 ///
330311 /// @throws IllegalStateException if the tag with the given name exists but is not a byte tag.
331- @ Contract (mutates = "this" )
332- public void setByte (String name , byte value ) throws IllegalStateException {
312+ @ Contract (value = "_, _ -> this" , mutates = "this" )
313+ public CompoundTag setByte (String name , byte value ) throws IllegalStateException {
333314 getOrPutTag (name , TagType .BYTE ).set (value );
315+ return this ;
334316 }
335317
336318 /// Sets the boolean value of the [ByteTag] with the given name.
337319 ///
338320 /// If no byte tag with the given name exists, a new byte tag will be created.
339321 ///
340322 /// @throws IllegalStateException if the tag with the given name exists but is not a byte tag.
341- @ Contract (mutates = "this" )
342- public void setBoolean (String name , boolean value ) throws IllegalStateException {
323+ @ Contract (value = "_, _ -> this" , mutates = "this" )
324+ public CompoundTag setBoolean (String name , boolean value ) throws IllegalStateException {
343325 getOrPutTag (name , TagType .BYTE ).setBoolean (value );
326+ return this ;
344327 }
345328
346329 /// Sets the short value of the [ShortTag] with the given name.
347330 ///
348331 /// If no short tag with the given name exists, a new short tag will be created.
349332 ///
350333 /// @throws IllegalStateException if the tag with the given name exists but is not a short tag.
351- @ Contract (mutates = "this" )
352- public void setShort (String name , short value ) throws IllegalStateException {
334+ @ Contract (value = "_, _ -> this" , mutates = "this" )
335+ public CompoundTag setShort (String name , short value ) throws IllegalStateException {
353336 getOrPutTag (name , TagType .SHORT ).set (value );
337+ return this ;
354338 }
355339
356340 /// Sets the int value of the [IntTag] with the given name.
357341 ///
358342 /// If no int tag with the given name exists, a new int tag will be created.
359343 ///
360344 /// @throws IllegalStateException if the tag with the given name exists but is not an int tag.
361- @ Contract (mutates = "this" )
362- public void setInt (String name , int value ) throws IllegalStateException {
345+ @ Contract (value = "_, _ -> this" , mutates = "this" )
346+ public CompoundTag setInt (String name , int value ) throws IllegalStateException {
363347 getOrPutTag (name , TagType .INT ).set (value );
348+ return this ;
364349 }
365350
366351 /// Sets the long value of the [LongTag] with the given name.
367352 ///
368353 /// If no long tag with the given name exists, a new long tag will be created.
369354 ///
370355 /// @throws IllegalStateException if the tag with the given name exists but is not a long tag.
371- @ Contract (mutates = "this" )
372- public void setLong (String name , long value ) throws IllegalStateException {
356+ @ Contract (value = "_, _ -> this" , mutates = "this" )
357+ public CompoundTag setLong (String name , long value ) throws IllegalStateException {
373358 getOrPutTag (name , TagType .LONG ).set (value );
359+ return this ;
374360 }
375361
376362 /// Sets the float value of the [FloatTag] with the given name.
377363 ///
378364 /// If no float tag with the given name exists, a new float tag will be created.
379365 ///
380366 /// @throws IllegalStateException if the tag with the given name exists but is not a float tag.
381- @ Contract (mutates = "this" )
382- public void setFloat (String name , float value ) throws IllegalStateException {
367+ @ Contract (value = "_, _ -> this" , mutates = "this" )
368+ public CompoundTag setFloat (String name , float value ) throws IllegalStateException {
383369 getOrPutTag (name , TagType .FLOAT ).set (value );
370+ return this ;
384371 }
385372
386373 /// Sets the double value of the [DoubleTag] with the given name.
387374 ///
388375 /// If no double tag with the given name exists, a new double tag will be created.
389376 ///
390377 /// @throws IllegalStateException if the tag with the given name exists but is not a double tag.
391- @ Contract (mutates = "this" )
392- public void setDouble (String name , double value ) throws IllegalStateException {
378+ @ Contract (value = "_, _ -> this" , mutates = "this" )
379+ public CompoundTag setDouble (String name , double value ) throws IllegalStateException {
393380 getOrPutTag (name , TagType .DOUBLE ).set (value );
381+ return this ;
394382 }
395383
396384 /// Sets the string value of the [StringTag] with the given name.
397385 ///
398386 /// If no string tag with the given name exists, a new string tag will be created.
399387 ///
400388 /// @throws IllegalStateException if the tag with the given name exists but is not a string tag.
401- @ Contract (mutates = "this" )
402- public void setString (String name , String value ) throws IllegalStateException {
389+ @ Contract (value = "_, _ -> this" , mutates = "this" )
390+ public CompoundTag setString (String name , String value ) throws IllegalStateException {
403391 getOrPutTag (name , TagType .STRING ).set (value );
392+ return this ;
404393 }
405394
406395 /// Sets the byte array value of the [ByteArrayTag] with the given name.
407396 ///
408397 /// If no byte array tag with the given name exists, a new byte array tag will be created.
409398 ///
410399 /// @throws IllegalStateException if the tag with the given name exists but is not a byte array tag.
411- @ Contract (mutates = "this" )
412- public void setByteArray (String name , byte [] value ) throws IllegalStateException {
400+ @ Contract (value = "_, _ -> this" , mutates = "this" )
401+ public CompoundTag setByteArray (String name , byte [] value ) throws IllegalStateException {
413402 getOrPutTag (name , TagType .BYTE_ARRAY ).setAll (value );
403+ return this ;
414404 }
415405
416406 /// Sets the int array value of the [IntArrayTag] with the given name.
417407 ///
418408 /// If no int array tag with the given name exists, a new int array tag will be created.
419409 ///
420410 /// @throws IllegalStateException if the tag with the given name exists but is not an int array tag.
421- @ Contract (mutates = "this" )
422- public void setIntArray (String name , int [] value ) throws IllegalStateException {
411+ @ Contract (value = "_, _ -> this" , mutates = "this" )
412+ public CompoundTag setIntArray (String name , int [] value ) throws IllegalStateException {
423413 getOrPutTag (name , TagType .INT_ARRAY ).setAll (value );
414+ return this ;
424415 }
425416
426417 /// Sets the long array value of the [LongArrayTag] with the given name.
427418 ///
428419 /// If no long array tag with the given name exists, a new long array tag will be created.
429420 ///
430421 /// @throws IllegalStateException if the tag with the given name exists but is not a long array tag.
431- @ Contract (mutates = "this" )
432- public void setLongArray (String name , long [] value ) throws IllegalStateException {
422+ @ Contract (value = "_, _ -> this" , mutates = "this" )
423+ public CompoundTag setLongArray (String name , long [] value ) throws IllegalStateException {
433424 getOrPutTag (name , TagType .LONG_ARRAY ).setAll (value );
425+ return this ;
434426 }
435427
436428 /// Set the UUID value of the [IntArrayTag] with the given name.
437429 ///
438430 /// If no int array tag with the given name exists, a new int array tag will be created.
439431 ///
440432 /// @throws IllegalStateException if the tag with the given name exists but is not an int array tag.
441- @ Contract (mutates = "this" )
442- public void setUUID (String name , UUID value ) {
433+ @ Contract (value = "_, _ -> this" , mutates = "this" )
434+ public CompoundTag setUUID (String name , UUID value ) throws IllegalStateException {
443435 getOrPutTag (name , TagType .INT_ARRAY ).setUUID (value );
436+ return this ;
444437 }
445438
446439 @ Override
0 commit comments