Skip to content

Commit

Permalink
Another batch of End-related bug fixes.
Browse files Browse the repository at this point in the history
- Resolve crashes when loading multiple games with Biolith End placement in the same Minecraft session
- Improve smoothness of End biome placement
- Improve output of `/biolith describe` in the End
  • Loading branch information
gniftygnome committed Jul 1, 2024
1 parent 879d5be commit 9556ae7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import net.minecraft.registry.RegistryEntryLookup;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.math.ChunkSectionPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeKeys;
Expand All @@ -20,11 +19,6 @@
public class EndBiomePlacement extends DimensionBiomePlacement {
private final double[] scale = new double[4];

private final MultiNoiseUtil.NoiseHypercube noiseSmallEndIslands = new MultiNoiseUtil.NoiseHypercube(DEFAULT_PARAMETER, DEFAULT_PARAMETER, DEFAULT_PARAMETER, MultiNoiseUtil.ParameterRange.of(-1f, -0.21875f), DEFAULT_PARAMETER, DEFAULT_PARAMETER, 0L);
private final MultiNoiseUtil.NoiseHypercube noiseEndBarrens = new MultiNoiseUtil.NoiseHypercube(DEFAULT_PARAMETER, DEFAULT_PARAMETER, DEFAULT_PARAMETER, MultiNoiseUtil.ParameterRange.of(-0.21875f, -0.0625f), DEFAULT_PARAMETER, DEFAULT_PARAMETER, 0L);
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;
Expand All @@ -51,18 +45,29 @@ 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));
nodeEndHighlands = new MultiNoiseUtil.SearchTree.TreeLeafNode<>(noiseEndHighlands, biomeEntryGetter.getOrThrow(BiomeKeys.END_HIGHLANDS));
nodeTheEnd = new MultiNoiseUtil.SearchTree.TreeLeafNode<>(OUT_OF_RANGE, biomeEntryGetter.getOrThrow(BiomeKeys.THE_END));
nodeSmallEndIslands = new MultiNoiseUtil.SearchTree.TreeLeafNode<>(VanillaEndBiomeParameters.NOISE_SMALL_END_ISLANDS, biomeEntryGetter.getOrThrow(BiomeKeys.SMALL_END_ISLANDS));
nodeEndBarrens = new MultiNoiseUtil.SearchTree.TreeLeafNode<>(VanillaEndBiomeParameters.NOISE_END_BARRENS, biomeEntryGetter.getOrThrow(BiomeKeys.END_BARRENS));
nodeEndMidlands = new MultiNoiseUtil.SearchTree.TreeLeafNode<>(VanillaEndBiomeParameters.NOISE_END_MIDLANDS, biomeEntryGetter.getOrThrow(BiomeKeys.END_MIDLANDS));
nodeEndHighlands = new MultiNoiseUtil.SearchTree.TreeLeafNode<>(VanillaEndBiomeParameters.NOISE_END_HIGHLANDS, biomeEntryGetter.getOrThrow(BiomeKeys.END_HIGHLANDS));

// Seed the End simplex noises based on the game seed
humidityNoise = new OpenSimplexNoise2(seedlets[7]);
temperatureNoise = new OpenSimplexNoise2(seedlets[5]);
weirdnessNoise = new OpenSimplexNoise2(seedlets[3]);
}

@Override
protected void serverStopped() {
super.serverStopped();

nodeTheEnd = null;
nodeSmallEndIslands = null;
nodeEndBarrens = null;
nodeEndMidlands = null;
nodeEndHighlands = null;
}

