From 26853b80fd30b351a0291bc63b870301ef3a705c Mon Sep 17 00:00:00 2001 From: Darren Eberly Date: Wed, 18 Sep 2024 17:25:49 -0400 Subject: [PATCH 1/4] Inject fake byte[] for metadata NibbleArray creation to make Thermos happy --- .../minecraft/MixinAnvilChunkLoader.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/com/gtnewhorizons/neid/mixins/early/minecraft/MixinAnvilChunkLoader.java b/src/main/java/com/gtnewhorizons/neid/mixins/early/minecraft/MixinAnvilChunkLoader.java index 0a31fb9..3c60c20 100644 --- a/src/main/java/com/gtnewhorizons/neid/mixins/early/minecraft/MixinAnvilChunkLoader.java +++ b/src/main/java/com/gtnewhorizons/neid/mixins/early/minecraft/MixinAnvilChunkLoader.java @@ -17,6 +17,8 @@ @Mixin(AnvilChunkLoader.class) public class MixinAnvilChunkLoader { + private static byte[] fakeByteArray = new byte[]{1}; + @Redirect( method = "writeChunkToNBT", at = @At( @@ -133,6 +135,26 @@ public class MixinAnvilChunkLoader { return false; } + @Redirect( + method = "readChunkFromNBT", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/nbt/NBTTagCompound;getByteArray(Ljava/lang/String;)[B", + ordinal = 2 + ), + require = 1 + ) + private byte[] neid$injectFakeByteArrayForThermos(NBTTagCompound nbttagcompound1, String s) { + /* + This is here because Thermos(Spigot) makes some changes to NibbleArray which cause creating a + NibbleArray with an empty byte[] to crash. When the postNeidWorldsSupport option is enabled, it means + that the vanilla byte[] in the NBT is no longer stored there. Which causes the NibbleArray creation + for it to be done with an empty byte[]. This just returns a static fake byte[] with one value in it, + because we're not actually going to use this NibbleArray anymore, but it still needs to be created. + */ + return fakeByteArray; + } + @Redirect( method = "readChunkFromNBT", at = @At( From 6362c1b23a2fcc8090428d8ccc9344dd6a9080ff Mon Sep 17 00:00:00 2001 From: GitHub GTNH Actions <> Date: Wed, 18 Sep 2024 21:30:27 +0000 Subject: [PATCH 2/4] spotlessApply --- .../minecraft/MixinAnvilChunkLoader.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/gtnewhorizons/neid/mixins/early/minecraft/MixinAnvilChunkLoader.java b/src/main/java/com/gtnewhorizons/neid/mixins/early/minecraft/MixinAnvilChunkLoader.java index 3c60c20..45d1b2e 100644 --- a/src/main/java/com/gtnewhorizons/neid/mixins/early/minecraft/MixinAnvilChunkLoader.java +++ b/src/main/java/com/gtnewhorizons/neid/mixins/early/minecraft/MixinAnvilChunkLoader.java @@ -17,7 +17,7 @@ @Mixin(AnvilChunkLoader.class) public class MixinAnvilChunkLoader { - private static byte[] fakeByteArray = new byte[]{1}; + private static byte[] fakeByteArray = new byte[] { 1 }; @Redirect( method = "writeChunkToNBT", @@ -136,21 +136,19 @@ public class MixinAnvilChunkLoader { } @Redirect( - method = "readChunkFromNBT", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/nbt/NBTTagCompound;getByteArray(Ljava/lang/String;)[B", - ordinal = 2 - ), - require = 1 - ) + method = "readChunkFromNBT", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/nbt/NBTTagCompound;getByteArray(Ljava/lang/String;)[B", + ordinal = 2), + require = 1) private byte[] neid$injectFakeByteArrayForThermos(NBTTagCompound nbttagcompound1, String s) { /* - This is here because Thermos(Spigot) makes some changes to NibbleArray which cause creating a - NibbleArray with an empty byte[] to crash. When the postNeidWorldsSupport option is enabled, it means - that the vanilla byte[] in the NBT is no longer stored there. Which causes the NibbleArray creation - for it to be done with an empty byte[]. This just returns a static fake byte[] with one value in it, - because we're not actually going to use this NibbleArray anymore, but it still needs to be created. + * This is here because Thermos(Spigot) makes some changes to NibbleArray which cause creating a NibbleArray + * with an empty byte[] to crash. When the postNeidWorldsSupport option is enabled, it means that the vanilla + * byte[] in the NBT is no longer stored there. Which causes the NibbleArray creation for it to be done with an + * empty byte[]. This just returns a static fake byte[] with one value in it, because we're not actually going + * to use this NibbleArray anymore, but it still needs to be created. */ return fakeByteArray; } From c3a64f470b1ba9a5344724fe4ed45f87ced24d33 Mon Sep 17 00:00:00 2001 From: Darren Eberly Date: Wed, 18 Sep 2024 17:59:18 -0400 Subject: [PATCH 3/4] Switch to WrapOperation --- .../minecraft/MixinAnvilChunkLoader.java | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/gtnewhorizons/neid/mixins/early/minecraft/MixinAnvilChunkLoader.java b/src/main/java/com/gtnewhorizons/neid/mixins/early/minecraft/MixinAnvilChunkLoader.java index 45d1b2e..5fc5ab7 100644 --- a/src/main/java/com/gtnewhorizons/neid/mixins/early/minecraft/MixinAnvilChunkLoader.java +++ b/src/main/java/com/gtnewhorizons/neid/mixins/early/minecraft/MixinAnvilChunkLoader.java @@ -1,5 +1,7 @@ package com.gtnewhorizons.neid.mixins.early.minecraft; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.chunk.NibbleArray; import net.minecraft.world.chunk.storage.AnvilChunkLoader; @@ -17,7 +19,8 @@ @Mixin(AnvilChunkLoader.class) public class MixinAnvilChunkLoader { - private static byte[] fakeByteArray = new byte[] { 1 }; + private static byte[] fakeByteArray = new byte[0]; + private static NibbleArray fakeNibbleArray = new NibbleArray(0, 0); @Redirect( method = "writeChunkToNBT", @@ -136,30 +139,38 @@ public class MixinAnvilChunkLoader { } @Redirect( - method = "readChunkFromNBT", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/nbt/NBTTagCompound;getByteArray(Ljava/lang/String;)[B", - ordinal = 2), - require = 1) - private byte[] neid$injectFakeByteArrayForThermos(NBTTagCompound nbttagcompound1, String s) { - /* - * This is here because Thermos(Spigot) makes some changes to NibbleArray which cause creating a NibbleArray - * with an empty byte[] to crash. When the postNeidWorldsSupport option is enabled, it means that the vanilla - * byte[] in the NBT is no longer stored there. Which causes the NibbleArray creation for it to be done with an - * empty byte[]. This just returns a static fake byte[] with one value in it, because we're not actually going - * to use this NibbleArray anymore, but it still needs to be created. - */ + method = "readChunkFromNBT", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/nbt/NBTTagCompound;getByteArray(Ljava/lang/String;)[B", + ordinal = 2 + ), + require = 1 + ) + private byte[] neid$cancelByteArrayCreationForMetadata(NBTTagCompound nbttagcompound1, String s) { return fakeByteArray; } + @WrapOperation( + method = "readChunkFromNBT", + at = @At( + value = "NEW", + target = "Lnet/minecraft/world/chunk/NibbleArray;", + ordinal = 1 + ), + require = 1 + ) + private NibbleArray neid$cancelNibbleArrayCreationForMetadata(byte[] bytes, int i, Operation original) { + return fakeNibbleArray; + } + @Redirect( method = "readChunkFromNBT", at = @At( value = "INVOKE", target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;setBlockMetadataArray(Lnet/minecraft/world/chunk/NibbleArray;)V"), require = 1) - private void neid$overrideReadMetadataArray(ExtendedBlockStorage ebs, NibbleArray oldBrokenNibbleArray, + private void neid$overrideReadMetadataArray(ExtendedBlockStorage ebs, NibbleArray oldNibble, @Local(ordinal = 1) NBTTagCompound nbt) { IExtendedBlockStorageMixin ebsMixin = (IExtendedBlockStorageMixin) ebs; if (nbt.hasKey("Data16")) { From 88f2ae36cf8e1ec25b1ee656a3995f7ef7bf66a1 Mon Sep 17 00:00:00 2001 From: Darren Eberly Date: Wed, 18 Sep 2024 17:59:47 -0400 Subject: [PATCH 4/4] spotless --- .../minecraft/MixinAnvilChunkLoader.java | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/gtnewhorizons/neid/mixins/early/minecraft/MixinAnvilChunkLoader.java b/src/main/java/com/gtnewhorizons/neid/mixins/early/minecraft/MixinAnvilChunkLoader.java index 5fc5ab7..e5c50e2 100644 --- a/src/main/java/com/gtnewhorizons/neid/mixins/early/minecraft/MixinAnvilChunkLoader.java +++ b/src/main/java/com/gtnewhorizons/neid/mixins/early/minecraft/MixinAnvilChunkLoader.java @@ -1,7 +1,5 @@ package com.gtnewhorizons.neid.mixins.early.minecraft; -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.chunk.NibbleArray; import net.minecraft.world.chunk.storage.AnvilChunkLoader; @@ -14,6 +12,8 @@ import com.gtnewhorizons.neid.Constants; import com.gtnewhorizons.neid.NEIDConfig; import com.gtnewhorizons.neid.mixins.interfaces.IExtendedBlockStorageMixin; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import com.llamalad7.mixinextras.sugar.Local; @Mixin(AnvilChunkLoader.class) @@ -139,28 +139,22 @@ public class MixinAnvilChunkLoader { } @Redirect( - method = "readChunkFromNBT", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/nbt/NBTTagCompound;getByteArray(Ljava/lang/String;)[B", - ordinal = 2 - ), - require = 1 - ) + method = "readChunkFromNBT", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/nbt/NBTTagCompound;getByteArray(Ljava/lang/String;)[B", + ordinal = 2), + require = 1) private byte[] neid$cancelByteArrayCreationForMetadata(NBTTagCompound nbttagcompound1, String s) { return fakeByteArray; } @WrapOperation( - method = "readChunkFromNBT", - at = @At( - value = "NEW", - target = "Lnet/minecraft/world/chunk/NibbleArray;", - ordinal = 1 - ), - require = 1 - ) - private NibbleArray neid$cancelNibbleArrayCreationForMetadata(byte[] bytes, int i, Operation original) { + method = "readChunkFromNBT", + at = @At(value = "NEW", target = "Lnet/minecraft/world/chunk/NibbleArray;", ordinal = 1), + require = 1) + private NibbleArray neid$cancelNibbleArrayCreationForMetadata(byte[] bytes, int i, + Operation original) { return fakeNibbleArray; }