From 8be702b3aa9c7dd7a8a80a1dbdb031142316fbda Mon Sep 17 00:00:00 2001 From: Sen Date: Tue, 27 May 2025 21:57:15 +0200 Subject: [PATCH] change nbt format: small fix --- .../src/main/java/common/tags/TagObject.java | 71 +++++++++---------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/common/src/main/java/common/tags/TagObject.java b/common/src/main/java/common/tags/TagObject.java index c2c764c..ad35ab6 100755 --- a/common/src/main/java/common/tags/TagObject.java +++ b/common/src/main/java/common/tags/TagObject.java @@ -121,14 +121,9 @@ public class TagObject extends Tag { return this.tags.get(key); } - public byte getTagId(String key) { + private boolean has(String key, int type) { Tag tag = this.tags.get(key); - return tag != null ? tag.getId() : 0; - } - - private boolean hasKey(String key, int type) { - int id = this.getTagId(key); - return id == type || (type == 99 && id >= 1 && id <= 6); + return tag != null && tag.getId() == type; } public boolean hasBool(String key) { @@ -136,123 +131,123 @@ public class TagObject extends Tag { } public boolean hasByte(String key) { - return this.hasKey(key, 1); + return this.has(key, 1); } public boolean hasShort(String key) { - return this.hasKey(key, 2); + return this.has(key, 2); } public boolean hasInt(String key) { - return this.hasKey(key, 3); + return this.has(key, 3); } public boolean hasLong(String key) { - return this.hasKey(key, 4); + return this.has(key, 4); } public boolean hasFloat(String key) { - return this.hasKey(key, 5); + return this.has(key, 5); } public boolean hasDouble(String key) { - return this.hasKey(key, 6); + return this.has(key, 6); } public boolean hasString(String key) { - return this.hasKey(key, 8); + return this.has(key, 8); } public boolean hasByteArray(String key) { - return this.hasKey(key, 7); + return this.has(key, 7); } public boolean hasIntArray(String key) { - return this.hasKey(key, 11); + return this.has(key, 11); } public boolean hasTag(String key) { - return this.hasKey(key, 10); + return this.has(key, 10); } public boolean hasFloatList(String key) { - return this.hasKey(key, 13); + return this.has(key, 13); } public boolean hasDoubleList(String key) { - return this.hasKey(key, 14); + return this.has(key, 14); } public boolean hasStringList(String key) { - return this.hasKey(key, 9); + return this.has(key, 9); } public boolean hasIntArrayList(String key) { - return this.hasKey(key, 15); + return this.has(key, 15); } public boolean hasTagList(String key) { - return this.hasKey(key, 12); + return this.has(key, 12); } public byte getByte(String key) { - return !this.hasKey(key, 1) ? 0 : ((TagByte)this.tags.get(key)).getByte(); + return !this.has(key, 1) ? 0 : ((TagByte)this.tags.get(key)).getByte(); } public short getShort(String key) { - return !this.hasKey(key, 2) ? 0 : ((TagShort)this.tags.get(key)).getShort(); + return !this.has(key, 2) ? 0 : ((TagShort)this.tags.get(key)).getShort(); } public int getInt(String key) { - return !this.hasKey(key, 3) ? 0 : ((TagInt)this.tags.get(key)).getInt(); + return !this.has(key, 3) ? 0 : ((TagInt)this.tags.get(key)).getInt(); } public long getLong(String key) { - return !this.hasKey(key, 4) ? 0L : ((TagLong)this.tags.get(key)).getLong(); + return !this.has(key, 4) ? 0L : ((TagLong)this.tags.get(key)).getLong(); } public float getFloat(String key) { - return !this.hasKey(key, 5) ? 0.0F : ((TagFloat)this.tags.get(key)).getFloat(); + return !this.has(key, 5) ? 0.0F : ((TagFloat)this.tags.get(key)).getFloat(); } public double getDouble(String key) { - return !this.hasKey(key, 6) ? 0.0D : ((TagDouble)this.tags.get(key)).getDouble(); + return !this.has(key, 6) ? 0.0D : ((TagDouble)this.tags.get(key)).getDouble(); } public String getString(String key) { - return !this.hasKey(key, 8) ? "" : ((TagString)this.tags.get(key)).getString(); + return !this.has(key, 8) ? "" : ((TagString)this.tags.get(key)).getString(); } public byte[] getByteArray(String key) { - return !this.hasKey(key, 7) ? new byte[0] : ((TagByteArray)this.tags.get(key)).getByteArray(); + return !this.has(key, 7) ? new byte[0] : ((TagByteArray)this.tags.get(key)).getByteArray(); } public int[] getIntArray(String key) { - return !this.hasKey(key, 11) ? new int[0] : ((TagIntArray)this.tags.get(key)).getIntArray(); + return !this.has(key, 11) ? new int[0] : ((TagIntArray)this.tags.get(key)).getIntArray(); } public TagObject getTag(String key) { - return !this.hasKey(key, 10) ? new TagObject() : (TagObject)this.tags.get(key); + return !this.has(key, 10) ? new TagObject() : (TagObject)this.tags.get(key); } public TagFloatList getFloatList(String key) { - return !this.hasKey(key, 13) ? new TagFloatList() : (TagFloatList)this.tags.get(key); + return !this.has(key, 13) ? new TagFloatList() : (TagFloatList)this.tags.get(key); } public TagDoubleList getDoubleList(String key) { - return !this.hasKey(key, 14) ? new TagDoubleList() : (TagDoubleList)this.tags.get(key); + return !this.has(key, 14) ? new TagDoubleList() : (TagDoubleList)this.tags.get(key); } public TagStringList getStringList(String key) { - return !this.hasKey(key, 9) ? new TagStringList() : (TagStringList)this.tags.get(key); + return !this.has(key, 9) ? new TagStringList() : (TagStringList)this.tags.get(key); } public TagIntArrayList getIntArrayList(String key) { - return !this.hasKey(key, 15) ? new TagIntArrayList() : (TagIntArrayList)this.tags.get(key); + return !this.has(key, 15) ? new TagIntArrayList() : (TagIntArrayList)this.tags.get(key); } public TagObjectList getTagList(String key) { - return !this.hasKey(key, 12) ? new TagObjectList() : (TagObjectList)this.tags.get(key); + return !this.has(key, 12) ? new TagObjectList() : (TagObjectList)this.tags.get(key); } public boolean getBool(String key) { @@ -302,7 +297,7 @@ public class TagObject extends Tag { for(String key : other.tags.keySet()) { Tag tag = other.tags.get(key); if(tag.getId() == 10) { - if(this.hasKey(key, 10)) { + if(this.has(key, 10)) { TagObject comp = this.getTag(key); comp.merge((TagObject)tag); }