Skip to content

Commit

Permalink
Fix the crash I didn't fix last time and the bug I introduced with th…
Browse files Browse the repository at this point in the history
…e failed fix.

- Really fixed the rare crash in the End generation this time
  • Loading branch information
gniftygnome committed Jul 1, 2024
1 parent 03995e5 commit 879d5be
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class EndBiomePlacement extends DimensionBiomePlacement {
private final MultiNoiseUtil.NoiseHypercube noiseEndMidlands = new MultiNoiseUtil.NoiseHypercube(DEFAULT_PARAMETER, DEFAULT_PARAMETER, DEFAULT_PARAMETER, MultiNoiseUtil.ParameterRange.of(-0.0625f, 0.25f), DEFAULT_PARAMETER, DEFAULT_PARAMETER, 0L);
private final MultiNoiseUtil.NoiseHypercube noiseEndHighlands = new MultiNoiseUtil.NoiseHypercube(DEFAULT_PARAMETER, DEFAULT_PARAMETER, DEFAULT_PARAMETER, MultiNoiseUtil.ParameterRange.of(0.25f, 1f), DEFAULT_PARAMETER, DEFAULT_PARAMETER, 0L);

public MultiNoiseUtil.SearchTree.TreeLeafNode<RegistryEntry<Biome>> nodeTheEnd;
public MultiNoiseUtil.SearchTree.TreeLeafNode<RegistryEntry<Biome>> nodeSmallEndIslands;
public MultiNoiseUtil.SearchTree.TreeLeafNode<RegistryEntry<Biome>> nodeEndBarrens;
public MultiNoiseUtil.SearchTree.TreeLeafNode<RegistryEntry<Biome>> nodeEndMidlands;
Expand All @@ -50,6 +51,7 @@ protected void serverReplaced(BiolithState state, long seed) {

// Update vanilla biome entries for the End
RegistryEntryLookup<Biome> biomeEntryGetter = BiomeCoordinator.getBiomeLookupOrThrow();
nodeTheEnd = new MultiNoiseUtil.SearchTree.TreeLeafNode<>(OUT_OF_RANGE, biomeEntryGetter.getOrThrow(BiomeKeys.THE_END));
nodeSmallEndIslands = new MultiNoiseUtil.SearchTree.TreeLeafNode<>(noiseSmallEndIslands, biomeEntryGetter.getOrThrow(BiomeKeys.SMALL_END_ISLANDS));
nodeEndBarrens = new MultiNoiseUtil.SearchTree.TreeLeafNode<>(noiseEndBarrens, biomeEntryGetter.getOrThrow(BiomeKeys.END_BARRENS));
nodeEndMidlands = new MultiNoiseUtil.SearchTree.TreeLeafNode<>(noiseEndMidlands, biomeEntryGetter.getOrThrow(BiomeKeys.END_MIDLANDS));
Expand All @@ -59,11 +61,6 @@ protected void serverReplaced(BiolithState state, long seed) {
humidityNoise = new OpenSimplexNoise2(seedlets[7]);
temperatureNoise = new OpenSimplexNoise2(seedlets[5]);
weirdnessNoise = new OpenSimplexNoise2(seedlets[3]);

// Somehow, biolith$getBiome() can be called before biolith$biomeStream() in the End
if (state.getWorld().getChunkManager().getChunkGenerator().getBiomeSource().getBiomes() == null) {
throw new IllegalStateException("Biome entries for the End are null after initialization...");
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.source.util.MultiNoiseUtil;
import net.minecraft.world.dimension.DimensionType;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;

@SuppressWarnings("unused")
public interface InterfaceBiomeSource {
RegistryEntry<DimensionType> biolith$getDimensionType();

void biolith$setDimensionType(RegistryEntry<DimensionType> dimensionTypeEntry);

default @Nullable MultiNoiseUtil.Entries<RegistryEntry<Biome>> biolith$getBiomeEntries() {
return null;
default @NotNull MultiNoiseUtil.Entries<RegistryEntry<Biome>> biolith$getBiomeEntries() {
throw new UnsupportedOperationException("Unimplemented on abstract BiomeSource!");
}

default boolean biolith$getBypass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ private static int atBlockPos(CommandContext<ServerCommandSource> context, Block
} else if (world.getDimensionEntry().matchesKey(DimensionTypes.THE_END)) {
RegistryEntry<Biome> original = VanillaCompat.getOriginalEndBiome(biomeX, biomeY, biomeZ, noise);
noisePoint = BiomeCoordinator.END.sampleEndNoise(biomeX, biomeY, biomeZ, noise, original);
vanillaFittestNodes = new BiolithFittestNodes<>(
new MultiNoiseUtil.SearchTree.TreeLeafNode<>(DimensionBiomePlacement.OUT_OF_RANGE,
VanillaCompat.getOriginalEndBiome(biomeX, biomeY, biomeZ, noise)), 0L);
vanillaFittestNodes = VanillaCompat.getEndBiome(noisePoint, biomeEntries, original);
if (BiolithCompat.COMPAT_TERRABLENDER) {
biomeSource.biolith$setBypass(true);
fittestNodes = terrablenderFittestNodes = new BiolithFittestNodes<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,4 @@ public void addBiomeReplacements(RegistryKey<Biome> target, Stream<RegistryKey<B

this.markDirty();
}

public ServerWorld getWorld() {
return world;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.world.biome.source.TheEndBiomeSource;
import net.minecraft.world.biome.source.util.MultiNoiseUtil;
import net.minecraft.world.gen.densityfunction.DensityFunction;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -27,7 +28,7 @@
import java.util.Objects;
import java.util.stream.Stream;

@Mixin(value = TheEndBiomeSource.class, priority = 1100)
@Mixin(value = TheEndBiomeSource.class, priority = 990)
public abstract class MixinTheEndBiomeSource extends BiomeSource {
private static RegistryEntryLookup<Biome> biolith$biomeLookup;
private static MultiNoiseUtil.Entries<RegistryEntry<Biome>> biolith$biomeEntries;
Expand Down Expand Up @@ -96,7 +97,7 @@ public abstract class MixinTheEndBiomeSource extends BiomeSource {
MultiNoiseUtil.NoiseValuePoint noisePoint = BiomeCoordinator.END.sampleEndNoise(x, y, z, noise, original);

// Select noise biome
BiolithFittestNodes<RegistryEntry<Biome>> fittestNodes = VanillaCompat.getEndBiome(noisePoint, biolith$biomeEntries, original);
BiolithFittestNodes<RegistryEntry<Biome>> fittestNodes = VanillaCompat.getEndBiome(noisePoint, this.biolith$getBiomeEntries(), original);

// Process any replacements or sub-biomes.
return BiomeCoordinator.END.getReplacement(x, y, z, noisePoint, fittestNodes);
Expand All @@ -114,7 +115,16 @@ public abstract class MixinTheEndBiomeSource extends BiomeSource {
}

@Override
public MultiNoiseUtil.Entries<RegistryEntry<Biome>> biolith$getBiomeEntries() {
public @NotNull MultiNoiseUtil.Entries<RegistryEntry<Biome>> biolith$getBiomeEntries() {
// I don't know why this hasn't always happened already, but sometimes it hasn't...
if (biolith$biomeEntries == null) {
this.biomeStream();

if (biolith$biomeEntries == null) {
throw new IllegalStateException("biolith$biomeEntries is null after call to " + this.getClass().getCanonicalName() + ".biomeStream()");
}
}

return biolith$biomeEntries;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ public abstract class MixinTBTheEndBiomeSource extends BiomeSource {
@Unique
private static final ThreadLocal<Boolean> bypass = ThreadLocal.withInitial(() -> false);

@Override
public boolean biolith$getBypass() {
return bypass.get();
}

@Override
public void biolith$setBypass(boolean value) {
bypass.set(value);
}
Expand Down

0 comments on commit 879d5be

Please sign in to comment.