From 1fb6d35db1e6e5631dbd84d6883ff09ec5a39316 Mon Sep 17 00:00:00 2001 From: Madeline Miller Date: Wed, 21 Sep 2022 22:29:13 +1000 Subject: [PATCH] Fixed parsing of NBT blocks failing due to missing ID --- .../worldedit/internal/wna/WorldNativeAccess.java | 10 ++++++---- .../com/sk89q/worldedit/world/block/BaseBlock.java | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/wna/WorldNativeAccess.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/wna/WorldNativeAccess.java index 7ecb2603a7..fa35796ba3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/wna/WorldNativeAccess.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/wna/WorldNativeAccess.java @@ -67,12 +67,14 @@ default > boolean setBlock(BlockVector3 position, if (block instanceof BaseBlock baseBlock) { LinCompoundTag tag = baseBlock.getNbt(); if (tag != null) { - tag = tag.toBuilder() - .putString("id", baseBlock.getNbtId()) + LinCompoundTag.Builder tagBuilder = tag.toBuilder() .putInt("x", position.getX()) .putInt("y", position.getY()) - .putInt("z", position.getZ()) - .build(); + .putInt("z", position.getZ()); + if (!baseBlock.getNbtId().isBlank()) { + tagBuilder.putString("id", baseBlock.getNbtId()); + } + tag = tagBuilder.build(); // update if TE changed as well successful = updateTileEntity(pos, tag); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java index 57955a0ab8..c094324902 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java @@ -27,6 +27,7 @@ import org.enginehub.linbus.format.snbt.LinStringIO; import org.enginehub.linbus.stream.exception.NbtWriteException; import org.enginehub.linbus.tree.LinCompoundTag; +import org.enginehub.linbus.tree.LinStringTag; import org.enginehub.linbus.tree.LinTagType; import java.util.Map; @@ -121,7 +122,8 @@ public String getNbtId() { if (nbtData == null) { return ""; } - return nbtData.getValue().getTag("id", LinTagType.stringTag()).value(); + LinStringTag idTag = nbtData.getValue().findTag("id", LinTagType.stringTag()); + return idTag != null ? idTag.value() : ""; } @Nullable