From 24238e047563c0ef5e111adf044f83760f57d777 Mon Sep 17 00:00:00 2001 From: ishland Date: Sun, 5 Jan 2025 12:16:24 +0800 Subject: [PATCH] fix: handle uninitialized parameter list (#198) (cherry picked from commit c90344362b5e813c43f38fed19ea82412c1fffc3) --- .../mixin/MixinMultiNoiseBiomeSource.java | 7 +------ .../mixin/MixinNoiseBasedChunkGenerator.java | 13 +++++++++++-- .../terrablender/mixin/MixinParameterList.java | 14 +++++++++++--- .../mixin/MultiNoiseBiomeSourceAccess.java | 3 +++ .../worldgen/IExtendedParameterList.java | 1 + 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Common/src/main/java/terrablender/mixin/MixinMultiNoiseBiomeSource.java b/Common/src/main/java/terrablender/mixin/MixinMultiNoiseBiomeSource.java index c208049..fee14c9 100644 --- a/Common/src/main/java/terrablender/mixin/MixinMultiNoiseBiomeSource.java +++ b/Common/src/main/java/terrablender/mixin/MixinMultiNoiseBiomeSource.java @@ -44,9 +44,6 @@ public abstract class MixinMultiNoiseBiomeSource implements IExtendedMultiNoiseB @Shadow public abstract Climate.ParameterList> parameters(); - @Shadow @Final @Mutable - private Either>, Holder> parameters; - @Inject(method="getNoiseBiome(IIILnet/minecraft/world/level/biome/Climate$Sampler;)Lnet/minecraft/core/Holder;", at=@At("HEAD"), cancellable = true) public void getNoiseBiome(int x, int y, int z, Climate.Sampler sampler, CallbackInfoReturnable> cir) { @@ -65,9 +62,7 @@ public void addDebugInfo(List debugLines, BlockPos pos, Climate.Sampler @Override public MultiNoiseBiomeSource clone() { try { - MultiNoiseBiomeSource cloned = (MultiNoiseBiomeSource) super.clone(); - ((MixinMultiNoiseBiomeSource) (Object) cloned).parameters = Either.left(((IExtendedParameterList>) this.parameters()).clone()); - return cloned; + return (MultiNoiseBiomeSource) super.clone(); } catch (CloneNotSupportedException e) { throw new AssertionError(); } diff --git a/Common/src/main/java/terrablender/mixin/MixinNoiseBasedChunkGenerator.java b/Common/src/main/java/terrablender/mixin/MixinNoiseBasedChunkGenerator.java index 9be3443..4ad8b85 100644 --- a/Common/src/main/java/terrablender/mixin/MixinNoiseBasedChunkGenerator.java +++ b/Common/src/main/java/terrablender/mixin/MixinNoiseBasedChunkGenerator.java @@ -1,20 +1,29 @@ package terrablender.mixin; +import com.mojang.datafixers.util.Either; +import net.minecraft.core.Holder; +import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.BiomeResolver; +import net.minecraft.world.level.biome.Climate; import net.minecraft.world.level.biome.MultiNoiseBiomeSource; import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArg; import terrablender.worldgen.IExtendedMultiNoiseBiomeSource; +import terrablender.worldgen.IExtendedParameterList; @Mixin(NoiseBasedChunkGenerator.class) public class MixinNoiseBasedChunkGenerator { @ModifyArg(method = "doCreateBiomes", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/chunk/ChunkAccess;fillBiomesFromNoise(Lnet/minecraft/world/level/biome/BiomeResolver;Lnet/minecraft/world/level/biome/Climate$Sampler;)V")) private BiomeResolver modifyBiomeSource(BiomeResolver biomeResolver) { - if (biomeResolver instanceof MultiNoiseBiomeSource multiNoiseBiomeSource) { - return ((IExtendedMultiNoiseBiomeSource) multiNoiseBiomeSource).clone(); + if (biomeResolver instanceof MultiNoiseBiomeSource multiNoiseBiomeSource && ((IExtendedParameterList>) multiNoiseBiomeSource.parameters()).isInitialized()) { + MultiNoiseBiomeSource cloned = ((IExtendedMultiNoiseBiomeSource) multiNoiseBiomeSource).clone(); + Climate.ParameterList> clonedParameterList = ((IExtendedParameterList>) cloned.parameters()).clone(); + ((IExtendedParameterList>) clonedParameterList).recreateUniqueness(); + ((MultiNoiseBiomeSourceAccess) cloned).setParameters(Either.left(clonedParameterList)); + return cloned; } else { return biomeResolver; } diff --git a/Common/src/main/java/terrablender/mixin/MixinParameterList.java b/Common/src/main/java/terrablender/mixin/MixinParameterList.java index 8119a45..4f5a8da 100644 --- a/Common/src/main/java/terrablender/mixin/MixinParameterList.java +++ b/Common/src/main/java/terrablender/mixin/MixinParameterList.java @@ -27,6 +27,7 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import terrablender.api.Region; import terrablender.api.RegionType; import terrablender.api.Regions; @@ -151,11 +152,18 @@ public T findValuePositional(Climate.TargetPoint target, int x, int y, int z) @Override public Climate.ParameterList clone() { try { - Climate.ParameterList cloned = (Climate.ParameterList) super.clone(); - ((MixinParameterList) (Object) cloned).uniqueness = ((MixinParameterList) (Object) cloned).newUniqueness.get(); - return cloned; + return (Climate.ParameterList) super.clone(); } catch (CloneNotSupportedException e) { throw new AssertionError(); } } + + @Unique + @Override + public void recreateUniqueness() { + if (!this.initialized) { + return; + } + this.uniqueness = this.newUniqueness.get(); + } } diff --git a/Common/src/main/java/terrablender/mixin/MultiNoiseBiomeSourceAccess.java b/Common/src/main/java/terrablender/mixin/MultiNoiseBiomeSourceAccess.java index c92ace1..52270a0 100644 --- a/Common/src/main/java/terrablender/mixin/MultiNoiseBiomeSourceAccess.java +++ b/Common/src/main/java/terrablender/mixin/MultiNoiseBiomeSourceAccess.java @@ -17,4 +17,7 @@ public interface MultiNoiseBiomeSourceAccess { @Accessor void setParameters(Either>, Holder> parameters); + @Accessor + Either>, Holder> getParameters(); + } diff --git a/Common/src/main/java/terrablender/worldgen/IExtendedParameterList.java b/Common/src/main/java/terrablender/worldgen/IExtendedParameterList.java index 3b50ba9..836d510 100644 --- a/Common/src/main/java/terrablender/worldgen/IExtendedParameterList.java +++ b/Common/src/main/java/terrablender/worldgen/IExtendedParameterList.java @@ -32,4 +32,5 @@ public interface IExtendedParameterList extends Cloneable int getTreeCount(); boolean isInitialized(); Climate.ParameterList clone(); + void recreateUniqueness(); } \ No newline at end of file