Skip to content

Commit

Permalink
Add an extra data block to allow serializing neid data blocks correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
spacebuilder2020 committed Feb 14, 2025
1 parent 9e9e0c1 commit b68e162
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ public Clipboard read(WorldData data) throws IOException {
// Get blocks
byte[] blockId = requireTag(schematic, "Blocks", ByteArrayTag.class).getValue();
byte[] blockData = requireTag(schematic, "Data", ByteArrayTag.class).getValue();
byte[] extraData = null;
if (schematic.containsKey("ExtraData")) {
extraData = requireTag(schematic, "ExtraData", ByteArrayTag.class).getValue();
}

byte[] addId = new byte[0];
short[] blocks = new short[blockId.length]; // Have to later combine IDs

Expand Down Expand Up @@ -239,7 +244,7 @@ public Clipboard read(WorldData data) throws IOException {
blocks[index] = blockConversionMap.get(blocks[index]);
}

BaseBlock block = new BaseBlock(Short.toUnsignedInt(blocks[index]), Byte.toUnsignedInt(blockData[index]));
BaseBlock block = new BaseBlock(Short.toUnsignedInt(blocks[index]), blockData[index] < -1 || extraData != null ? Byte.toUnsignedInt(blockData[index]) + (extraData != null ? (extraData[index] << 8) : 0) : blockData[index]);

if (tileEntitiesMap.containsKey(pt)) {
BiPredicate<CompoundTag, String[]> isItem = (itemTag, idPtr) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public void write(Clipboard clipboard, WorldData data) throws IOException {
byte[] blocks = new byte[width * height * length];
byte[] addBlocks = null;
byte[] blockData = new byte[width * height * length];
byte[] extraBlockData = new byte[width * height * length];
List<Tag> tileEntities = new ArrayList<Tag>();

for (Vector point : region) {
Expand Down Expand Up @@ -142,6 +143,7 @@ public void write(Clipboard clipboard, WorldData data) throws IOException {

blocks[index] = (byte) block.getType();
blockData[index] = (byte) block.getData();
extraBlockData[index] = (byte) (block.getData() >> 8);

// Store TileEntity data
CompoundTag rawTag = block.getNbtData();
Expand Down Expand Up @@ -216,6 +218,7 @@ else if (tag instanceof CompoundTag itemTag)

schematic.put("Blocks", new ByteArrayTag(blocks));
schematic.put("Data", new ByteArrayTag(blockData));
schematic.put("ExtraData", new ByteArrayTag(extraBlockData));
schematic.put("TileEntities", new ListTag(CompoundTag.class, tileEntities));

if (addBlocks != null) {
Expand Down

0 comments on commit b68e162

Please sign in to comment.