mirror of
https://github.com/GTNewHorizons/Postea.git
synced 2026-11-12 16:37:38 +00:00
Merge pull request #3 from GTNewHorizons/fix-empty-blockarray
Fix crash when metadata array is empty
This commit is contained in:
1 file changed
+20
@@ -60,6 +60,15 @@ public class ChunkFixerUtility {
|
||||
// Blocks16 and Data16 exist only because of NEID.
|
||||
byte[] blockArray = section.getByteArray("Blocks16");
|
||||
byte[] metadataArray = section.getByteArray("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 sectionY = section.getByte("Y");
|
||||
|
||||
@@ -84,6 +93,11 @@ public class ChunkFixerUtility {
|
||||
blockConversionInfo.blockName = blockName;
|
||||
blockConversionInfo.blockID = blockId;
|
||||
blockConversionInfo.metadata = (byte) metadata; // Updated
|
||||
// If we wrote a nonzero metadata, keep track of this because it means the
|
||||
// new array needs to be written back to NBT
|
||||
if (metadata != 0) {
|
||||
hasWrittenNonZero = true;
|
||||
}
|
||||
blockConversionInfo.world = world;
|
||||
|
||||
int x = index % 16;
|
||||
@@ -107,6 +121,12 @@ public class ChunkFixerUtility {
|
||||
metadataArray[index * 2 + 1] = (byte) (newMetadata & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user