[Change] Separated all World-Load related code to a new namespace
This commit is contained in:
parent
67d09676c4
commit
25fa53541f
79 changed files with 1924 additions and 814 deletions
|
@ -1,29 +1,28 @@
|
|||
package org.betterx.bclib.presets;
|
||||
|
||||
import org.betterx.bclib.api.v2.tag.TagAPI;
|
||||
import org.betterx.bclib.api.v2.tag.TagType;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.FlatLevelGeneratorPresetTags;
|
||||
import net.minecraft.world.level.levelgen.flat.FlatLevelGeneratorPreset;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link org.betterx.worlds.together.flatLevel.FlatLevelPresets} instead
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public class FlatLevelPresets {
|
||||
public static TagType.Simple<FlatLevelGeneratorPreset> FLAT_LEVEL_PRESETS =
|
||||
TagAPI.registerType(
|
||||
Registry.FLAT_LEVEL_GENERATOR_PRESET_REGISTRY,
|
||||
"tags/worldgen/flat_level_generator_preset",
|
||||
(b) -> null
|
||||
);
|
||||
/**
|
||||
* @deprecated Use {@link org.betterx.worlds.together.flatLevel.FlatLevelPresets#FLAT_LEVEL_PRESETS} instead
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static TagType.Simple<FlatLevelGeneratorPreset> FLAT_LEVEL_PRESETS = org.betterx.worlds.together.flatLevel.FlatLevelPresets.FLAT_LEVEL_PRESETS;
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link org.betterx.worlds.together.flatLevel.FlatLevelPresets#register(ResourceLocation)} instead
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static ResourceKey<FlatLevelGeneratorPreset> register(ResourceLocation loc) {
|
||||
ResourceKey<FlatLevelGeneratorPreset> key = ResourceKey.create(
|
||||
Registry.FLAT_LEVEL_GENERATOR_PRESET_REGISTRY,
|
||||
loc
|
||||
);
|
||||
FLAT_LEVEL_PRESETS.addUntyped(FlatLevelGeneratorPresetTags.VISIBLE, key.location());
|
||||
return key;
|
||||
return org.betterx.worlds.together.flatLevel.FlatLevelPresets.register(loc);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
package org.betterx.bclib.presets.worldgen;
|
||||
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.api.v2.WorldDataAPI;
|
||||
import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
|
||||
import org.betterx.bclib.mixin.common.WorldPresetAccessor;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class BCLWorldPreset extends WorldPreset {
|
||||
public final WorldPresetSettings settings;
|
||||
public final int sortOrder;
|
||||
|
||||
private static final String TAG_GENERATOR = LevelGenUtil.TAG_GENERATOR;
|
||||
|
||||
private static int NEXT_IN_SORT_ORDER = 1000;
|
||||
|
||||
public BCLWorldPreset(
|
||||
Map<ResourceKey<LevelStem>, LevelStem> map,
|
||||
Optional<Integer> sortOrder,
|
||||
Optional<WorldPresetSettings> settings
|
||||
) {
|
||||
this(map, sortOrder.orElse(NEXT_IN_SORT_ORDER++), settings.orElse(VanillaWorldPresetSettings.DEFAULT));
|
||||
}
|
||||
|
||||
public BCLWorldPreset(Map<ResourceKey<LevelStem>, LevelStem> map, int sortOrder, WorldPresetSettings settings) {
|
||||
super(map);
|
||||
this.sortOrder = sortOrder;
|
||||
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();
|
||||
}
|
||||
|
||||
public static WorldPresetSettings writeWorldPresetSettings(Optional<Holder<WorldPreset>> worldPreset) {
|
||||
if (worldPreset.isPresent() && worldPreset.get().value() instanceof BCLWorldPreset wp) {
|
||||
writeWorldPresetSettings(wp.settings);
|
||||
return wp.settings;
|
||||
} else {
|
||||
writeWorldPresetSettings(VanillaWorldPresetSettings.DEFAULT);
|
||||
return VanillaWorldPresetSettings.DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeWorldPresetSettings(WorldPresetSettings presetSettings) {
|
||||
final RegistryOps<Tag> registryOps = RegistryOps.create(NbtOps.INSTANCE, BuiltinRegistries.ACCESS);
|
||||
final var codec = WorldPresetSettings.CODEC.orElse(presetSettings);
|
||||
final var encodeResult = codec.encodeStart(registryOps, presetSettings);
|
||||
|
||||
if (encodeResult.result().isPresent()) {
|
||||
final CompoundTag settingsNbt = WorldDataAPI.getRootTag(BCLib.TOGETHER_WORLDS);
|
||||
settingsNbt.put(TAG_GENERATOR, encodeResult.result().get());
|
||||
} else {
|
||||
BCLib.LOGGER.error("Unable to encode world generator settings generator for level.dat.");
|
||||
}
|
||||
|
||||
WorldDataAPI.saveFile(BCLib.TOGETHER_WORLDS);
|
||||
}
|
||||
}
|
|
@ -9,6 +9,9 @@ import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
|
|||
import org.betterx.bclib.api.v2.levelgen.surface.SurfaceRuleUtil;
|
||||
import org.betterx.bclib.interfaces.ChunkGeneratorAccessor;
|
||||
import org.betterx.bclib.interfaces.NoiseGeneratorSettingsProvider;
|
||||
import org.betterx.worlds.together.world.WorldGenUtil;
|
||||
import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
|
||||
import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
|
@ -78,18 +81,18 @@ public class BCLWorldPresetSettings extends WorldPresetSettings {
|
|||
return CODEC;
|
||||
}
|
||||
|
||||
public BCLWorldPreset buildPreset(
|
||||
public TogetherWorldPreset buildPreset(
|
||||
LevelStem overworldStem,
|
||||
LevelGenUtil.Context netherContext,
|
||||
LevelGenUtil.Context endContext
|
||||
WorldGenUtil.Context netherContext,
|
||||
WorldGenUtil.Context endContext
|
||||
) {
|
||||
return new BCLWorldPreset(buildDimensionMap(overworldStem, netherContext, endContext), 1000, this);
|
||||
return new TogetherWorldPreset(buildDimensionMap(overworldStem, netherContext, endContext), 1000, this);
|
||||
}
|
||||
|
||||
public Map<ResourceKey<LevelStem>, LevelStem> buildDimensionMap(
|
||||
LevelStem overworldStem,
|
||||
LevelGenUtil.Context netherContext,
|
||||
LevelGenUtil.Context endContext
|
||||
WorldGenUtil.Context netherContext,
|
||||
WorldGenUtil.Context endContext
|
||||
) {
|
||||
return Map.of(
|
||||
LevelStem.OVERWORLD,
|
||||
|
@ -108,17 +111,17 @@ public class BCLWorldPresetSettings extends WorldPresetSettings {
|
|||
return BCLBiomeSource.BIOME_SOURCE_VERSION_VANILLA;
|
||||
}
|
||||
|
||||
public LevelStem createStem(LevelGenUtil.Context ctx, ResourceKey<LevelStem> key) {
|
||||
public LevelStem createStem(WorldGenUtil.Context ctx, ResourceKey<LevelStem> key) {
|
||||
if (key == LevelStem.NETHER) return createNetherStem(ctx);
|
||||
if (key == LevelStem.END) return createEndStem(ctx);
|
||||
return null;
|
||||
}
|
||||
|
||||
public LevelStem createNetherStem(LevelGenUtil.Context ctx) {
|
||||
public LevelStem createNetherStem(WorldGenUtil.Context ctx) {
|
||||
return LevelGenUtil.getBCLNetherLevelStem(ctx, Optional.of(netherVersion));
|
||||
}
|
||||
|
||||
public LevelStem createEndStem(LevelGenUtil.Context ctx) {
|
||||
public LevelStem createEndStem(WorldGenUtil.Context ctx) {
|
||||
return LevelGenUtil.getBCLEndLevelStem(ctx, Optional.of(endVersion));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,120 +0,0 @@
|
|||
package org.betterx.bclib.presets.worldgen;
|
||||
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.api.v2.generator.BCLBiomeSource;
|
||||
import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
|
||||
import org.betterx.bclib.api.v2.tag.TagAPI;
|
||||
import org.betterx.bclib.api.v2.tag.TagType;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.WorldPresetTags;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class BCLWorldPresets {
|
||||
|
||||
public static final TagType.Simple<WorldPreset> WORLD_PRESETS =
|
||||
TagAPI.registerType(BuiltinRegistries.WORLD_PRESET, "tags/worldgen/world_preset");
|
||||
private static Map<ResourceKey<WorldPreset>, PresetBuilder> BUILDERS = Maps.newHashMap();
|
||||
private static final Map<ResourceKey<WorldPreset>, WorldPresetSettings> SETTINGS = Maps.newHashMap();
|
||||
public static final ResourceKey<WorldPreset> BCL_WORLD =
|
||||
register(
|
||||
BCLib.makeID("normal"),
|
||||
(overworldStem, netherContext, endContext) ->
|
||||
new BCLWorldPresetSettings(BCLBiomeSource.DEFAULT_BIOME_SOURCE_VERSION).buildPreset(
|
||||
overworldStem,
|
||||
netherContext,
|
||||
endContext
|
||||
),
|
||||
true
|
||||
);
|
||||
public static Optional<ResourceKey<WorldPreset>> DEFAULT = Optional.of(BCL_WORLD);
|
||||
public static final ResourceKey<WorldPreset> BCL_WORLD_17 = register(
|
||||
BCLib.makeID("legacy_17"),
|
||||
(overworldStem, netherContext, endContext) ->
|
||||
new BCLWorldPresetSettings(BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE).buildPreset(
|
||||
overworldStem,
|
||||
netherContext,
|
||||
endContext
|
||||
),
|
||||
false
|
||||
);
|
||||
|
||||
/**
|
||||
* Registers a custom WorldPreset (with custom rules and behaviour)
|
||||
* <p>
|
||||
* See also {@link org.betterx.bclib.client.presets.WorldPresetsUI} if you need to add a Customize Button/Screen
|
||||
* for your preset
|
||||
*
|
||||
* @param loc The ID of your Preset
|
||||
* @return The key you may use to reference your new Preset
|
||||
*/
|
||||
private static ResourceKey<WorldPreset> register(ResourceLocation loc) {
|
||||
return register(loc, true);
|
||||
}
|
||||
|
||||
private static ResourceKey<WorldPreset> register(ResourceLocation loc, boolean addToNormal) {
|
||||
ResourceKey<WorldPreset> key = ResourceKey.create(Registry.WORLD_PRESET_REGISTRY, loc);
|
||||
if (addToNormal) {
|
||||
WORLD_PRESETS.addUntyped(WorldPresetTags.NORMAL, key.location());
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
public static void registerPresets() {
|
||||
|
||||
}
|
||||
|
||||
public static ResourceKey<WorldPreset> register(
|
||||
ResourceLocation loc,
|
||||
PresetBuilder builder,
|
||||
boolean visibleInUI
|
||||
) {
|
||||
ResourceKey<WorldPreset> key = register(loc, visibleInUI);
|
||||
|
||||
if (BUILDERS == null) {
|
||||
BCLib.LOGGER.error("Unable to register WorldPreset '" + loc + "'.");
|
||||
|
||||
} else {
|
||||
BUILDERS.put(key, builder);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
public static void bootstrapPresets(
|
||||
Registry<WorldPreset> presets,
|
||||
LevelStem overworldStem,
|
||||
LevelGenUtil.Context netherContext,
|
||||
LevelGenUtil.Context endContext
|
||||
) {
|
||||
|
||||
for (Map.Entry<ResourceKey<WorldPreset>, PresetBuilder> e : BUILDERS.entrySet()) {
|
||||
BCLWorldPreset preset = e.getValue().create(overworldStem, netherContext, endContext);
|
||||
SETTINGS.put(e.getKey(), preset.settings);
|
||||
BuiltinRegistries.register(presets, e.getKey(), preset);
|
||||
}
|
||||
BUILDERS = null;
|
||||
}
|
||||
|
||||
public static WorldPresetSettings getSettingsForPreset(ResourceKey<WorldPreset> key) {
|
||||
return SETTINGS.getOrDefault(key, BCLWorldPresetSettings.DEFAULT);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface PresetBuilder {
|
||||
BCLWorldPreset create(
|
||||
LevelStem overworldStem,
|
||||
LevelGenUtil.Context netherContext,
|
||||
LevelGenUtil.Context endContext
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package org.betterx.bclib.presets.worldgen;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
import net.minecraft.world.level.levelgen.WorldGenSettings;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class VanillaWorldPresetSettings extends WorldPresetSettings {
|
||||
public static final VanillaWorldPresetSettings DEFAULT = new VanillaWorldPresetSettings();
|
||||
public static final Codec<VanillaWorldPresetSettings> CODEC = Codec.unit(VanillaWorldPresetSettings::new);
|
||||
|
||||
@Override
|
||||
public Codec<? extends WorldPresetSettings> codec() {
|
||||
return CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldGenSettings repairSettingsOnLoad(RegistryAccess registryAccess, WorldGenSettings settings) {
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeSource fixBiomeSource(BiomeSource biomeSource, Set<Holder<Biome>> datapackBiomes) {
|
||||
return biomeSource;
|
||||
}
|
||||
}
|
|
@ -1,200 +0,0 @@
|
|||
package org.betterx.bclib.presets.worldgen;
|
||||
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.api.v2.LifeCycleAPI;
|
||||
import org.betterx.bclib.api.v2.WorldDataAPI;
|
||||
import org.betterx.bclib.api.v2.dataexchange.DataExchangeAPI;
|
||||
import org.betterx.bclib.api.v2.datafixer.DataFixerAPI;
|
||||
import org.betterx.bclib.api.v2.generator.BCLibEndBiomeSource;
|
||||
import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
|
||||
import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
|
||||
import org.betterx.bclib.interfaces.WorldGenSettingsComponentAccessor;
|
||||
import org.betterx.bclib.mixin.common.RegistryOpsAccessor;
|
||||
|
||||
import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.levelgen.WorldGenSettings;
|
||||
import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Optional;
|
||||
|
||||
public class WorldBootstrap {
|
||||
private static class Helpers {
|
||||
|
||||
private static void initializeWorldDataAPI(
|
||||
LevelStorageSource.LevelStorageAccess levelStorageAccess,
|
||||
boolean newWorld
|
||||
) {
|
||||
File levelPath = levelStorageAccess.getLevelPath(LevelResource.ROOT).toFile();
|
||||
initializeWorldDataAPI(levelPath, newWorld);
|
||||
}
|
||||
|
||||
private static void setupWorld() {
|
||||
InternalBiomeAPI.prepareNewLevel();
|
||||
DataExchangeAPI.prepareServerside();
|
||||
}
|
||||
|
||||
private static void initializeWorldDataAPI(File levelBaseDir, boolean newWorld) {
|
||||
WorldDataAPI.load(new File(levelBaseDir, "data"));
|
||||
|
||||
if (newWorld) {
|
||||
WorldDataAPI.saveFile(BCLib.MOD_ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class DedicatedServer {
|
||||
public static void registryReady(RegistryOps<Tag> regOps) {
|
||||
InternalBiomeAPI.initRegistry(regOps);
|
||||
}
|
||||
|
||||
public static void setupWorld(LevelStorageSource.LevelStorageAccess levelStorageAccess) {
|
||||
Helpers.setupWorld();
|
||||
|
||||
File levelDat = levelStorageAccess.getLevelPath(LevelResource.LEVEL_DATA_FILE).toFile();
|
||||
if (!levelDat.exists()) {
|
||||
BCLib.LOGGER.info("Creating a new World, no fixes needed");
|
||||
Helpers.initializeWorldDataAPI(levelStorageAccess, true);
|
||||
BCLWorldPreset.writeWorldPresetSettings(Optional.empty());
|
||||
DataFixerAPI.initializePatchData();
|
||||
} else {
|
||||
Helpers.initializeWorldDataAPI(levelStorageAccess, false);
|
||||
DataFixerAPI.fixData(levelStorageAccess, false, (didFix) -> {/* not called when showUI==false */});
|
||||
}
|
||||
|
||||
|
||||
LifeCycleAPI._runBeforeLevelLoad();
|
||||
}
|
||||
}
|
||||
|
||||
public static class InGUI {
|
||||
public static void registryReady(WorldGenSettingsComponent worldGenSettingsComponent) {
|
||||
InternalBiomeAPI.initRegistry(worldGenSettingsComponent.registryHolder());
|
||||
}
|
||||
|
||||
public static void registryReady(Optional<RegistryOps<Tag>> registryOps) {
|
||||
if (registryOps.orElse(null) instanceof RegistryOpsAccessor acc) {
|
||||
InternalBiomeAPI.initRegistry(acc.bcl_getRegistryAccess());
|
||||
}
|
||||
}
|
||||
|
||||
public static void setupNewWorld(
|
||||
Optional<LevelStorageSource.LevelStorageAccess> levelStorageAccess,
|
||||
WorldGenSettingsComponent worldGenSettingsComponent
|
||||
) {
|
||||
if (levelStorageAccess.isPresent()) {
|
||||
Helpers.setupWorld();
|
||||
|
||||
Helpers.initializeWorldDataAPI(levelStorageAccess.get(), true);
|
||||
|
||||
if (worldGenSettingsComponent instanceof WorldGenSettingsComponentAccessor acc) {
|
||||
BCLWorldPreset.writeWorldPresetSettings(adaptPresetForDatapacks(acc, worldGenSettingsComponent));
|
||||
}
|
||||
|
||||
DataFixerAPI.initializePatchData();
|
||||
// DataFixerAPI.createWorldData(
|
||||
// levelStorageAccess.get(),
|
||||
// worldGenSettingsComponent.settings().worldGenSettings()
|
||||
// );
|
||||
|
||||
LifeCycleAPI._runBeforeLevelLoad();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Does not call {@link LifeCycleAPI#_runBeforeLevelLoad()}
|
||||
*/
|
||||
public static void setupLoadedWorld(
|
||||
String levelID,
|
||||
LevelStorageSource levelSource
|
||||
) {
|
||||
Helpers.setupWorld();
|
||||
try {
|
||||
var levelStorageAccess = levelSource.createAccess(levelID);
|
||||
Helpers.initializeWorldDataAPI(levelStorageAccess, true);
|
||||
levelStorageAccess.close();
|
||||
} catch (Exception e) {
|
||||
BCLib.LOGGER.error("Failed to initialize data in world", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class InFreshLevel {
|
||||
public static void setupNewWorld(
|
||||
String levelID,
|
||||
WorldGenSettings worldGenSettings,
|
||||
LevelStorageSource levelSource,
|
||||
Optional<Holder<WorldPreset>> worldPreset
|
||||
) {
|
||||
InGUI.setupLoadedWorld(levelID, levelSource);
|
||||
|
||||
BCLWorldPreset.writeWorldPresetSettings(worldPreset);
|
||||
DataFixerAPI.initializePatchData();
|
||||
LifeCycleAPI._runBeforeLevelLoad();
|
||||
}
|
||||
}
|
||||
|
||||
private static Optional<Holder<WorldPreset>> adaptPresetForDatapacks(
|
||||
WorldGenSettingsComponentAccessor accessor,
|
||||
WorldGenSettingsComponent component
|
||||
) {
|
||||
LevelStem endStem = component.settings().worldGenSettings().dimensions().get(LevelStem.END);
|
||||
Optional<Holder<WorldPreset>> currentPreset = accessor.bcl_getPreset();
|
||||
|
||||
//We probably loaded a Datapack for the End
|
||||
if (!(endStem.generator().getBiomeSource() instanceof BCLibEndBiomeSource)) {
|
||||
BCLib.LOGGER.info("Detected Datapack for END.");
|
||||
|
||||
if (currentPreset.isPresent()) {
|
||||
if (currentPreset.get().value() instanceof BCLWorldPreset worldPreset) {
|
||||
ResourceKey key = currentPreset.get().unwrapKey().orElse(null);
|
||||
//user did not configure the Preset!
|
||||
if (BCLWorldPresets.BCL_WORLD.equals(key) || BCLWorldPresets.BCL_WORLD_17.equals(key)) {
|
||||
if (worldPreset.settings instanceof BCLWorldPresetSettings settings) {
|
||||
BCLib.LOGGER.info("Changing Default WorldPreset Settings for Datapack use.");
|
||||
|
||||
worldPreset = worldPreset.withSettings(new BCLWorldPresetSettings(
|
||||
settings.netherVersion,
|
||||
settings.endVersion,
|
||||
false,
|
||||
false
|
||||
));
|
||||
currentPreset = Optional.of(Holder.direct(worldPreset));
|
||||
accessor.bcl_setPreset(currentPreset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return currentPreset;
|
||||
}
|
||||
|
||||
public static WorldGenSettings enforceInNewWorld(WorldGenSettings worldGenSettings) {
|
||||
worldGenSettings = LevelGenUtil
|
||||
.getWorldSettings()
|
||||
.repairSettingsOnLoad(InternalBiomeAPI.worldRegistryAccess(), worldGenSettings);
|
||||
return worldGenSettings;
|
||||
}
|
||||
|
||||
public static WorldGenSettings enforceInLoadedWorld(
|
||||
Optional<RegistryOps<Tag>> registryOps,
|
||||
WorldGenSettings worldGenSettings
|
||||
) {
|
||||
if (registryOps.orElse(null) instanceof RegistryOpsAccessor acc) {
|
||||
return LevelGenUtil
|
||||
.getWorldSettings()
|
||||
.repairSettingsOnLoad(acc.bcl_getRegistryAccess(), worldGenSettings);
|
||||
//.repairSettingsOnLoad(InternalBiomeAPI.worldRegistryAccess(), worldGenSettings);
|
||||
} else {
|
||||
BCLib.LOGGER.error("Unable to obtain registryAccess when enforcing generators.");
|
||||
}
|
||||
return worldGenSettings;
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
package org.betterx.bclib.presets.worldgen;
|
||||
|
||||
import org.betterx.bclib.BCLib;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.MappedRegistry;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
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.WorldGenSettings;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
public abstract class WorldPresetSettings {
|
||||
public static final ResourceKey<Registry<Codec<? extends WorldPresetSettings>>> WORLD_PRESET_SETTINGS_REGISTRY =
|
||||
createRegistryKey(BCLib.makeID("worldgen/world_preset_settings"));
|
||||
|
||||
public static final Registry<Codec<? extends WorldPresetSettings>> WORLD_PRESET_SETTINGS =
|
||||
registerSimple(WORLD_PRESET_SETTINGS_REGISTRY);
|
||||
|
||||
public static final Codec<WorldPresetSettings> CODEC = WORLD_PRESET_SETTINGS
|
||||
.byNameCodec()
|
||||
.dispatchStable(WorldPresetSettings::codec, Function.identity());
|
||||
|
||||
|
||||
private static <T> ResourceKey<Registry<T>> createRegistryKey(ResourceLocation location) {
|
||||
|
||||
return ResourceKey.createRegistryKey(location);
|
||||
}
|
||||
|
||||
private static <T> Registry<T> registerSimple(ResourceKey<? extends Registry<T>> resourceKey) {
|
||||
return new MappedRegistry<>(resourceKey, Lifecycle.stable(), null);
|
||||
}
|
||||
|
||||
public static Codec<? extends WorldPresetSettings> register(
|
||||
ResourceLocation loc,
|
||||
Codec<? extends WorldPresetSettings> codec
|
||||
) {
|
||||
return Registry.register(WORLD_PRESET_SETTINGS, loc, codec);
|
||||
}
|
||||
|
||||
public static void bootstrap() {
|
||||
register(BCLib.makeID("bcl_world_preset_settings"), BCLWorldPresetSettings.CODEC);
|
||||
register(BCLib.makeID("vanilla_world_preset_settings"), VanillaWorldPresetSettings.CODEC);
|
||||
}
|
||||
|
||||
public abstract Codec<? extends WorldPresetSettings> codec();
|
||||
public abstract WorldGenSettings repairSettingsOnLoad(RegistryAccess registryAccess, WorldGenSettings settings);
|
||||
public abstract BiomeSource fixBiomeSource(BiomeSource biomeSource, Set<Holder<Biome>> datapackBiomes);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue