[Fix] Dimension height is not updated for repaired BiomeSources (quiqueck/BetterEnd#28)

This commit is contained in:
Frank 2022-07-03 13:35:12 +02:00
parent 0eb857e293
commit b3c58b42e9
5 changed files with 34 additions and 5 deletions

View file

@ -2,6 +2,7 @@ package org.betterx.bclib.api.v2.generator;
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI;
import org.betterx.worlds.together.biomesource.MergeableBiomeSource;
import org.betterx.worlds.together.world.BiomeSourceWithNoiseRelatedSettings;
import org.betterx.worlds.together.world.BiomeSourceWithSeed;
import net.minecraft.core.Holder;
@ -9,6 +10,7 @@ import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
import com.google.common.collect.Sets;
@ -16,7 +18,7 @@ import java.util.Comparator;
import java.util.List;
import java.util.Set;
public abstract class BCLBiomeSource extends BiomeSource implements BiomeSourceWithSeed, MergeableBiomeSource<BCLBiomeSource> {
public abstract class BCLBiomeSource extends BiomeSource implements BiomeSourceWithSeed, MergeableBiomeSource<BCLBiomeSource>, BiomeSourceWithNoiseRelatedSettings {
protected final Registry<Biome> biomeRegistry;
protected long currentSeed;
protected int maxHeight;
@ -110,4 +112,9 @@ public abstract class BCLBiomeSource extends BiomeSource implements BiomeSourceW
final Set<Holder<Biome>> datapackBiomes = inputBiomeSource.possibleBiomes();
return this.createCopyForDatapack(datapackBiomes);
}
public void onLoadGeneratorSettings(NoiseGeneratorSettings generator) {
this.setMaxHeight(generator.noiseSettings().height());
}
}

View file

@ -9,6 +9,7 @@ import org.betterx.worlds.together.biomesource.MergeableBiomeSource;
import org.betterx.worlds.together.chunkgenerator.EnforceableChunkGenerator;
import org.betterx.worlds.together.chunkgenerator.InjectableSurfaceRules;
import org.betterx.worlds.together.chunkgenerator.RestorableBiomeSource;
import org.betterx.worlds.together.world.BiomeSourceWithNoiseRelatedSettings;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
@ -71,8 +72,8 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator implements Resto
) {
super(registry, registry2, biomeSource, holder);
initialBiomeSource = biomeSource;
if (biomeSource instanceof BCLBiomeSource bcl) {
bcl.setMaxHeight(holder.value().noiseSettings().height());
if (biomeSource instanceof BiomeSourceWithNoiseRelatedSettings bcl) {
bcl.onLoadGeneratorSettings(holder.value());
}
if (WorldsTogether.RUNS_TERRABLENDER) {

View file

@ -1,7 +1,8 @@
package org.betterx.bclib.mixin.common;
import org.betterx.bclib.api.v2.LifeCycleAPI;
import org.betterx.bclib.api.v2.generator.BCLBiomeSource;
import org.betterx.worlds.together.world.BiomeSourceWithNoiseRelatedSettings;
import org.betterx.worlds.together.world.BiomeSourceWithSeed;
import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceKey;
@ -12,6 +13,7 @@ import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator;
import net.minecraft.world.level.storage.LevelStorageSource.LevelStorageAccess;
import net.minecraft.world.level.storage.ServerLevelData;
import net.minecraft.world.level.storage.WritableLevelData;
@ -73,10 +75,15 @@ public abstract class ServerLevelMixin extends Level {
bl2
);
if (levelStem.generator().getBiomeSource() instanceof BCLBiomeSource source) {
if (levelStem.generator().getBiomeSource() instanceof BiomeSourceWithSeed source) {
source.setSeed(level.getSeed());
}
if (levelStem.generator().getBiomeSource() instanceof BiomeSourceWithNoiseRelatedSettings bcl
&& levelStem.generator() instanceof NoiseBasedChunkGenerator noiseGenerator) {
bcl.onLoadGeneratorSettings(noiseGenerator.generatorSettings().value());
}
if (bclib_lastWorld != null && bclib_lastWorld.equals(levelStorageAccess.getLevelId())) {
return;
}

View file

@ -3,6 +3,7 @@ package org.betterx.worlds.together.levelgen;
import org.betterx.worlds.together.WorldsTogether;
import org.betterx.worlds.together.biomesource.BiomeSourceWithConfig;
import org.betterx.worlds.together.chunkgenerator.EnforceableChunkGenerator;
import org.betterx.worlds.together.world.BiomeSourceWithNoiseRelatedSettings;
import org.betterx.worlds.together.world.BiomeSourceWithSeed;
import org.betterx.worlds.together.world.WorldConfig;
import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
@ -19,6 +20,7 @@ import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator;
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.levelgen.presets.WorldPreset;
@ -46,6 +48,11 @@ public class WorldGenUtil {
if (stem.generator().getBiomeSource() instanceof BiomeSourceWithSeed bcl) {
bcl.setSeed(seed);
}
if (stem.generator().getBiomeSource() instanceof BiomeSourceWithNoiseRelatedSettings bcl
&& stem.generator() instanceof NoiseBasedChunkGenerator noiseGenerator) {
bcl.onLoadGeneratorSettings(noiseGenerator.generatorSettings().value());
}
}
return settings;

View file

@ -0,0 +1,7 @@
package org.betterx.worlds.together.world;
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
public interface BiomeSourceWithNoiseRelatedSettings {
void onLoadGeneratorSettings(NoiseGeneratorSettings generator);
}