@Override
public double getLocalNoise(int x, int y, int z) {
double localNoise;
Expand Down Expand Up @@ -109,9 +114,9 @@ public void writeBiomeParameters(Consumer<Pair<MultiNoiseUtil.NoiseHypercube, Re
// TODO: This should be replaced with a more robust noise implementation, perhaps also more similar to vanilla.
public MultiNoiseUtil.NoiseValuePoint sampleEndNoise(int x, int y, int z, MultiNoiseUtil.MultiNoiseSampler originalNoise, RegistryEntry<Biome> originalBiome) {
double erosion = originalNoise.erosion().sample(new DensityFunction.UnblendedNoisePos(
(ChunkSectionPos.getSectionCoord(BiomeCoords.toBlock(x)) * 2 + 1) * 8,
BiomeCoords.toBlock(x),
BiomeCoords.toBlock(y),
(ChunkSectionPos.getSectionCoord(BiomeCoords.toBlock(z)) * 2 + 1) * 8
BiomeCoords.toBlock(z)
));

return new MultiNoiseUtil.NoiseValuePoint(
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.NotNull;
import org.jetbrains.annotations.Nullable;

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

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

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

default boolean biolith$getBypass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.function.Consumer;

import static com.terraformersmc.biolith.impl.biome.DimensionBiomePlacement.DEFAULT_PARAMETER;
import static com.terraformersmc.biolith.impl.biome.DimensionBiomePlacement.OUT_OF_RANGE;

public class VanillaEndBiomeParameters {
private static final long VANILLA_OFFSET = 0L;
Expand All @@ -25,6 +26,7 @@ public class VanillaEndBiomeParameters {
public static final MultiNoiseUtil.NoiseHypercube NOISE_END_HIGHLANDS = new MultiNoiseUtil.NoiseHypercube(VANILLA_TEMPERATURE, VANILLA_HUMIDITY, DEFAULT_PARAMETER, MultiNoiseUtil.ParameterRange.of(0.25f, 1f), VANILLA_DEPTH, VANILLA_WEIRDNESS, VANILLA_OFFSET);

public static void writeEndBiomeParameters(Consumer<Pair<MultiNoiseUtil.NoiseHypercube, RegistryKey<Biome>>> parameters) {
parameters.accept(Pair.of(OUT_OF_RANGE, BiomeKeys.THE_END));
parameters.accept(Pair.of(NOISE_SMALL_END_ISLANDS, BiomeKeys.SMALL_END_ISLANDS));
parameters.accept(Pair.of(NOISE_END_BARRENS, BiomeKeys.END_BARRENS));
parameters.accept(Pair.of(NOISE_END_MIDLANDS, BiomeKeys.END_MIDLANDS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ public static RegistryEntry<Biome> getOriginalEndBiome(int biomeX, int biomeY, i

if (MathHelper.square((long) ChunkSectionPos.getSectionCoord(x)) +
MathHelper.square((long) ChunkSectionPos.getSectionCoord(z)) <= 4096L) {
biomeEntry = BiomeCoordinator.getBiomeLookupOrThrow().getOrThrow(BiomeKeys.THE_END);
biomeEntry = BiomeCoordinator.END.nodeTheEnd.value;
} else {
double erosion = noise.erosion().sample(new DensityFunction.UnblendedNoisePos(x, y, z));
if (erosion > 0.25) {
biomeEntry = BiomeCoordinator.getBiomeLookupOrThrow().getOrThrow(BiomeKeys.END_HIGHLANDS);
biomeEntry = BiomeCoordinator.END.nodeEndHighlands.value;
} else if (erosion >= -0.0625) {
biomeEntry = BiomeCoordinator.getBiomeLookupOrThrow().getOrThrow(BiomeKeys.END_MIDLANDS);
biomeEntry = BiomeCoordinator.END.nodeEndMidlands.value;
} else if (erosion < -0.21875) {
biomeEntry = BiomeCoordinator.getBiomeLookupOrThrow().getOrThrow(BiomeKeys.SMALL_END_ISLANDS);
biomeEntry = BiomeCoordinator.END.nodeSmallEndIslands.value;
} else {
biomeEntry = BiomeCoordinator.getBiomeLookupOrThrow().getOrThrow(BiomeKeys.END_BARRENS);
biomeEntry = BiomeCoordinator.END.nodeEndBarrens.value;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ public abstract class MixinTheEndBiomeSource extends BiomeSource {

@Inject(method = "createVanilla", at = @At("HEAD"))
private static void biolith$getRegistry(RegistryEntryLookup<Biome> biomeLookup, CallbackInfoReturnable<TheEndBiomeSource> cir) {
biolith$biomeLookup = biomeLookup;
if (!biomeLookup.equals(biolith$biomeLookup)) {
biolith$biomeLookup = biomeLookup;
biolith$biomeEntries = null;
}
}

@ModifyReturnValue(method = "biomeStream", at = @At("RETURN"))
Expand Down

0 comments on commit 9556ae7

Please sign in to comment.