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);
|
||||
|
||||
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
|
||||
|
|
|
@ -5,9 +5,13 @@ import org.betterx.bclib.api.v2.generator.BCLBiomeSource;
|
|||
import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
|
||||
import org.betterx.bclib.client.gui.gridlayout.GridCheckboxCell;
|
||||
import org.betterx.bclib.client.gui.gridlayout.GridLayout;
|
||||
import org.betterx.bclib.interfaces.WorldGenSettingsComponentAccessor;
|
||||
import org.betterx.bclib.presets.worldgen.BCLWorldPreset;
|
||||
import org.betterx.bclib.presets.worldgen.BCLWorldPresetSettings;
|
||||
|
||||
import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen;
|
||||
import net.minecraft.client.gui.screens.worldselection.WorldCreationContext;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.network.chat.CommonComponents;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
|
@ -18,6 +22,7 @@ import net.minecraft.world.level.dimension.LevelStem;
|
|||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import java.util.Optional;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
|
@ -35,24 +40,26 @@ public class WorldSetupScreen extends BCLibScreen {
|
|||
private GridCheckboxCell bclibEnd;
|
||||
private GridCheckboxCell bclibNether;
|
||||
GridCheckboxCell endLegacy;
|
||||
GridCheckboxCell endCustomTerrain;
|
||||
GridCheckboxCell netherLegacy;
|
||||
|
||||
@Override
|
||||
protected void initLayout() {
|
||||
final int netherVersion = LevelGenUtil.getBiomeVersionForGenerator(context
|
||||
.worldGenSettings()
|
||||
.dimensions()
|
||||
.getOrCreateHolderOrThrow(
|
||||
LevelStem.NETHER)
|
||||
.value()
|
||||
.generator());
|
||||
final int endVersion = LevelGenUtil.getBiomeVersionForGenerator(context
|
||||
.worldGenSettings()
|
||||
.dimensions()
|
||||
.getOrCreateHolderOrThrow(
|
||||
LevelStem.END)
|
||||
.value()
|
||||
.generator());
|
||||
final int netherVersion;
|
||||
final int endVersion;
|
||||
final boolean customEndGen;
|
||||
if (createWorldScreen.worldGenSettingsComponent instanceof WorldGenSettingsComponentAccessor acc
|
||||
&& acc.bcl_getPreset()
|
||||
.isPresent() && acc.bcl_getPreset()
|
||||
.get()
|
||||
.value() instanceof BCLWorldPreset wp
|
||||
&& wp.settings instanceof BCLWorldPresetSettings settings) {
|
||||
netherVersion = settings.netherVersion;
|
||||
endVersion = settings.endVersion;
|
||||
customEndGen = settings.useEndTerrainGenerator;
|
||||
} else {
|
||||
throw new IllegalStateException("The WorldSetup Screen is only valid for BetterX Presets.");
|
||||
}
|
||||
|
||||
final int BUTTON_HEIGHT = 20;
|
||||
grid.addSpacerRow(20);
|
||||
|
@ -99,7 +106,17 @@ public class WorldSetupScreen extends BCLibScreen {
|
|||
colEnd.addSpacerRow(2);
|
||||
row = colEnd.addRow();
|
||||
row.addSpacer(20);
|
||||
endCustomTerrain = row.addCheckbox(
|
||||
Component.translatable("title.screen.bclib.worldgen.custom_end_terrain"),
|
||||
customEndGen,
|
||||
1.0,
|
||||
GridLayout.GridValueType.PERCENTAGE,
|
||||
(state) -> {
|
||||
}
|
||||
);
|
||||
|
||||
row = colEnd.addRow();
|
||||
row.addSpacer(20);
|
||||
endLegacy = row.addCheckbox(
|
||||
Component.translatable("title.screen.bclib.worldgen.legacy_square"),
|
||||
endVersion == BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE,
|
||||
|
@ -117,9 +134,11 @@ public class WorldSetupScreen extends BCLibScreen {
|
|||
GridLayout.GridValueType.PERCENTAGE,
|
||||
(state) -> {
|
||||
endLegacy.setEnabled(state);
|
||||
endCustomTerrain.setEnabled(state);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
grid.addSpacerRow(36);
|
||||
row = grid.addRow();
|
||||
row.addFiller();
|
||||
|
@ -147,9 +166,23 @@ public class WorldSetupScreen extends BCLibScreen {
|
|||
netherVersion = BCLBiomeSource.BIOME_SOURCE_VERSION_VANILLA;
|
||||
}
|
||||
|
||||
if (createWorldScreen.worldGenSettingsComponent instanceof WorldGenSettingsComponentAccessor acc
|
||||
&& acc.bcl_getPreset()
|
||||
.isPresent() && acc.bcl_getPreset()
|
||||
.get()
|
||||
.value() instanceof BCLWorldPreset worldPreset) {
|
||||
acc.bcl_setPreset(Optional.of(Holder.direct(worldPreset.withSettings(new BCLWorldPresetSettings(
|
||||
netherVersion,
|
||||
endVersion,
|
||||
endCustomTerrain.isChecked()
|
||||
)))));
|
||||
}
|
||||
|
||||
BCLib.LOGGER.info("Custom World Versions: end=" + endVersion + ", nether=" + netherVersion);
|
||||
updateConfiguration(LevelStem.END, BuiltinDimensionTypes.END, endVersion);
|
||||
updateConfiguration(LevelStem.NETHER, BuiltinDimensionTypes.NETHER, netherVersion);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -7,4 +7,5 @@ import java.util.Optional;
|
|||
|
||||
public interface WorldGenSettingsComponentAccessor {
|
||||
Optional<Holder<WorldPreset>> bcl_getPreset();
|
||||
void bcl_setPreset(Optional<Holder<WorldPreset>> preset);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,10 @@ public abstract class WorldGenSettingsComponentMixin implements WorldGenSettings
|
|||
@Accessor("preset")
|
||||
public abstract Optional<Holder<WorldPreset>> bcl_getPreset();
|
||||
|
||||
@Override
|
||||
@Accessor("preset")
|
||||
public abstract void bcl_setPreset(Optional<Holder<WorldPreset>> preset);
|
||||
|
||||
@ModifyArg(method = "init", index = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/components/CycleButton$Builder;withValues(Ljava/util/List;Ljava/util/List;)Lnet/minecraft/client/gui/components/CycleButton$Builder;"))
|
||||
public List<Holder<WorldPreset>> bcl_SortLists(List<Holder<WorldPreset>> list) {
|
||||
final Predicate<Holder<WorldPreset>> vanilla = (p -> p.unwrapKey()
|
||||
|
|
|
@ -2,8 +2,6 @@ package org.betterx.bclib.mixin.common;
|
|||
|
||||
import org.betterx.bclib.api.v2.LifeCycleAPI;
|
||||
import org.betterx.bclib.api.v2.generator.BCLBiomeSource;
|
||||
import org.betterx.bclib.api.v2.generator.BCLibEndBiomeSource;
|
||||
import org.betterx.bclib.api.v2.generator.BCLibNetherBiomeSource;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
|
@ -75,12 +73,6 @@ public abstract class ServerLevelMixin extends Level {
|
|||
bl2
|
||||
);
|
||||
|
||||
if (level.dimension() == Level.NETHER) {
|
||||
BCLibNetherBiomeSource.setWorldHeight(level.getChunkSource().getGenerator().getGenDepth());
|
||||
} else if (level.dimension() == Level.END) {
|
||||
BCLibEndBiomeSource.setWorldHeight(level.getChunkSource().getGenerator().getGenDepth());
|
||||
}
|
||||
|
||||
if (levelStem.generator().getBiomeSource() instanceof BCLBiomeSource source) {
|
||||
source.setSeed(level.getSeed());
|
||||
}
|
||||
|
|
|
@ -40,6 +40,10 @@ public class BCLWorldPreset extends WorldPreset {
|
|||
this.settings = settings;
|
||||
}
|
||||
|
||||
public BCLWorldPreset withSettings(WorldPresetSettings settings) {
|
||||
return new BCLWorldPreset(getDimensions(), sortOrder, settings);
|
||||
}
|
||||
|
||||
private Map<ResourceKey<LevelStem>, LevelStem> getDimensions() {
|
||||
return ((WorldPresetAccessor) this).bcl_getDimensions();
|
||||
}
|
||||
|
|
|
@ -55,5 +55,6 @@
|
|||
"title.bclib.the_nether": "Nether",
|
||||
"title.bclib.the_end": "Das Ende",
|
||||
"title.screen.bclib.worldgen.custom_biome_source": "Benutzerdefinierte Biomquelle verwenden",
|
||||
"title.screen.bclib.worldgen.legacy_square": "Legacy-Verteilung (1.17)"
|
||||
"title.screen.bclib.worldgen.legacy_square": "Legacy-Verteilung (1.17)",
|
||||
"title.screen.bclib.worldgen.custom_end_terrain": "Angepasster End-Terrain-Generator"
|
||||
}
|
|
@ -56,5 +56,6 @@
|
|||
"title.bclib.the_nether": "The Nether",
|
||||
"title.bclib.the_end": "The End",
|
||||
"title.screen.bclib.worldgen.custom_biome_source": "Use Custom Biome Source",
|
||||
"title.screen.bclib.worldgen.legacy_square": "Use Legacy Map (1.17)"
|
||||
"title.screen.bclib.worldgen.legacy_square": "Use Legacy Map (1.17)",
|
||||
"title.screen.bclib.worldgen.custom_end_terrain": "Custom End Terrain Generator"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue