Compare commits

...
7 Commits
Author SHA1 Message Date
Martin Robertz 361c851706 update 2024-09-10 16:55:44 +02:00
Darren Eberly ebb2517488 Mixin ordering compat with NEID (#5)
* Mixin ordering compat with NEID

* spotless
2024-09-10 12:40:03 +01:00
Connor-Colenso ff97e8841c Merge pull request #4 from GTNewHorizons/fix-empty-metadata 2024-08-26 12:49:06 +01:00
NotAPenguin b60e19b434 fix the empty metadata array but now for TE transformer 2024-08-26 13:04:16 +02:00
Connor-Colenso cb9de2d290 Merge pull request #3 from GTNewHorizons/fix-empty-blockarray
Fix crash when metadata array is empty
2024-08-20 13:09:12 +01:00
NotAPenguin ec2b6a9007 More proper fix 2024-08-20 14:00:44 +02:00
NotAPenguin d9ceee01b5 fix crash when metadata array is empty 2024-08-20 13:43:45 +02:00
3 changed files with 45 additions and 2 deletions

No files matched your search

+1 -1
View File
@@ -17,7 +17,7 @@ pluginManagement {
}
plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.26'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.27'
}
@@ -17,7 +17,12 @@ import com.gtnewhorizons.postea.utility.ChunkFixerUtility;
@Mixin(AnvilChunkLoader.class)
public abstract class MixinAnvilChunkLoader {
@Inject(method = "checkedReadChunkFromNBT__Async", at = @At("HEAD"), remap = false)
@Inject(
method = "checkedReadChunkFromNBT__Async",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/AnvilChunkLoader;readChunkFromNBT(Lnet/minecraft/world/World;Lnet/minecraft/nbt/NBTTagCompound;)Lnet/minecraft/world/chunk/Chunk;"),
remap = false)
private void onCheckedReadChunkFromNBT__Async(World world, int x, int z, NBTTagCompound compound,
CallbackInfoReturnable<Object[]> cir) {
ChunkFixerUtility.processChunkNBT(compound, world);
@@ -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);
}
}
}
@@ -136,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<ConversionInfo> filteredList = filterConversionInfosByY(conversionInfoList, y);
@@ -145,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);
}
}