Skip to content

Commit

Permalink
Fixed parsing of NBT blocks failing due to missing ID
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Dec 27, 2022
1 parent 3483e00 commit 640b0ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ default <B extends BlockStateHolder<B>> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 640b0ff

Please sign in to comment.