9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-27 10:59:07 +00:00

改进SNBTReader, 支持null值.

This commit is contained in:
Catnies
2025-06-26 07:16:20 +08:00
parent adf83a67a6
commit 85db623bf2

View File

@@ -149,12 +149,13 @@ public final class SNBTReader extends DefaultStringReader {
}
}
int tokenLength = getCursor() - tokenStart - lastWhitespace; // 计算值长度需要再减去尾部空格.
if (tokenLength == 0) throw new IllegalArgumentException("Empty value at position " + tokenStart);
if (tokenLength == 0) return null; // 如果值长度为0则返回null.
if (contentHasWhitespace) return substring(tokenStart, tokenStart + tokenLength); // 如果值的中间有空格, 一定是字符串, 可直接返回.
// 布尔值检查
if (tokenLength == 4) {
if (matchesAt(tokenStart, "true")) return Boolean.TRUE;
if (matchesAt(tokenStart, "null")) return null; // 支持 {key:null}.
} else if (tokenLength == 5) {
if (matchesAt(tokenStart, "false")) return Boolean.FALSE;
}