Correct handling of WorldPreset Settings from UI
This commit is contained in:
parent
73cd08fa69
commit
586485fe48
12 changed files with 106 additions and 58 deletions
|
@ -23,6 +23,7 @@ public abstract class BCLBiomeSource extends BiomeSource {
|
|||
public static int DEFAULT_BIOME_SOURCE_VERSION = BIOME_SOURCE_VERSION_HEX;
|
||||
protected final Registry<Biome> biomeRegistry;
|
||||
protected long currentSeed;
|
||||
protected int maxHeight;
|
||||
|
||||
public final int biomeSourceVersion;
|
||||
|
||||
|
@ -62,12 +63,26 @@ public abstract class BCLBiomeSource extends BiomeSource {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set world height
|
||||
*
|
||||
* @param maxHeight height of the World.
|
||||
*/
|
||||
final public void setMaxHeight(int maxHeight) {
|
||||
if (this.maxHeight != maxHeight) {
|
||||
System.out.println(this + " set Max Height: " + maxHeight);
|
||||
this.maxHeight = maxHeight;
|
||||
onHeightChange(maxHeight);
|
||||
}
|
||||
}
|
||||
|
||||
protected final void initMap(long seed) {
|
||||
System.out.println(this + " updates Map");
|
||||
onInitMap(seed);
|
||||
}
|
||||
|
||||
protected abstract void onInitMap(long newSeed);
|
||||
protected abstract void onHeightChange(int newHeight);
|
||||
|
||||
public static int getVersionBiomeSource(BiomeSource biomeSource) {
|
||||
if (biomeSource == null) return BCLBiomeSource.BIOME_SOURCE_VERSION_NONE;
|
||||
|
|
|
@ -69,6 +69,9 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator {
|
|||
) {
|
||||
super(registry, registry2, biomeSource, holder);
|
||||
initialBiomeSource = biomeSource;
|
||||
if (biomeSource instanceof BCLBiomeSource bcl) {
|
||||
bcl.setMaxHeight(holder.value().noiseSettings().height());
|
||||
}
|
||||
|
||||
if (BCLib.RUNS_TERRABLENDER) {
|
||||
BCLib.LOGGER.info("Make sure features are loaded from terrablender for " + biomeSource);
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.betterx.bclib.api.v2.generator;
|
|||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.api.v2.generator.map.hex.HexBiomeMap;
|
||||
import org.betterx.bclib.api.v2.generator.map.square.SquareBiomeMap;
|
||||
import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
|
||||
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiome;
|
||||
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI;
|
||||
import org.betterx.bclib.config.ConfigKeeper.StringArrayEntry;
|
||||
|
@ -10,6 +11,7 @@ import org.betterx.bclib.config.Configs;
|
|||
import org.betterx.bclib.interfaces.BiomeMap;
|
||||
import org.betterx.bclib.interfaces.TheEndBiomeDataAccessor;
|
||||
import org.betterx.bclib.noise.OpenSimplexNoise;
|
||||
import org.betterx.bclib.presets.worldgen.BCLWorldPresetSettings;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
|
@ -67,8 +69,6 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
|
|||
private BiomeMap mapLand;
|
||||
private BiomeMap mapVoid;
|
||||
|
||||
private static int worldHeight;
|
||||
|
||||
private final BiomePicker endLandBiomePicker;
|
||||
private final BiomePicker endVoidBiomePicker;
|
||||
|
||||
|
@ -141,7 +141,12 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
|
|||
this.centerBiome = biomeRegistry.getOrCreateHolderOrThrow(Biomes.THE_END);
|
||||
this.barrens = biomeRegistry.getOrCreateHolderOrThrow(Biomes.END_BARRENS);
|
||||
|
||||
this.endLandFunction = GeneratorOptions.getEndLandFunction();
|
||||
if (LevelGenUtil.getWorldSettings() instanceof BCLWorldPresetSettings settings
|
||||
&& !settings.useEndTerrainGenerator) {
|
||||
this.endLandFunction = null;
|
||||
} else {
|
||||
this.endLandFunction = GeneratorOptions.getEndLandFunction();
|
||||
}
|
||||
this.pos = new Point();
|
||||
|
||||
if (initMaps) {
|
||||
|
@ -160,15 +165,6 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set world height, used when Nether is larger than vanilla 128 blocks tall.
|
||||
*
|
||||
* @param worldHeight height of the Nether ceiling.
|
||||
*/
|
||||
public static void setWorldHeight(int worldHeight) {
|
||||
BCLibEndBiomeSource.worldHeight = worldHeight;
|
||||
}
|
||||
|
||||
private static List<Holder<Biome>> getBclBiomes(Registry<Biome> biomeRegistry) {
|
||||
List<String> include = Configs.BIOMES_CONFIG.getEntry(
|
||||
"force_include",
|
||||
|
@ -297,6 +293,11 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
|
|||
this.noise = new SimplexNoise(chunkRandom);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHeightChange(int newHeight) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Holder<Biome> getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler sampler) {
|
||||
|
@ -331,7 +332,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
|
|||
}
|
||||
} else {
|
||||
pos.setLocation(biomeX, biomeZ);
|
||||
if (endLandFunction.apply(pos, worldHeight)) {
|
||||
if (endLandFunction.apply(pos, maxHeight)) {
|
||||
return dist <= farEndBiomes ? centerBiome : mapLand.getBiome(posX, biomeY << 2, posZ).biome;
|
||||
} else {
|
||||
return dist <= farEndBiomes ? barrens : mapVoid.getBiome(posX, biomeY << 2, posZ).biome;
|
||||
|
@ -346,6 +347,6 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BCLib - The End BiomeSource (" + Integer.toHexString(hashCode()) + ", version=" + biomeSourceVersion + ", seed=" + currentSeed + ", biomes=" + possibleBiomes().size() + ")";
|
||||
return "BCLib - The End BiomeSource (" + Integer.toHexString(hashCode()) + ", version=" + biomeSourceVersion + ", seed=" + currentSeed + ", height=" + maxHeight + ", biomes=" + possibleBiomes().size() + ")";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,8 +30,6 @@ import java.util.Optional;
|
|||
import java.util.Set;
|
||||
|
||||
public class BCLibNetherBiomeSource extends BCLBiomeSource {
|
||||
private static int lastWorldHeight;
|
||||
private static int worldHeight;
|
||||
public static final Codec<BCLibNetherBiomeSource> CODEC = RecordCodecBuilder
|
||||
.create(instance -> instance
|
||||
.group(
|
||||
|
@ -118,15 +116,6 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set world height, used when Nether is larger than vanilla 128 blocks tall.
|
||||
*
|
||||
* @param worldHeight height of the Nether ceiling.
|
||||
*/
|
||||
public static void setWorldHeight(int worldHeight) {
|
||||
BCLibNetherBiomeSource.worldHeight = worldHeight;
|
||||
}
|
||||
|
||||
private static List<Holder<Biome>> getBclBiomes(Registry<Biome> biomeRegistry) {
|
||||
List<String> include = Configs.BIOMES_CONFIG.getEntry("force_include", "nether_biomes", StringArrayEntry.class)
|
||||
.getValue();
|
||||
|
@ -177,10 +166,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
|
|||
public Holder<Biome> getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler var4) {
|
||||
if (biomeMap == null)
|
||||
return this.possibleBiomes().stream().findFirst().get();
|
||||
if (lastWorldHeight != worldHeight) {
|
||||
lastWorldHeight = worldHeight;
|
||||
initMap(this.currentSeed);
|
||||
}
|
||||
|
||||
if ((biomeX & 63) == 0 && (biomeZ & 63) == 0) {
|
||||
biomeMap.clearCache();
|
||||
}
|
||||
|
@ -198,13 +184,13 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
|
|||
TriFunction<Long, Integer, BiomePicker, BiomeMap> mapConstructor = (biomeSourceVersion != BIOME_SOURCE_VERSION_HEX)
|
||||
? SquareBiomeMap::new
|
||||
: HexBiomeMap::new;
|
||||
if (worldHeight > 128 && GeneratorOptions.useVerticalBiomes()) {
|
||||
if (maxHeight > 128 && GeneratorOptions.useVerticalBiomes()) {
|
||||
this.biomeMap = new MapStack(
|
||||
seed,
|
||||
GeneratorOptions.getBiomeSizeNether(),
|
||||
biomePicker,
|
||||
GeneratorOptions.getVerticalBiomeSizeNether(),
|
||||
worldHeight,
|
||||
maxHeight,
|
||||
mapConstructor
|
||||
);
|
||||
} else {
|
||||
|
@ -216,8 +202,13 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHeightChange(int newHeight) {
|
||||
initMap(currentSeed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BCLib - Nether BiomeSource (" + Integer.toHexString(hashCode()) + ", version=" + biomeSourceVersion + ", seed=" + currentSeed + ", biomes=" + possibleBiomes().size() + ")";
|
||||
return "BCLib - Nether BiomeSource (" + Integer.toHexString(hashCode()) + ", version=" + biomeSourceVersion + ", seed=" + currentSeed + ", height=" + maxHeight + ", biomes=" + possibleBiomes().size() + ")";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import net.minecraft.core.Holder;
|
|||
import net.minecraft.core.MappedRegistry;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.nbt.Tag;
|
||||
|
@ -309,7 +310,8 @@ public class LevelGenUtil {
|
|||
}
|
||||
|
||||
public static WorldPresetSettings getWorldSettings() {
|
||||
final RegistryAccess registryAccess = RegistryAccess.builtinCopy();
|
||||
if (BuiltinRegistries.ACCESS == null) return null;
|
||||
final RegistryAccess registryAccess = BuiltinRegistries.ACCESS;
|
||||
final RegistryOps<Tag> registryOps = RegistryOps.create(NbtOps.INSTANCE, registryAccess);
|
||||
|
||||
Optional<WorldPresetSettings> oLevelStem = WorldPresetSettings.CODEC
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue