From d9ceee01b5785c8c13d105a995bad77df0737e4d Mon Sep 17 00:00:00 2001 From: NotAPenguin Date: Tue, 20 Aug 2024 13:43:45 +0200 Subject: [PATCH] fix crash when metadata array is empty --- .../com/gtnewhorizons/postea/utility/ChunkFixerUtility.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gtnewhorizons/postea/utility/ChunkFixerUtility.java b/src/main/java/com/gtnewhorizons/postea/utility/ChunkFixerUtility.java index 30d73cc..4558f62 100644 --- a/src/main/java/com/gtnewhorizons/postea/utility/ChunkFixerUtility.java +++ b/src/main/java/com/gtnewhorizons/postea/utility/ChunkFixerUtility.java @@ -66,7 +66,10 @@ public class ChunkFixerUtility { for (int index = 0; index < blockArray.length / 2; index++) { // Horrible bit jank to recreate the actual IDs, because the array is just a byte array. int blockId = ((blockArray[index * 2] & 0xFF) << 8) | (blockArray[index * 2 + 1] & 0xFF); - int metadata = ((metadataArray[index * 2] & 0xFF) << 8) | (metadataArray[index * 2 + 1] & 0xFF); + // If metadata is all zeroes, it isn't stored, so simply check the length and assign zero to + // metadata if it's empty. + int metadata = (metadataArray.length == 0) ? 0 + : (((metadataArray[index * 2] & 0xFF) << 8) | (metadataArray[index * 2 + 1] & 0xFF)); // Skip air. if (blockId == AIR_ID) continue;