Skip to content

Commit

Permalink
fix: handle uninitialized parameter list (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland authored Jan 5, 2025
1 parent cae9eba commit c903443
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ public abstract class MixinMultiNoiseBiomeSource implements IExtendedMultiNoiseB
@Shadow
public abstract Climate.ParameterList<Holder<Biome>> parameters();

@Shadow @Final @Mutable
private Either<Climate.ParameterList<Holder<Biome>>, Holder<MultiNoiseBiomeSourceParameterList>> 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<Holder<Biome>> cir)
{
Expand All @@ -65,9 +62,7 @@ public void addDebugInfo(List<String> debugLines, BlockPos pos, Climate.Sampler
@Override
public MultiNoiseBiomeSource clone() {
try {
MultiNoiseBiomeSource cloned = (MultiNoiseBiomeSource) super.clone();
((MixinMultiNoiseBiomeSource) (Object) cloned).parameters = Either.left(((IExtendedParameterList<Holder<Biome>>) this.parameters()).clone());
return cloned;
return (MultiNoiseBiomeSource) super.clone();
} catch (CloneNotSupportedException e) {
throw new AssertionError();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Holder<Biome>>) multiNoiseBiomeSource.parameters()).isInitialized()) {
MultiNoiseBiomeSource cloned = ((IExtendedMultiNoiseBiomeSource) multiNoiseBiomeSource).clone();
Climate.ParameterList<Holder<Biome>> clonedParameterList = ((IExtendedParameterList<Holder<Biome>>) cloned.parameters()).clone();
((IExtendedParameterList<Holder<Biome>>) clonedParameterList).recreateUniqueness();
((MultiNoiseBiomeSourceAccess) cloned).setParameters(Either.left(clonedParameterList));
return cloned;
} else {
return biomeResolver;
}
Expand Down
14 changes: 11 additions & 3 deletions Common/src/main/java/terrablender/mixin/MixinParameterList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -151,11 +152,18 @@ public T findValuePositional(Climate.TargetPoint target, int x, int y, int z)
@Override
public Climate.ParameterList<T> clone() {
try {
Climate.ParameterList<T> cloned = (Climate.ParameterList<T>) super.clone();
((MixinParameterList<T>) (Object) cloned).uniqueness = ((MixinParameterList<T>) (Object) cloned).newUniqueness.get();
return cloned;
return (Climate.ParameterList<T>) super.clone();
} catch (CloneNotSupportedException e) {
throw new AssertionError();
}
}

@Unique
@Override
public void recreateUniqueness() {
if (!this.initialized) {
return;
}
this.uniqueness = this.newUniqueness.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ public interface MultiNoiseBiomeSourceAccess {
@Accessor
void setParameters(Either<Climate.ParameterList<Holder<Biome>>, Holder<MultiNoiseBiomeSourceParameterList>> parameters);

@Accessor
Either<Climate.ParameterList<Holder<Biome>>, Holder<MultiNoiseBiomeSourceParameterList>> getParameters();

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ public interface IExtendedParameterList<T> extends Cloneable
int getTreeCount();
boolean isInitialized();
Climate.ParameterList<T> clone();
void recreateUniqueness();
}

0 comments on commit c903443

Please sign in to comment.