From b60e19b434efd9a0608e2f843c75421dd81f05f5 Mon Sep 17 00:00:00 2001 From: NotAPenguin Date: Mon, 26 Aug 2024 13:04:16 +0200 Subject: [PATCH] fix the empty metadata array but now for TE transformer --- .../postea/utility/ChunkFixerUtility.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/com/gtnewhorizons/postea/utility/ChunkFixerUtility.java b/src/main/java/com/gtnewhorizons/postea/utility/ChunkFixerUtility.java index 1a0ced4..57a8ecc 100644 --- a/src/main/java/com/gtnewhorizons/postea/utility/ChunkFixerUtility.java +++ b/src/main/java/com/gtnewhorizons/postea/utility/ChunkFixerUtility.java @@ -156,6 +156,17 @@ public class ChunkFixerUtility { int chunkZPos) { byte[] blockArray = section.getByteArray("Blocks16"); byte[] metadataArray = section.getByteArray("Data16"); // Updated to use Data16 + + // If metadata array is empty, it was all zeroes. We create a new array to write our new values to, + // and only save this when a nonzero value was written + boolean wasAllZero = false; + if (metadataArray.length == 0) { + wasAllZero = true; + metadataArray = new byte[8192]; + } + // Keep track of if we write a nonzero element to the metadata array + boolean hasWrittenNonZero = false; + byte y = section.getByte("Y"); List filteredList = filterConversionInfosByY(conversionInfoList, y); @@ -165,6 +176,13 @@ public class ChunkFixerUtility { int index = computeBlockIndex(localCoords); setBlockInfo(info.blockInfo.block, index, blockArray); setMetadata(info.blockInfo.metadata, index, metadataArray); // This uses the updated setMetadata + if (info.blockInfo.metadata != 0) hasWrittenNonZero = true; + } + + // After processing all replacements, if we made a new metadata array and wrote a nonzero value to it, + // write it back to world NBT to save + if (wasAllZero && hasWrittenNonZero) { + section.setByteArray("Data16", metadataArray); } }