3.4.0: Add helper put methods

This commit is contained in:
Nassim Jahnke 2023-12-29 11:43:13 +01:00
parent ad8ac024c4
commit 324eb6af2c
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
3 changed files with 43 additions and 3 deletions

View File

@ -5,7 +5,7 @@
<groupId>com.viaversion</groupId>
<artifactId>nbt</artifactId>
<version>3.3.0</version>
<version>3.4.0</version>
<packaging>jar</packaging>
<name>ViaNBT</name>

View File

@ -112,9 +112,9 @@ public class CompoundTag extends Tag implements Iterable<Entry<String, Tag>> {
/**
* Puts the tag into this compound tag.
*
* @param <T> Type of tag to put.
* @param <T> Type of tag to put.
* @param tagName Name of the tag.
* @param tag Tag to put into this compound tag.
* @param tag Tag to put into this compound tag.
* @return The previous tag associated with its name, or null if there wasn't one.
*/
@Nullable
@ -122,6 +122,42 @@ public class CompoundTag extends Tag implements Iterable<Entry<String, Tag>> {
return (T) this.value.put(tagName, tag);
}
public void putString(String tagName, String value) {
this.value.put(tagName, new StringTag(value));
}
public void putByte(String tagName, byte value) {
this.value.put(tagName, new ByteTag(value));
}
public void putInt(String tagName, int value) {
this.value.put(tagName, new IntTag(value));
}
public void putShort(String tagName, short value) {
this.value.put(tagName, new ShortTag(value));
}
public void putLong(String tagName, long value) {
this.value.put(tagName, new LongTag(value));
}
public void putFloat(String tagName, float value) {
this.value.put(tagName, new FloatTag(value));
}
public void putDouble(String tagName, double value) {
this.value.put(tagName, new DoubleTag(value));
}
public void putBoolean(String tagName, boolean value) {
this.value.put(tagName, new ByteTag((byte) (value ? 1 : 0)));
}
public void putAll(CompoundTag compoundTag) {
this.value.putAll(compoundTag.value);
}
/**
* Removes a tag from this compound tag.
*

View File

@ -134,6 +134,10 @@ public class ListTag extends Tag implements Iterable<Tag> {
return this.value.size();
}
public boolean isEmpty() {
return this.value.isEmpty();
}
@Override
public Iterator<Tag> iterator() {
return this.value.iterator();