修正了NBTBuilder方法
This commit is contained in:
parent
ea2865d58b
commit
9a87b9ee54
|
|
@ -33,7 +33,7 @@ mod_name=3944Realms 's Lib Mod
|
||||||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||||
mod_license=MIT
|
mod_license=MIT
|
||||||
# The mod version. See https://semver.org/
|
# The mod version. See https://semver.org/
|
||||||
mod_version=0.0.9
|
mod_version=0.0.10
|
||||||
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||||
# This should match the base package used for the mod sources.
|
# This should match the base package used for the mod sources.
|
||||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package top.r3944realms.lib39.util.nbt;
|
package top.r3944realms.lib39.util.nbt;
|
||||||
|
|
||||||
import net.minecraft.nbt.*;
|
import net.minecraft.nbt.*;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
@ -20,23 +22,19 @@ public class NBTBuilder {
|
||||||
/**
|
/**
|
||||||
* 创建一个新的NBT构建器
|
* 创建一个新的NBT构建器
|
||||||
*/
|
*/
|
||||||
public static NBTBuilder builder() {
|
@Contract(value = " -> new", pure = true)
|
||||||
|
public static @NotNull NBTBuilder builder() {
|
||||||
return new NBTBuilder();
|
return new NBTBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 基于现有CompoundTag创建构建器
|
* 基于现有CompoundTag创建构建器
|
||||||
*/
|
*/
|
||||||
public static NBTBuilder of(CompoundTag existingTag) {
|
@Contract(value = "_ -> new", pure = true)
|
||||||
|
public static @NotNull NBTBuilder of(CompoundTag existingTag) {
|
||||||
return new NBTBuilder(existingTag);
|
return new NBTBuilder(existingTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 基本数据类型 - 原始类型
|
|
||||||
public NBTBuilder string(String key, String value) {
|
|
||||||
root.putString(key, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NBTBuilder byteValue(String key, byte value) {
|
public NBTBuilder byteValue(String key, byte value) {
|
||||||
root.putByte(key, value);
|
root.putByte(key, value);
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -71,7 +69,12 @@ public class NBTBuilder {
|
||||||
root.putBoolean(key, value);
|
root.putBoolean(key, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
public NBTBuilder string(String key, String value) {
|
||||||
|
if (value != null) {
|
||||||
|
root.putString(key, value);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
// 包装类型 - null安全的版本
|
// 包装类型 - null安全的版本
|
||||||
public NBTBuilder string(String key, String value, String defaultValue) {
|
public NBTBuilder string(String key, String value, String defaultValue) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
|
|
@ -82,19 +85,6 @@ public class NBTBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NBTBuilder string(String key, String value, boolean skipIfNull) {
|
|
||||||
if (!skipIfNull || value != null) {
|
|
||||||
root.putString(key, value != null ? value : "");
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NBTBuilder stringIf(String key, String value) {
|
|
||||||
if (value != null) {
|
|
||||||
root.putString(key, value);
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NBTBuilder byteValue(String key, Byte value) {
|
public NBTBuilder byteValue(String key, Byte value) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
|
|
@ -318,14 +308,10 @@ public class NBTBuilder {
|
||||||
|
|
||||||
// 构建最终的CompoundTag
|
// 构建最终的CompoundTag
|
||||||
public CompoundTag build() {
|
public CompoundTag build() {
|
||||||
return root.copy();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取原始的CompoundTag(不推荐,除非你知道在做什么)
|
|
||||||
public CompoundTag getRaw() {
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ListTag专用的构建器 - 同样支持null安全
|
* ListTag专用的构建器 - 同样支持null安全
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user