Removed WorldPresetSettings
This commit is contained in:
parent
877691011f
commit
fb19ebaae6
23 changed files with 291 additions and 543 deletions
|
@ -10,7 +10,6 @@ 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.levelgen.WorldGenUtil;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
|
@ -109,9 +108,10 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator implements Resto
|
|||
public void restoreInitialBiomeSource(ResourceKey<LevelStem> dimensionKey) {
|
||||
if (initialBiomeSource != getBiomeSource()) {
|
||||
if (this instanceof ChunkGeneratorAccessor acc) {
|
||||
BiomeSource bs = WorldGenUtil.getWorldSettings()
|
||||
.addDatapackBiomes(initialBiomeSource, getBiomeSource().possibleBiomes());
|
||||
acc.bcl_setBiomeSource(bs);
|
||||
if (initialBiomeSource instanceof MergeableBiomeSource bs) {
|
||||
acc.bcl_setBiomeSource(bs.mergeWithBiomeSource(getBiomeSource()));
|
||||
}
|
||||
|
||||
rebuildFeaturesPerStep(getBiomeSource());
|
||||
}
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator implements Resto
|
|||
} else {
|
||||
bs = referenceGenerator.getBiomeSource();
|
||||
}
|
||||
|
||||
|
||||
InternalBiomeAPI.applyModifications(bs, dimensionKey);
|
||||
referenceGenerator = new BCLChunkGenerator(
|
||||
generator.bclib_getStructureSetsRegistry(),
|
||||
|
|
|
@ -8,9 +8,7 @@ import org.betterx.bclib.config.ConfigKeeper.StringArrayEntry;
|
|||
import org.betterx.bclib.config.Configs;
|
||||
import org.betterx.bclib.interfaces.BiomeMap;
|
||||
import org.betterx.bclib.interfaces.TheEndBiomeDataAccessor;
|
||||
import org.betterx.bclib.presets.worldgen.BCLWorldPresetSettings;
|
||||
import org.betterx.worlds.together.biomesource.BiomeSourceWithConfig;
|
||||
import org.betterx.worlds.together.levelgen.WorldGenUtil;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
|
@ -158,12 +156,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource implements BiomeSourceWi
|
|||
this.centerBiome = biomeRegistry.getOrCreateHolderOrThrow(Biomes.THE_END);
|
||||
this.barrens = biomeRegistry.getOrCreateHolderOrThrow(Biomes.END_BARRENS);
|
||||
|
||||
if (WorldGenUtil.getWorldSettings() instanceof BCLWorldPresetSettings settings
|
||||
&& !settings.useEndTerrainGenerator) {
|
||||
this.endLandFunction = null;
|
||||
} else {
|
||||
this.endLandFunction = GeneratorOptions.getEndLandFunction();
|
||||
}
|
||||
this.endLandFunction = GeneratorOptions.getEndLandFunction();
|
||||
this.pos = new Point();
|
||||
|
||||
if (initMaps) {
|
||||
|
|
|
@ -216,7 +216,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource implements BiomeSourc
|
|||
|
||||
@Override
|
||||
public void setTogetherConfig(BCLNetherBiomeSourceConfig newConfig) {
|
||||
this.config = config;
|
||||
this.config = newConfig;
|
||||
initMap(currentSeed);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,12 @@ import java.util.Objects;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BCLEndBiomeSourceConfig implements BiomeSourceConfig<BCLibEndBiomeSource> {
|
||||
public static final BCLEndBiomeSourceConfig VANILLA = new BCLEndBiomeSourceConfig(
|
||||
EndBiomeMapType.VANILLA,
|
||||
EndBiomeGeneratorType.VANILLA,
|
||||
true,
|
||||
4096
|
||||
);
|
||||
public static final BCLEndBiomeSourceConfig MINECRAFT_17 = new BCLEndBiomeSourceConfig(
|
||||
EndBiomeMapType.SQUARE,
|
||||
EndBiomeGeneratorType.PAULEVS,
|
||||
|
|
|
@ -16,6 +16,9 @@ import java.util.Objects;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BCLNetherBiomeSourceConfig implements BiomeSourceConfig<BCLibNetherBiomeSource> {
|
||||
public static final BCLNetherBiomeSourceConfig VANILLA = new BCLNetherBiomeSourceConfig(
|
||||
NetherBiomeMapType.VANILLA
|
||||
);
|
||||
public static final BCLNetherBiomeSourceConfig MINECRAFT_17 = new BCLNetherBiomeSourceConfig(
|
||||
NetherBiomeMapType.SQUARE
|
||||
);
|
||||
|
|
|
@ -10,16 +10,17 @@ import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
|
|||
import org.betterx.bclib.registry.PresetsRegistry;
|
||||
import org.betterx.worlds.together.world.event.WorldEvents;
|
||||
import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
|
||||
import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
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.LevelStorageSource;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
@ -89,21 +90,20 @@ public class LevelGenEvents {
|
|||
InternalBiomeAPI.initRegistry(a);
|
||||
}
|
||||
|
||||
public static WorldPresetSettings prepareWorld(
|
||||
public static void prepareWorld(
|
||||
LevelStorageSource.LevelStorageAccess storageAccess,
|
||||
WorldPresetSettings settings,
|
||||
Map<ResourceKey<LevelStem>, ChunkGenerator> dimensions,
|
||||
boolean isNewWorld
|
||||
) {
|
||||
setupWorld();
|
||||
if (isNewWorld) {
|
||||
DataFixerAPI.initializePatchData();
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
public static WorldPresetSettings prepareServerWorld(
|
||||
public static void prepareServerWorld(
|
||||
LevelStorageSource.LevelStorageAccess storageAccess,
|
||||
WorldPresetSettings settings,
|
||||
Map<ResourceKey<LevelStem>, ChunkGenerator> dimensions,
|
||||
boolean isNewWorld
|
||||
) {
|
||||
setupWorld();
|
||||
|
@ -113,9 +113,6 @@ public class LevelGenEvents {
|
|||
} else {
|
||||
DataFixerAPI.fixData(storageAccess, false, (didFix) -> {/* not called when showUI==false */});
|
||||
}
|
||||
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
public static void onWorldLoad() {
|
||||
|
|
|
@ -7,13 +7,11 @@ import org.betterx.bclib.api.v2.generator.BCLibEndBiomeSource;
|
|||
import org.betterx.bclib.api.v2.generator.BCLibNetherBiomeSource;
|
||||
import org.betterx.bclib.api.v2.generator.config.BCLEndBiomeSourceConfig;
|
||||
import org.betterx.bclib.api.v2.generator.config.BCLNetherBiomeSourceConfig;
|
||||
import org.betterx.bclib.presets.worldgen.BCLWorldPresetSettings;
|
||||
import org.betterx.bclib.registry.PresetsRegistry;
|
||||
import org.betterx.worlds.together.levelgen.WorldGenUtil;
|
||||
import org.betterx.worlds.together.util.ModUtil;
|
||||
import org.betterx.worlds.together.world.WorldConfig;
|
||||
import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
|
||||
import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
|
||||
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import net.minecraft.core.Holder;
|
||||
|
@ -26,6 +24,7 @@ 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.WorldGenSettings;
|
||||
import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
@ -111,23 +110,23 @@ public class LevelGenUtil {
|
|||
);
|
||||
}
|
||||
|
||||
public static WorldGenSettings replaceStem(
|
||||
ResourceKey<LevelStem> dimensionKey,
|
||||
WorldGenSettings worldGenSettings,
|
||||
LevelStem levelStem
|
||||
) {
|
||||
Registry<LevelStem> newDimensions = withDimension(
|
||||
dimensionKey,
|
||||
worldGenSettings.dimensions(),
|
||||
levelStem
|
||||
);
|
||||
return new WorldGenSettings(
|
||||
worldGenSettings.seed(),
|
||||
worldGenSettings.generateStructures(),
|
||||
worldGenSettings.generateBonusChest(),
|
||||
newDimensions
|
||||
);
|
||||
}
|
||||
// public static WorldGenSettings replaceStem(
|
||||
// ResourceKey<LevelStem> dimensionKey,
|
||||
// WorldGenSettings worldGenSettings,
|
||||
// LevelStem levelStem
|
||||
// ) {
|
||||
// Registry<LevelStem> newDimensions = withDimension(
|
||||
// dimensionKey,
|
||||
// worldGenSettings.dimensions(),
|
||||
// levelStem
|
||||
// );
|
||||
// return new WorldGenSettings(
|
||||
// worldGenSettings.seed(),
|
||||
// worldGenSettings.generateStructures(),
|
||||
// worldGenSettings.generateBonusChest(),
|
||||
// newDimensions
|
||||
// );
|
||||
// }
|
||||
|
||||
public static Registry<LevelStem> withDimension(
|
||||
ResourceKey<LevelStem> dimensionKey,
|
||||
|
@ -211,11 +210,11 @@ public class LevelGenUtil {
|
|||
return referenceSettings.dimensions().getHolder(dimensionKey);
|
||||
}
|
||||
|
||||
public static int getBiomeVersionForCurrentWorld(ResourceKey<LevelStem> key) {
|
||||
final CompoundTag settingsNbt = WorldGenUtil.getSettingsNbt();
|
||||
if (!settingsNbt.contains(key.location().toString())) return BCLBiomeSource.DEFAULT_BIOME_SOURCE_VERSION;
|
||||
return settingsNbt.getInt(key.location().toString());
|
||||
}
|
||||
// public static int getBiomeVersionForCurrentWorld(ResourceKey<LevelStem> key) {
|
||||
// final CompoundTag settingsNbt = WorldGenUtil.getSettingsNbt();
|
||||
// if (!settingsNbt.contains(key.location().toString())) return BCLBiomeSource.DEFAULT_BIOME_SOURCE_VERSION;
|
||||
// return settingsNbt.getInt(key.location().toString());
|
||||
// }
|
||||
|
||||
// private static int getDimensionVersion(
|
||||
// WorldGenSettings settings,
|
||||
|
@ -242,7 +241,7 @@ public class LevelGenUtil {
|
|||
|
||||
if (settingsNbt.size() == 0) {
|
||||
BCLib.LOGGER.info("Found World without generator Settings. Setting up data...");
|
||||
int biomeSourceVersion = BCLBiomeSource.DEFAULT_BIOME_SOURCE_VERSION;
|
||||
ResourceKey<WorldPreset> biomeSourceVersion = PresetsRegistry.BCL_WORLD;
|
||||
|
||||
final CompoundTag bclRoot = WorldConfig.getRootTag(BCLib.MOD_ID);
|
||||
|
||||
|
@ -254,32 +253,32 @@ public class LevelGenUtil {
|
|||
|
||||
if (isPre18) {
|
||||
BCLib.LOGGER.info("World was create pre 1.18!");
|
||||
biomeSourceVersion = BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE;
|
||||
biomeSourceVersion = PresetsRegistry.BCL_WORLD_17;
|
||||
}
|
||||
|
||||
if (WorldConfig.hasMod("betternether")) {
|
||||
BCLib.LOGGER.info("Found Data from BetterNether, using for migration.");
|
||||
final CompoundTag bnRoot = WorldConfig.getRootTag("betternether");
|
||||
biomeSourceVersion = "1.17".equals(bnRoot.getString(TAG_BN_GEN_VERSION))
|
||||
? BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE
|
||||
: BCLBiomeSource.BIOME_SOURCE_VERSION_HEX;
|
||||
? PresetsRegistry.BCL_WORLD_17
|
||||
: PresetsRegistry.BCL_WORLD;
|
||||
}
|
||||
|
||||
BCLib.LOGGER.info("Set world to BiomeSource Version " + biomeSourceVersion);
|
||||
TogetherWorldPreset.writeWorldPresetSettings(new BCLWorldPresetSettings(
|
||||
biomeSourceVersion,
|
||||
biomeSourceVersion,
|
||||
true,
|
||||
true
|
||||
));
|
||||
Registry<LevelStem> dimensions = TogetherWorldPreset.getDimensions(biomeSourceVersion);
|
||||
if (dimensions != null) {
|
||||
BCLib.LOGGER.info("Set world to BiomeSource Version " + biomeSourceVersion);
|
||||
TogetherWorldPreset.writeWorldPresetSettings(dimensions);
|
||||
} else {
|
||||
BCLib.LOGGER.error("Failed to set world to BiomeSource Version " + biomeSourceVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Replace by {@link WorldGenUtil#getWorldSettings()}
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static WorldPresetSettings getWorldSettings() {
|
||||
return WorldGenUtil.getWorldSettings();
|
||||
}
|
||||
// /**
|
||||
// * @deprecated Replace by {@link WorldGenUtil#getWorldSettings()}
|
||||
// */
|
||||
// @Deprecated(forRemoval = true)
|
||||
// public static WorldPresetSettings getWorldSettings() {
|
||||
// return null;
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package org.betterx.bclib.client.gui.screens;
|
||||
|
||||
import org.betterx.bclib.BCLib;
|
||||
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 org.betterx.bclib.api.v2.generator.config.BCLEndBiomeSourceConfig;
|
||||
import org.betterx.bclib.api.v2.generator.config.BCLNetherBiomeSourceConfig;
|
||||
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.presets.worldgen.BCLWorldPresetSettings;
|
||||
import org.betterx.bclib.registry.PresetsRegistry;
|
||||
import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
|
||||
import org.betterx.worlds.together.worldPreset.WorldGenSettingsComponentAccessor;
|
||||
|
||||
|
@ -15,13 +17,16 @@ import net.minecraft.core.Holder;
|
|||
import net.minecraft.network.chat.CommonComponents;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.dimension.BuiltinDimensionTypes;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.levelgen.presets.WorldPresets;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -46,24 +51,25 @@ public class WorldSetupScreen extends BCLibScreen {
|
|||
|
||||
@Override
|
||||
protected void initLayout() {
|
||||
final int netherVersion;
|
||||
final int endVersion;
|
||||
final boolean customEndGen;
|
||||
final boolean haveEndVoid;
|
||||
BCLEndBiomeSourceConfig endConfig = BCLEndBiomeSourceConfig.VANILLA;
|
||||
BCLNetherBiomeSourceConfig netherConfig = BCLNetherBiomeSourceConfig.VANILLA;
|
||||
if (createWorldScreen.worldGenSettingsComponent instanceof WorldGenSettingsComponentAccessor acc
|
||||
&& acc.bcl_getPreset()
|
||||
.isPresent() && acc.bcl_getPreset()
|
||||
.get()
|
||||
.value() instanceof TogetherWorldPreset wp
|
||||
&& wp.settings instanceof BCLWorldPresetSettings settings) {
|
||||
netherVersion = settings.netherVersion;
|
||||
endVersion = settings.endVersion;
|
||||
customEndGen = settings.useEndTerrainGenerator;
|
||||
haveEndVoid = settings.generateEndVoid;
|
||||
} else {
|
||||
throw new IllegalStateException("The WorldSetup Screen is only valid for BetterX Presets.");
|
||||
.value() instanceof TogetherWorldPreset wp) {
|
||||
|
||||
LevelStem endStem = wp.getDimension(LevelStem.END);
|
||||
if (endStem != null && endStem.generator().getBiomeSource() instanceof BCLibEndBiomeSource bs) {
|
||||
endConfig = bs.getTogetherConfig();
|
||||
}
|
||||
LevelStem netherStem = wp.getDimension(LevelStem.NETHER);
|
||||
if (netherStem != null && netherStem.generator().getBiomeSource() instanceof BCLibNetherBiomeSource bs) {
|
||||
netherConfig = bs.getTogetherConfig();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final int BUTTON_HEIGHT = 20;
|
||||
grid.addSpacerRow(20);
|
||||
|
||||
|
@ -82,7 +88,7 @@ public class WorldSetupScreen extends BCLibScreen {
|
|||
row.addSpacer(20);
|
||||
netherLegacy = row.addCheckbox(
|
||||
Component.translatable("title.screen.bclib.worldgen.legacy_square"),
|
||||
endVersion == BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE,
|
||||
netherConfig.mapVersion == BCLNetherBiomeSourceConfig.NetherBiomeMapType.SQUARE,
|
||||
1.0,
|
||||
GridLayout.GridValueType.PERCENTAGE,
|
||||
(state) -> {
|
||||
|
@ -91,7 +97,7 @@ public class WorldSetupScreen extends BCLibScreen {
|
|||
bclibNether = mainSettingsRow.addCheckbox(
|
||||
Component.translatable(
|
||||
"title.screen.bclib.worldgen.custom_biome_source"),
|
||||
netherVersion != BCLBiomeSource.BIOME_SOURCE_VERSION_VANILLA,
|
||||
netherConfig.mapVersion != BCLNetherBiomeSourceConfig.NetherBiomeMapType.VANILLA,
|
||||
1.0,
|
||||
GridLayout.GridValueType.PERCENTAGE,
|
||||
(state) -> {
|
||||
|
@ -111,7 +117,7 @@ public class WorldSetupScreen extends BCLibScreen {
|
|||
row.addSpacer(20);
|
||||
endCustomTerrain = row.addCheckbox(
|
||||
Component.translatable("title.screen.bclib.worldgen.custom_end_terrain"),
|
||||
customEndGen,
|
||||
endConfig.generatorVersion != BCLEndBiomeSourceConfig.EndBiomeGeneratorType.VANILLA,
|
||||
1.0,
|
||||
GridLayout.GridValueType.PERCENTAGE,
|
||||
(state) -> {
|
||||
|
@ -122,7 +128,7 @@ public class WorldSetupScreen extends BCLibScreen {
|
|||
row.addSpacer(20);
|
||||
generateEndVoid = row.addCheckbox(
|
||||
Component.translatable("title.screen.bclib.worldgen.end_void"),
|
||||
haveEndVoid,
|
||||
endConfig.withVoidBiomes,
|
||||
1.0,
|
||||
GridLayout.GridValueType.PERCENTAGE,
|
||||
(state) -> {
|
||||
|
@ -133,7 +139,7 @@ public class WorldSetupScreen extends BCLibScreen {
|
|||
row.addSpacer(20);
|
||||
endLegacy = row.addCheckbox(
|
||||
Component.translatable("title.screen.bclib.worldgen.legacy_square"),
|
||||
endVersion == BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE,
|
||||
endConfig.mapVersion == BCLEndBiomeSourceConfig.EndBiomeMapType.SQUARE,
|
||||
1.0,
|
||||
GridLayout.GridValueType.PERCENTAGE,
|
||||
(state) -> {
|
||||
|
@ -143,7 +149,7 @@ public class WorldSetupScreen extends BCLibScreen {
|
|||
bclibEnd = mainSettingsRow.addCheckbox(
|
||||
Component.translatable(
|
||||
"title.screen.bclib.worldgen.custom_biome_source"),
|
||||
endVersion != BCLBiomeSource.BIOME_SOURCE_VERSION_VANILLA,
|
||||
endConfig.mapVersion != BCLEndBiomeSourceConfig.EndBiomeMapType.VANILLA,
|
||||
1.0,
|
||||
GridLayout.GridValueType.PERCENTAGE,
|
||||
(state) -> {
|
||||
|
@ -165,20 +171,48 @@ public class WorldSetupScreen extends BCLibScreen {
|
|||
}
|
||||
|
||||
private void updateSettings() {
|
||||
int endVersion = BCLBiomeSource.DEFAULT_BIOME_SOURCE_VERSION;
|
||||
Map<ResourceKey<LevelStem>, ChunkGenerator> betterxDimensions = TogetherWorldPreset.getDimensionsMap(
|
||||
PresetsRegistry.BCL_WORLD);
|
||||
Map<ResourceKey<LevelStem>, ChunkGenerator> vanillaDimensions = TogetherWorldPreset.getDimensionsMap(
|
||||
WorldPresets.NORMAL);
|
||||
BCLEndBiomeSourceConfig.EndBiomeMapType endVersion = BCLEndBiomeSourceConfig.DEFAULT.mapVersion;
|
||||
|
||||
|
||||
if (bclibEnd.isChecked()) {
|
||||
if (endLegacy.isChecked()) endVersion = BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE;
|
||||
else endVersion = BCLBiomeSource.BIOME_SOURCE_VERSION_HEX;
|
||||
BCLEndBiomeSourceConfig endConfig = new BCLEndBiomeSourceConfig(
|
||||
endLegacy.isChecked()
|
||||
? BCLEndBiomeSourceConfig.EndBiomeMapType.SQUARE
|
||||
: BCLEndBiomeSourceConfig.EndBiomeMapType.HEX,
|
||||
endCustomTerrain.isChecked()
|
||||
? BCLEndBiomeSourceConfig.EndBiomeGeneratorType.PAULEVS
|
||||
: BCLEndBiomeSourceConfig.EndBiomeGeneratorType.VANILLA,
|
||||
generateEndVoid.isChecked(),
|
||||
BCLEndBiomeSourceConfig.DEFAULT.innerVoidRadiusSquared
|
||||
);
|
||||
|
||||
ChunkGenerator endGenerator = betterxDimensions.get(LevelStem.END);
|
||||
((BCLibEndBiomeSource) endGenerator.getBiomeSource()).setTogetherConfig(endConfig);
|
||||
|
||||
updateConfiguration(LevelStem.END, BuiltinDimensionTypes.END, endGenerator);
|
||||
} else {
|
||||
endVersion = BCLBiomeSource.BIOME_SOURCE_VERSION_VANILLA;
|
||||
ChunkGenerator endGenerator = vanillaDimensions.get(LevelStem.END);
|
||||
updateConfiguration(LevelStem.END, BuiltinDimensionTypes.END, endGenerator);
|
||||
}
|
||||
|
||||
int netherVersion = BCLBiomeSource.DEFAULT_BIOME_SOURCE_VERSION;
|
||||
if (bclibNether.isChecked()) {
|
||||
if (netherLegacy.isChecked()) netherVersion = BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE;
|
||||
else netherVersion = BCLBiomeSource.BIOME_SOURCE_VERSION_HEX;
|
||||
BCLNetherBiomeSourceConfig netherConfig = new BCLNetherBiomeSourceConfig(
|
||||
netherLegacy.isChecked()
|
||||
? BCLNetherBiomeSourceConfig.NetherBiomeMapType.SQUARE
|
||||
: BCLNetherBiomeSourceConfig.NetherBiomeMapType.HEX
|
||||
);
|
||||
|
||||
ChunkGenerator netherGenerator = betterxDimensions.get(LevelStem.NETHER);
|
||||
((BCLibNetherBiomeSource) netherGenerator.getBiomeSource()).setTogetherConfig(netherConfig);
|
||||
|
||||
updateConfiguration(LevelStem.NETHER, BuiltinDimensionTypes.NETHER, netherGenerator);
|
||||
} else {
|
||||
netherVersion = BCLBiomeSource.BIOME_SOURCE_VERSION_VANILLA;
|
||||
ChunkGenerator endGenerator = vanillaDimensions.get(LevelStem.NETHER);
|
||||
updateConfiguration(LevelStem.NETHER, BuiltinDimensionTypes.NETHER, endGenerator);
|
||||
}
|
||||
|
||||
if (createWorldScreen.worldGenSettingsComponent instanceof WorldGenSettingsComponentAccessor acc
|
||||
|
@ -186,34 +220,31 @@ public class WorldSetupScreen extends BCLibScreen {
|
|||
.isPresent() && acc.bcl_getPreset()
|
||||
.get()
|
||||
.value() instanceof TogetherWorldPreset worldPreset) {
|
||||
acc.bcl_setPreset(Optional.of(Holder.direct(worldPreset.withSettings(new BCLWorldPresetSettings(
|
||||
netherVersion,
|
||||
endVersion,
|
||||
endCustomTerrain.isChecked(),
|
||||
generateEndVoid.isChecked()
|
||||
)))));
|
||||
acc.bcl_setPreset(Optional.of(Holder.direct(
|
||||
worldPreset.withDimensions(
|
||||
createWorldScreen
|
||||
.worldGenSettingsComponent
|
||||
.settings()
|
||||
.worldGenSettings()
|
||||
.dimensions()
|
||||
)
|
||||
)));
|
||||
}
|
||||
|
||||
BCLib.LOGGER.info("Custom World Versions: end=" + endVersion + ", nether=" + netherVersion);
|
||||
updateConfiguration(LevelStem.END, BuiltinDimensionTypes.END, endVersion);
|
||||
updateConfiguration(LevelStem.NETHER, BuiltinDimensionTypes.NETHER, netherVersion);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void updateConfiguration(
|
||||
ResourceKey<LevelStem> dimensionKey,
|
||||
ResourceKey<DimensionType> dimensionTypeKey,
|
||||
int biomeSourceVersion
|
||||
ChunkGenerator chunkGenerator
|
||||
) {
|
||||
createWorldScreen.worldGenSettingsComponent.updateSettings(
|
||||
(registryAccess, worldGenSettings) -> LevelGenUtil.replaceGenerator(
|
||||
dimensionKey,
|
||||
dimensionTypeKey,
|
||||
biomeSourceVersion,
|
||||
registryAccess,
|
||||
worldGenSettings
|
||||
worldGenSettings,
|
||||
chunkGenerator
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,6 @@ public class DedicatedServerPropertiesMixin {
|
|||
//Make sure the default server properties use our Default World Preset
|
||||
@ModifyArg(method = "<init>", index = 3, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/dedicated/DedicatedServerProperties$WorldGenProperties;<init>(Ljava/lang/String;Lcom/google/gson/JsonObject;ZLjava/lang/String;)V"))
|
||||
private String bcl_init(String levelType) {
|
||||
return WorldPresets.DEFAULT.orElseThrow().location().toString();
|
||||
return WorldPresets.DEFAULT.location().toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,238 +0,0 @@
|
|||
package org.betterx.bclib.presets.worldgen;
|
||||
|
||||
import org.betterx.bclib.api.v2.generator.BCLBiomeSource;
|
||||
import org.betterx.bclib.api.v2.generator.BCLibEndBiomeSource;
|
||||
import org.betterx.bclib.api.v2.generator.config.BCLEndBiomeSourceConfig;
|
||||
import org.betterx.bclib.api.v2.generator.config.BCLNetherBiomeSourceConfig;
|
||||
import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
|
||||
import org.betterx.worlds.together.levelgen.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;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.levelgen.WorldGenSettings;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class BCLWorldPresetSettings extends WorldPresetSettings {
|
||||
public final static BCLWorldPresetSettings DEFAULT = new BCLWorldPresetSettings(BCLBiomeSource.DEFAULT_BIOME_SOURCE_VERSION);
|
||||
|
||||
public static final Codec<BCLWorldPresetSettings> CODEC = RecordCodecBuilder
|
||||
.create((RecordCodecBuilder.Instance<BCLWorldPresetSettings> builderInstance) -> builderInstance.group(
|
||||
Codec.INT
|
||||
.fieldOf(LevelStem.NETHER.location().toString())
|
||||
.forGetter(o -> o.netherVersion),
|
||||
Codec.INT
|
||||
.fieldOf(LevelStem.END.location().toString())
|
||||
.forGetter(o -> o.endVersion),
|
||||
Codec.BOOL
|
||||
.fieldOf("custom_end_terrain")
|
||||
.orElse(true)
|
||||
.forGetter(o -> o.useEndTerrainGenerator),
|
||||
Codec.BOOL
|
||||
.fieldOf("generate_end_void")
|
||||
.orElse(false)
|
||||
.forGetter(o -> o.generateEndVoid)
|
||||
)
|
||||
.apply(
|
||||
builderInstance,
|
||||
builderInstance.stable(
|
||||
BCLWorldPresetSettings::new)
|
||||
));
|
||||
public final int netherVersion;
|
||||
public final int endVersion;
|
||||
public final boolean useEndTerrainGenerator;
|
||||
public final boolean generateEndVoid;
|
||||
|
||||
public BCLWorldPresetSettings(int version) {
|
||||
this(version, version, true, false);
|
||||
}
|
||||
|
||||
public BCLWorldPresetSettings(
|
||||
int netherVersion,
|
||||
int endVersion,
|
||||
boolean useEndTerrainGenerator,
|
||||
boolean generateEndVoid
|
||||
) {
|
||||
this.netherVersion = netherVersion;
|
||||
this.endVersion = endVersion;
|
||||
this.useEndTerrainGenerator = endVersion != BCLibEndBiomeSource.BIOME_SOURCE_VERSION_VANILLA && useEndTerrainGenerator;
|
||||
this.generateEndVoid = generateEndVoid;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Codec<? extends WorldPresetSettings> codec() {
|
||||
return CODEC;
|
||||
}
|
||||
|
||||
public TogetherWorldPreset buildPreset(
|
||||
LevelStem overworldStem,
|
||||
WorldGenUtil.Context netherContext,
|
||||
WorldGenUtil.Context endContext
|
||||
) {
|
||||
return new TogetherWorldPreset(buildDimensionMap(overworldStem, netherContext, endContext), 1000, this);
|
||||
}
|
||||
|
||||
private static BCLEndBiomeSourceConfig getEndConfigForVersion(int version) {
|
||||
if (version == BCLBiomeSource.BIOME_SOURCE_VERSION_HEX)
|
||||
return BCLEndBiomeSourceConfig.MINECRAFT_18;
|
||||
if (version == BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE)
|
||||
return BCLEndBiomeSourceConfig.MINECRAFT_17;
|
||||
|
||||
return BCLEndBiomeSourceConfig.DEFAULT;
|
||||
}
|
||||
|
||||
private static BCLNetherBiomeSourceConfig getNetherConfigForVersion(int version) {
|
||||
if (version == BCLBiomeSource.BIOME_SOURCE_VERSION_HEX)
|
||||
return BCLNetherBiomeSourceConfig.MINECRAFT_18;
|
||||
if (version == BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE)
|
||||
return BCLNetherBiomeSourceConfig.MINECRAFT_17;
|
||||
|
||||
return BCLNetherBiomeSourceConfig.DEFAULT;
|
||||
}
|
||||
|
||||
public Map<ResourceKey<LevelStem>, LevelStem> buildDimensionMap(
|
||||
LevelStem overworldStem,
|
||||
WorldGenUtil.Context netherContext,
|
||||
WorldGenUtil.Context endContext
|
||||
) {
|
||||
return Map.of(
|
||||
LevelStem.OVERWORLD,
|
||||
overworldStem,
|
||||
LevelStem.NETHER,
|
||||
LevelGenUtil.getBCLNetherLevelStem(netherContext, getNetherConfigForVersion(netherVersion)),
|
||||
LevelStem.END,
|
||||
LevelGenUtil.getBCLEndLevelStem(endContext, getEndConfigForVersion(endVersion))
|
||||
);
|
||||
}
|
||||
|
||||
// public int getVersion(ResourceKey<LevelStem> key) {
|
||||
// if (key == LevelStem.NETHER) return netherVersion;
|
||||
// if (key == LevelStem.END) return endVersion;
|
||||
//
|
||||
// return BCLBiomeSource.BIOME_SOURCE_VERSION_VANILLA;
|
||||
// }
|
||||
|
||||
|
||||
public BiomeSource addDatapackBiomes(BiomeSource biomeSource, Set<Holder<Biome>> datapackBiomes) {
|
||||
if (biomeSource instanceof BCLBiomeSource bs) {
|
||||
return bs.createCopyForDatapack(datapackBiomes);
|
||||
}
|
||||
return biomeSource;
|
||||
}
|
||||
|
||||
|
||||
// private static Holder<NoiseGeneratorSettings> buildGeneratorSettings(
|
||||
// Holder<NoiseGeneratorSettings> reference,
|
||||
// Holder<NoiseGeneratorSettings> settings,
|
||||
// BiomeSource biomeSource
|
||||
// ) {
|
||||
// //SurfaceRuleUtil.injectSurfaceRules(settings.value(), biomeSource);
|
||||
// return settings;
|
||||
//// NoiseGeneratorSettings old = settings.value();
|
||||
//// NoiseGeneratorSettings noise = new NoiseGeneratorSettings(
|
||||
//// old.noiseSettings(),
|
||||
//// old.defaultBlock(),
|
||||
//// old.defaultFluid(),
|
||||
//// old.noiseRouter(),
|
||||
//// SurfaceRuleRegistry.mergeSurfaceRulesFromBiomes(old.surfaceRule(), biomeSource),
|
||||
//// //SurfaceRuleUtil.addRulesForBiomeSource(old.surfaceRule(), biomeSource),
|
||||
//// old.spawnTarget(),
|
||||
//// old.seaLevel(),
|
||||
//// old.disableMobGeneration(),
|
||||
//// old.aquifersEnabled(),
|
||||
//// old.oreVeinsEnabled(),
|
||||
//// old.useLegacyRandomSource()
|
||||
//// );
|
||||
////
|
||||
////
|
||||
//// return Holder.direct(noise);
|
||||
// }
|
||||
|
||||
|
||||
// /**
|
||||
// * Datapacks can change the world's generator. This Method will ensure, that the Generators contain
|
||||
// * the correct BiomeSources for this world
|
||||
// *
|
||||
// * @param dimensionKey
|
||||
// * @param dimensionTypeKey
|
||||
// * @param settings
|
||||
// * @return
|
||||
// */
|
||||
// private WorldGenSettings fixSettingsInCurrentWorld(
|
||||
// RegistryAccess access, ResourceKey<LevelStem> dimensionKey,
|
||||
// ResourceKey<DimensionType> dimensionTypeKey,
|
||||
// WorldGenSettings settings
|
||||
// ) {
|
||||
// Optional<Holder<LevelStem>> loadedStem = settings.dimensions().getHolder(dimensionKey);
|
||||
// final ChunkGenerator loadedChunkGenerator = loadedStem.map(h -> h.value().generator()).orElse(null);
|
||||
// final int loaderVersion = LevelGenUtil.getBiomeVersionForGenerator(loadedStem
|
||||
// .map(h -> h.value().generator())
|
||||
// .orElse(null));
|
||||
//
|
||||
// final int targetVersion = getVersion(dimensionKey);
|
||||
// if (loaderVersion != targetVersion) {
|
||||
// BCLib.LOGGER.info("Enforcing Correct Generator for " + dimensionKey.location().toString() + ".");
|
||||
//
|
||||
// Optional<Holder<LevelStem>> refLevelStem = LevelGenUtil.referenceStemForVersion(
|
||||
// dimensionKey,
|
||||
// targetVersion,
|
||||
// access,
|
||||
// settings.seed(),
|
||||
// settings.generateStructures(),
|
||||
// settings.generateBonusChest()
|
||||
// );
|
||||
//
|
||||
// ChunkGenerator referenceGenerator = refLevelStem.map(h -> h.value().generator()).orElse(null);
|
||||
// if (referenceGenerator == null) {
|
||||
// BCLib.LOGGER.error("Failed to create Generator for " + dimensionKey.location().toString());
|
||||
// return settings;
|
||||
// }
|
||||
//
|
||||
// if (loadedChunkGenerator instanceof ChunkGeneratorAccessor generator) {
|
||||
// if (loadedChunkGenerator instanceof NoiseGeneratorSettingsProvider noiseProvider) {
|
||||
// if (referenceGenerator instanceof NoiseGeneratorSettingsProvider referenceProvider) {
|
||||
// final Set<Holder<Biome>> biomes = loadedChunkGenerator.getBiomeSource().possibleBiomes();
|
||||
// final BiomeSource bs = addDatapackBiomes(referenceGenerator.getBiomeSource(), biomes);
|
||||
// InternalBiomeAPI.applyModifications(bs, dimensionKey);
|
||||
// referenceGenerator = new BCLChunkGenerator(
|
||||
// generator.bclib_getStructureSetsRegistry(),
|
||||
// noiseProvider.bclib_getNoises(),
|
||||
// bs,
|
||||
// buildGeneratorSettings(
|
||||
// referenceProvider.bclib_getNoiseGeneratorSettingHolders(),
|
||||
// noiseProvider.bclib_getNoiseGeneratorSettingHolders(),
|
||||
// bs
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return LevelGenUtil.replaceGenerator(
|
||||
// dimensionKey,
|
||||
// dimensionTypeKey,
|
||||
// access,
|
||||
// settings,
|
||||
// referenceGenerator
|
||||
// );
|
||||
// }
|
||||
// return settings;
|
||||
// }
|
||||
|
||||
public WorldGenSettings repairSettingsOnLoad(RegistryAccess registryAccess, WorldGenSettings settings) {
|
||||
// settings = fixSettingsInCurrentWorld(registryAccess, LevelStem.NETHER, BuiltinDimensionTypes.NETHER, settings);
|
||||
// settings = fixSettingsInCurrentWorld(registryAccess, LevelStem.END, BuiltinDimensionTypes.END, settings);
|
||||
return settings;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,15 +1,18 @@
|
|||
package org.betterx.bclib.registry;
|
||||
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.api.v2.generator.BCLBiomeSource;
|
||||
import org.betterx.bclib.presets.worldgen.BCLWorldPresetSettings;
|
||||
import org.betterx.bclib.api.v2.generator.config.BCLEndBiomeSourceConfig;
|
||||
import org.betterx.bclib.api.v2.generator.config.BCLNetherBiomeSourceConfig;
|
||||
import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
|
||||
import org.betterx.worlds.together.levelgen.WorldGenUtil;
|
||||
import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
|
||||
import org.betterx.worlds.together.worldPreset.WorldPresets;
|
||||
import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
|
||||
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Map;
|
||||
|
||||
public class PresetsRegistry {
|
||||
public static ResourceKey<WorldPreset> BCL_WORLD;
|
||||
|
@ -18,12 +21,13 @@ public class PresetsRegistry {
|
|||
public static void onLoad() {
|
||||
BCL_WORLD =
|
||||
WorldPresets.register(
|
||||
BCLib.makeID("hex_map"),
|
||||
BCLib.makeID("normal"),
|
||||
(overworldStem, netherContext, endContext) ->
|
||||
new BCLWorldPresetSettings(BCLBiomeSource.BIOME_SOURCE_VERSION_HEX).buildPreset(
|
||||
buildPreset(
|
||||
overworldStem,
|
||||
netherContext,
|
||||
endContext
|
||||
BCLNetherBiomeSourceConfig.DEFAULT, endContext,
|
||||
BCLEndBiomeSourceConfig.DEFAULT
|
||||
),
|
||||
true
|
||||
);
|
||||
|
@ -31,18 +35,47 @@ public class PresetsRegistry {
|
|||
BCL_WORLD_17 = WorldPresets.register(
|
||||
BCLib.makeID("legacy_17"),
|
||||
(overworldStem, netherContext, endContext) ->
|
||||
new BCLWorldPresetSettings(BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE).buildPreset(
|
||||
buildPreset(
|
||||
overworldStem,
|
||||
netherContext,
|
||||
endContext
|
||||
BCLNetherBiomeSourceConfig.MINECRAFT_17, endContext,
|
||||
BCLEndBiomeSourceConfig.MINECRAFT_17
|
||||
),
|
||||
false
|
||||
);
|
||||
|
||||
WorldPresetSettings.DEFAULT = BCLWorldPresetSettings.DEFAULT;
|
||||
WorldPresets.DEFAULT = Optional.of(BCL_WORLD);
|
||||
|
||||
WorldPresetSettings.register(BCLib.makeID("bcl_world_preset_settings"), BCLWorldPresetSettings.CODEC);
|
||||
WorldPresets.DEFAULT = BCL_WORLD;
|
||||
}
|
||||
|
||||
public static TogetherWorldPreset buildPreset(
|
||||
LevelStem overworldStem,
|
||||
WorldGenUtil.Context netherContext,
|
||||
BCLNetherBiomeSourceConfig netherConfig,
|
||||
WorldGenUtil.Context endContext,
|
||||
BCLEndBiomeSourceConfig endConfig
|
||||
) {
|
||||
return new TogetherWorldPreset(buildDimensionMap(
|
||||
overworldStem,
|
||||
netherContext,
|
||||
netherConfig, endContext,
|
||||
endConfig
|
||||
), 1000);
|
||||
}
|
||||
|
||||
public static Map<ResourceKey<LevelStem>, LevelStem> buildDimensionMap(
|
||||
LevelStem overworldStem,
|
||||
WorldGenUtil.Context netherContext,
|
||||
BCLNetherBiomeSourceConfig netherConfig,
|
||||
WorldGenUtil.Context endContext,
|
||||
BCLEndBiomeSourceConfig endConfig
|
||||
) {
|
||||
return Map.of(
|
||||
LevelStem.OVERWORLD,
|
||||
overworldStem,
|
||||
LevelStem.NETHER,
|
||||
LevelGenUtil.getBCLNetherLevelStem(netherContext, netherConfig),
|
||||
LevelStem.END,
|
||||
LevelGenUtil.getBCLEndLevelStem(endContext, endConfig)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,18 +7,12 @@ import org.betterx.worlds.together.world.BiomeSourceWithSeed;
|
|||
import org.betterx.worlds.together.world.WorldConfig;
|
||||
import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
|
||||
import org.betterx.worlds.together.worldPreset.WorldPresets;
|
||||
import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Dynamic;
|
||||
import net.minecraft.core.Holder;
|
||||
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;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
|
@ -31,8 +25,6 @@ import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
|||
import net.minecraft.world.level.levelgen.structure.StructureSet;
|
||||
import net.minecraft.world.level.levelgen.synth.NormalNoise;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class WorldGenUtil {
|
||||
public static final String TAG_GENERATOR = "generator";
|
||||
|
||||
|
@ -65,7 +57,7 @@ public class WorldGenUtil {
|
|||
boolean generateBonusChest
|
||||
) {
|
||||
return createWorldFromPreset(
|
||||
WorldPresets.DEFAULT.orElseThrow(),
|
||||
WorldPresets.DEFAULT,
|
||||
registryAccess,
|
||||
seed,
|
||||
generateStructures,
|
||||
|
@ -90,22 +82,12 @@ public class WorldGenUtil {
|
|||
return WorldConfig.getCompoundTag(WorldsTogether.MOD_ID, TAG_GENERATOR);
|
||||
}
|
||||
|
||||
public static WorldPresetSettings getWorldSettings() {
|
||||
final RegistryAccess registryAccess = BuiltinRegistries.ACCESS;
|
||||
final RegistryOps<Tag> registryOps = RegistryOps.create(NbtOps.INSTANCE, registryAccess);
|
||||
|
||||
Optional<WorldPresetSettings> oLevelStem = WorldPresetSettings.CODEC
|
||||
.parse(new Dynamic<>(registryOps, getSettingsNbt()))
|
||||
.resultOrPartial(WorldsTogether.LOGGER::error);
|
||||
|
||||
return oLevelStem.orElse(WorldPresetSettings.DEFAULT);
|
||||
}
|
||||
|
||||
public static class Context extends StemContext {
|
||||
public final Registry<Biome> biomes;
|
||||
|
||||
public Context(
|
||||
Registry<Biome> biomes, Holder<DimensionType> dimension,
|
||||
Registry<Biome> biomes,
|
||||
Holder<DimensionType> dimension,
|
||||
Registry<StructureSet> structureSets,
|
||||
Registry<NormalNoise.NoiseParameters> noiseParameters,
|
||||
Holder<NoiseGeneratorSettings> generatorSettings
|
||||
|
|
|
@ -46,7 +46,7 @@ public class CreateWorldScreenMixin {
|
|||
//Change the WorldPreset that is selected by default on the Create World Screen
|
||||
@ModifyArg(method = "openFresh", index = 1, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/worldselection/WorldGenSettingsComponent;<init>(Lnet/minecraft/client/gui/screens/worldselection/WorldCreationContext;Ljava/util/Optional;Ljava/util/OptionalLong;)V"))
|
||||
private static Optional<ResourceKey<WorldPreset>> bcl_NewDefault(Optional<ResourceKey<WorldPreset>> preset) {
|
||||
return WorldPresets.DEFAULT;
|
||||
return Optional.of(WorldPresets.DEFAULT);
|
||||
}
|
||||
|
||||
//Make sure the WorldGenSettings used to populate the create screen match the default WorldPreset
|
||||
|
|
|
@ -20,6 +20,6 @@ public class WorldGenPropertiesMixin {
|
|||
//Make sure Servers use our Default World Preset
|
||||
@ModifyArg(method = "create", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/core/Registry;getHolder(Lnet/minecraft/resources/ResourceKey;)Ljava/util/Optional;"))
|
||||
private ResourceKey<WorldPreset> bcl_foo(ResourceKey<WorldPreset> resourceKey) {
|
||||
return WorldPresets.DEFAULT.orElseThrow();
|
||||
return WorldPresets.DEFAULT;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package org.betterx.worlds.together.mixin.common;
|
||||
|
||||
import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
|
||||
import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
|
||||
|
||||
import com.mojang.datafixers.kinds.App;
|
||||
import com.mojang.serialization.Codec;
|
||||
|
@ -44,14 +43,8 @@ public class WorldPresetMixin {
|
|||
? Optional.of(((TogetherWorldPreset) wp).sortOrder)
|
||||
: Optional.empty());
|
||||
|
||||
RecordCodecBuilder<WorldPreset, Optional<WorldPresetSettings>> settingsBuilder = WorldPresetSettings.CODEC
|
||||
.optionalFieldOf("settings")
|
||||
.forGetter(wp -> (wp instanceof TogetherWorldPreset)
|
||||
? Optional.of(((TogetherWorldPreset) wp).settings)
|
||||
: Optional.empty());
|
||||
|
||||
return builderInstance
|
||||
.group(dimensionsBuilder, sortBuilder, settingsBuilder)
|
||||
.group(dimensionsBuilder, sortBuilder)
|
||||
.apply(builderInstance, TogetherWorldPreset::new);
|
||||
};
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.betterx.worlds.together.mixin.common;
|
|||
|
||||
import org.betterx.worlds.together.levelgen.WorldGenUtil;
|
||||
import org.betterx.worlds.together.worldPreset.WorldPresets;
|
||||
import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
|
@ -51,7 +50,6 @@ public abstract class WorldPresetsBootstrapMixin {
|
|||
|
||||
@ModifyArg(method = "run", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/level/levelgen/presets/WorldPresets$Bootstrap;registerCustomOverworldPreset(Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/world/level/dimension/LevelStem;)Lnet/minecraft/core/Holder;"))
|
||||
private LevelStem bcl_getOverworldStem(LevelStem overworldStem) {
|
||||
WorldPresetSettings.bootstrap();
|
||||
WorldGenUtil.Context netherContext = new WorldGenUtil.Context(
|
||||
this.biomes,
|
||||
this.netherDimensionType,
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
package org.betterx.worlds.together.world.event;
|
||||
|
||||
import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
|
||||
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface BeforeServerWorldLoad {
|
||||
void prepareWorld(
|
||||
LevelStorageSource.LevelStorageAccess storageAccess,
|
||||
WorldPresetSettings settings,
|
||||
Map<ResourceKey<LevelStem>, ChunkGenerator> dimension,
|
||||
boolean isNewWorld
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
package org.betterx.worlds.together.world.event;
|
||||
|
||||
import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
|
||||
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface BeforeWorldLoad {
|
||||
void prepareWorld(
|
||||
LevelStorageSource.LevelStorageAccess storageAccess,
|
||||
WorldPresetSettings settings,
|
||||
Map<ResourceKey<LevelStem>, ChunkGenerator> settings,
|
||||
boolean isNewWorld
|
||||
);
|
||||
}
|
||||
|
|
|
@ -9,21 +9,24 @@ import org.betterx.worlds.together.world.WorldConfig;
|
|||
import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
|
||||
import org.betterx.worlds.together.worldPreset.WorldGenSettingsComponentAccessor;
|
||||
import org.betterx.worlds.together.worldPreset.WorldPresets;
|
||||
import org.betterx.worlds.together.worldPreset.settings.VanillaWorldPresetSettings;
|
||||
import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
|
||||
|
||||
import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
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.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
@ -36,6 +39,11 @@ public class WorldBootstrap {
|
|||
return LAST_REGISTRY_ACCESS;
|
||||
}
|
||||
|
||||
public static RegistryAccess getLastRegistryAccessOrElseBuiltin() {
|
||||
if (LAST_REGISTRY_ACCESS == null) return BuiltinRegistries.ACCESS;
|
||||
return LAST_REGISTRY_ACCESS;
|
||||
}
|
||||
|
||||
public static class Helpers {
|
||||
private static void initializeWorldConfig(
|
||||
LevelStorageSource.LevelStorageAccess levelStorageAccess,
|
||||
|
@ -63,31 +71,34 @@ public class WorldBootstrap {
|
|||
private static Holder<WorldPreset> defaultServerPreset() {
|
||||
return WorldPresets.get(
|
||||
LAST_REGISTRY_ACCESS,
|
||||
WorldPresets.DEFAULT.orElseThrow()
|
||||
WorldPresets.DEFAULT
|
||||
);
|
||||
}
|
||||
|
||||
private static WorldPresetSettings defaultServerSettings() {
|
||||
private static Map<ResourceKey<LevelStem>, ChunkGenerator> defaultServerDimensions() {
|
||||
final Holder<WorldPreset> defaultPreset = defaultServerPreset();
|
||||
return defaultServerSettings(defaultPreset);
|
||||
return defaultServerDimensions(defaultPreset);
|
||||
}
|
||||
|
||||
private static WorldPresetSettings defaultServerSettings(Holder<WorldPreset> defaultPreset) {
|
||||
final WorldPresetSettings settings;
|
||||
private static Map<ResourceKey<LevelStem>, ChunkGenerator> defaultServerDimensions(Holder<WorldPreset> defaultPreset) {
|
||||
final Map<ResourceKey<LevelStem>, ChunkGenerator> dimensions;
|
||||
if (defaultPreset.value() instanceof TogetherWorldPreset t) {
|
||||
settings = t.settings;
|
||||
dimensions = t.getDimensionsMap();
|
||||
} else {
|
||||
settings = VanillaWorldPresetSettings.DEFAULT;
|
||||
dimensions = TogetherWorldPreset.getDimensionsMap(net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL);
|
||||
}
|
||||
return settings;
|
||||
return dimensions;
|
||||
}
|
||||
|
||||
private static Optional<Holder<WorldPreset>> presetFromDatapack(Optional<Holder<WorldPreset>> currentPreset) {
|
||||
if (currentPreset.isPresent() && LAST_REGISTRY_ACCESS != null) {
|
||||
Optional<Holder<WorldPreset>> newPreset = LAST_REGISTRY_ACCESS
|
||||
.registryOrThrow(Registry.WORLD_PRESET_REGISTRY)
|
||||
.getHolder(currentPreset.map(h -> h.unwrapKey()).map(h -> h.orElseThrow()).orElseThrow());
|
||||
if (newPreset.isPresent()) currentPreset = newPreset;
|
||||
var presetKey = currentPreset.get().unwrapKey();
|
||||
if (presetKey.isPresent()) {
|
||||
Optional<Holder<WorldPreset>> newPreset = LAST_REGISTRY_ACCESS
|
||||
.registryOrThrow(Registry.WORLD_PRESET_REGISTRY)
|
||||
.getHolder(presetKey.get());
|
||||
if (newPreset.isPresent()) currentPreset = newPreset;
|
||||
}
|
||||
}
|
||||
return currentPreset;
|
||||
}
|
||||
|
@ -104,7 +115,7 @@ public class WorldBootstrap {
|
|||
File levelDat = levelStorageAccess.getLevelPath(LevelResource.LEVEL_DATA_FILE).toFile();
|
||||
if (!levelDat.exists()) {
|
||||
BCLib.LOGGER.info("Creating a new World, no fixes needed");
|
||||
final WorldPresetSettings settings = Helpers.defaultServerSettings();
|
||||
final Map<ResourceKey<LevelStem>, ChunkGenerator> settings = Helpers.defaultServerDimensions();
|
||||
|
||||
Helpers.initializeWorldConfig(levelStorageAccess, true);
|
||||
WorldEventsImpl.BEFORE_SERVER_WORLD_LOAD.emit(e -> e.prepareWorld(
|
||||
|
@ -114,7 +125,7 @@ public class WorldBootstrap {
|
|||
Helpers.initializeWorldConfig(levelStorageAccess, false);
|
||||
WorldEventsImpl.BEFORE_SERVER_WORLD_LOAD.emit(e -> e.prepareWorld(
|
||||
levelStorageAccess,
|
||||
WorldGenUtil.getWorldSettings(),
|
||||
TogetherWorldPreset.getWorldDimensions(),
|
||||
false
|
||||
));
|
||||
WorldEventsImpl.ON_WORLD_LOAD.emit(OnWorldLoad::onLoad);
|
||||
|
@ -124,18 +135,13 @@ public class WorldBootstrap {
|
|||
//Needs to get called after setupWorld
|
||||
public static void applyDatapackChangesOnNewWorld(WorldGenSettings worldGenSettings) {
|
||||
Optional<Holder<WorldPreset>> currentPreset = Optional.of(Helpers.defaultServerPreset());
|
||||
var settings = Helpers.defaultServerSettings(currentPreset.orElseThrow());
|
||||
|
||||
currentPreset = WorldEventsImpl.ADAPT_WORLD_PRESET.emit(currentPreset, worldGenSettings);
|
||||
if (currentPreset.map(h -> h.value()).orElse(null) instanceof TogetherWorldPreset t) {
|
||||
settings = t.settings;
|
||||
}
|
||||
TogetherWorldPreset.writeWorldPresetSettings(settings);
|
||||
if (currentPreset.map(h -> h.value()).orElse(null) instanceof WorldPresetAccessor acc) {
|
||||
|
||||
if (currentPreset.map(Holder::value).orElse(null) instanceof WorldPresetAccessor acc) {
|
||||
TogetherWorldPreset.writeWorldPresetSettings(acc.bcl_getDimensions());
|
||||
} else {
|
||||
WorldsTogether.LOGGER.error("Failed writing together File");
|
||||
//TogetherWorldPreset.writeWorldPresetSettings(worldGenSettings);
|
||||
TogetherWorldPreset.writeWorldPresetSettings(worldGenSettings.dimensions());
|
||||
}
|
||||
WorldEventsImpl.ON_WORLD_LOAD.emit(OnWorldLoad::onLoad);
|
||||
}
|
||||
|
@ -185,29 +191,28 @@ public class WorldBootstrap {
|
|||
Helpers.initializeWorldConfig(levelStorageAccess, true);
|
||||
|
||||
|
||||
final WorldPresetSettings settings;
|
||||
final Map<ResourceKey<LevelStem>, ChunkGenerator> dimensions;
|
||||
if (currentPreset.map(Holder::value).orElse(null) instanceof TogetherWorldPreset t) {
|
||||
settings = t.settings;
|
||||
dimensions = t.getDimensionsMap();
|
||||
} else {
|
||||
settings = VanillaWorldPresetSettings.DEFAULT;
|
||||
dimensions = TogetherWorldPreset.getDimensionsMap(net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL);
|
||||
}
|
||||
|
||||
// Helpers.setupWorld();
|
||||
// DataFixerAPI.initializePatchData();
|
||||
WorldEventsImpl.BEFORE_WORLD_LOAD.emit(e -> e.prepareWorld(
|
||||
levelStorageAccess,
|
||||
settings,
|
||||
dimensions,
|
||||
true
|
||||
));
|
||||
|
||||
currentPreset = WorldEventsImpl.ADAPT_WORLD_PRESET.emit(currentPreset, worldGenSettings);
|
||||
|
||||
TogetherWorldPreset.writeWorldPresetSettings(currentPreset);
|
||||
if (currentPreset.map(h -> h.value()).orElse(null) instanceof WorldPresetAccessor acc) {
|
||||
if (currentPreset.map(Holder::value).orElse(null) instanceof WorldPresetAccessor acc) {
|
||||
TogetherWorldPreset.writeWorldPresetSettings(acc.bcl_getDimensions());
|
||||
} else {
|
||||
WorldsTogether.LOGGER.error("Failed writing together File");
|
||||
//TogetherWorldPreset.writeWorldPresetSettings(worldGenSettings);
|
||||
TogetherWorldPreset.writeWorldPresetSettings(worldGenSettings.dimensions());
|
||||
}
|
||||
|
||||
//LifeCycleAPI._runBeforeLevelLoad();
|
||||
|
@ -230,7 +235,7 @@ public class WorldBootstrap {
|
|||
//Helpers.setupWorld();
|
||||
WorldEventsImpl.BEFORE_WORLD_LOAD.emit(e -> e.prepareWorld(
|
||||
levelStorageAccess,
|
||||
WorldGenUtil.getWorldSettings(),
|
||||
TogetherWorldPreset.getWorldDimensions(),
|
||||
false
|
||||
));
|
||||
levelStorageAccess.close();
|
||||
|
|
|
@ -5,8 +5,6 @@ import org.betterx.worlds.together.levelgen.WorldGenUtil;
|
|||
import org.betterx.worlds.together.mixin.common.WorldPresetAccessor;
|
||||
import org.betterx.worlds.together.world.WorldConfig;
|
||||
import org.betterx.worlds.together.world.event.WorldBootstrap;
|
||||
import org.betterx.worlds.together.worldPreset.settings.VanillaWorldPresetSettings;
|
||||
import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.Dynamic;
|
||||
|
@ -29,7 +27,6 @@ import java.util.Optional;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TogetherWorldPreset extends WorldPreset {
|
||||
public final WorldPresetSettings settings;
|
||||
public final int sortOrder;
|
||||
|
||||
private static final String TAG_GENERATOR = WorldGenUtil.TAG_GENERATOR;
|
||||
|
@ -38,41 +35,57 @@ public class TogetherWorldPreset extends WorldPreset {
|
|||
|
||||
public TogetherWorldPreset(
|
||||
Map<ResourceKey<LevelStem>, LevelStem> map,
|
||||
Optional<Integer> sortOrder,
|
||||
Optional<WorldPresetSettings> settings
|
||||
Optional<Integer> sortOrder
|
||||
) {
|
||||
this(map, sortOrder.orElse(NEXT_IN_SORT_ORDER++), settings.orElse(VanillaWorldPresetSettings.DEFAULT));
|
||||
this(map, sortOrder.orElse(NEXT_IN_SORT_ORDER++));
|
||||
}
|
||||
|
||||
public TogetherWorldPreset(
|
||||
Map<ResourceKey<LevelStem>, LevelStem> map,
|
||||
int sortOrder,
|
||||
WorldPresetSettings settings
|
||||
int sortOrder
|
||||
) {
|
||||
super(map);
|
||||
this.sortOrder = sortOrder;
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public TogetherWorldPreset withSettings(WorldPresetSettings settings) {
|
||||
return new TogetherWorldPreset(getDimensions(), sortOrder, settings);
|
||||
public TogetherWorldPreset withDimensions(Registry<LevelStem> dimensions) {
|
||||
Map<ResourceKey<LevelStem>, LevelStem> map = new HashMap<>();
|
||||
for (var entry : dimensions.entrySet()) {
|
||||
ResourceKey<LevelStem> key = entry.getKey();
|
||||
LevelStem stem = entry.getValue();
|
||||
map.put(key, stem);
|
||||
}
|
||||
return new TogetherWorldPreset(map, sortOrder);
|
||||
}
|
||||
|
||||
private Map<ResourceKey<LevelStem>, LevelStem> getDimensions() {
|
||||
return ((WorldPresetAccessor) this).bcl_getDimensions();
|
||||
}
|
||||
|
||||
public Map<ResourceKey<LevelStem>, ChunkGenerator> getDimensionsMap() {
|
||||
return DimensionsWrapper.build(getDimensions());
|
||||
}
|
||||
|
||||
public LevelStem getDimension(ResourceKey<LevelStem> key) {
|
||||
return getDimensions().get(key);
|
||||
}
|
||||
|
||||
public static void writeWorldPresetSettings(Registry<LevelStem> dimensions) {
|
||||
DimensionsWrapper wrapper = new DimensionsWrapper(dimensions);
|
||||
writeWorldPresetSettings(wrapper);
|
||||
}
|
||||
|
||||
public static void writeWorldPresetSettings(Map<ResourceKey<LevelStem>, LevelStem> settings) {
|
||||
DimensionsWrapper wrapper = new DimensionsWrapper(DimensionsWrapper.build(settings));
|
||||
writeWorldPresetSettings(wrapper);
|
||||
}
|
||||
|
||||
private static void writeWorldPresetSettings(DimensionsWrapper wrapper) {
|
||||
final RegistryOps<Tag> registryOps = RegistryOps.create(
|
||||
NbtOps.INSTANCE,
|
||||
WorldBootstrap.getLastRegistryAccess()
|
||||
);
|
||||
DimensionsWrapper wrapper = new DimensionsWrapper(DimensionsWrapper.build(settings));
|
||||
final var encodeResult = wrapper.CODEC.encodeStart(registryOps, wrapper);
|
||||
final var encodeResult = DimensionsWrapper.CODEC.encodeStart(registryOps, wrapper);
|
||||
|
||||
if (encodeResult.result().isPresent()) {
|
||||
final CompoundTag settingsNbt = WorldConfig.getRootTag(WorldsTogether.MOD_ID);
|
||||
|
@ -87,7 +100,6 @@ public class TogetherWorldPreset extends WorldPreset {
|
|||
private static DimensionsWrapper DEFAULT_DIMENSIONS_WRAPPER = null;
|
||||
|
||||
public static @NotNull Map<ResourceKey<LevelStem>, ChunkGenerator> getWorldDimensions() {
|
||||
if (BuiltinRegistries.ACCESS == null) return null;
|
||||
final RegistryAccess registryAccess;
|
||||
if (WorldBootstrap.getLastRegistryAccess() != null) {
|
||||
registryAccess = WorldBootstrap.getLastRegistryAccess();
|
||||
|
@ -104,7 +116,7 @@ public class TogetherWorldPreset extends WorldPreset {
|
|||
DEFAULT_DIMENSIONS_WRAPPER = new DimensionsWrapper(WorldPresets
|
||||
.get(
|
||||
registryAccess,
|
||||
WorldPresets.DEFAULT.orElseThrow()
|
||||
WorldPresets.DEFAULT
|
||||
)
|
||||
.value()
|
||||
.createWorldGenSettings(0, true, true)
|
||||
|
@ -114,6 +126,27 @@ public class TogetherWorldPreset extends WorldPreset {
|
|||
return oLevelStem.orElse(DEFAULT_DIMENSIONS_WRAPPER).dimensions;
|
||||
}
|
||||
|
||||
public static Registry<LevelStem> getDimensions(ResourceKey<WorldPreset> key) {
|
||||
RegistryAccess access = WorldBootstrap.getLastRegistryAccessOrElseBuiltin();
|
||||
var preset = access.registryOrThrow(Registry.WORLD_PRESET_REGISTRY).getHolder(key);
|
||||
if (preset.isEmpty()) return null;
|
||||
return preset
|
||||
.get()
|
||||
.value()
|
||||
.createWorldGenSettings(
|
||||
0,
|
||||
true,
|
||||
true
|
||||
)
|
||||
.dimensions();
|
||||
}
|
||||
|
||||
public static @NotNull Map<ResourceKey<LevelStem>, ChunkGenerator> getDimensionsMap(ResourceKey<WorldPreset> key) {
|
||||
Registry<LevelStem> reg = getDimensions(key);
|
||||
if (reg == null) return new HashMap<>();
|
||||
return DimensionsWrapper.build(reg);
|
||||
}
|
||||
|
||||
private static class DimensionsWrapper {
|
||||
public static final Codec<DimensionsWrapper> CODEC = RecordCodecBuilder.create(instance -> instance
|
||||
.group(Codec.unboundedMap(
|
||||
|
@ -146,6 +179,7 @@ public class TogetherWorldPreset extends WorldPreset {
|
|||
return map;
|
||||
}
|
||||
|
||||
|
||||
DimensionsWrapper(Registry<LevelStem> dimensions) {
|
||||
this(build(dimensions));
|
||||
}
|
||||
|
|
|
@ -2,12 +2,10 @@ package org.betterx.worlds.together.worldPreset;
|
|||
|
||||
import org.betterx.bclib.registry.PresetsRegistry;
|
||||
import org.betterx.worlds.together.WorldsTogether;
|
||||
import org.betterx.worlds.together.levelgen.WorldGenUtil;
|
||||
import org.betterx.worlds.together.tag.v3.TagManager;
|
||||
import org.betterx.worlds.together.tag.v3.TagRegistry;
|
||||
import org.betterx.worlds.together.levelgen.WorldGenUtil;
|
||||
import org.betterx.worlds.together.worldPreset.client.WorldPresetsClient;
|
||||
import org.betterx.worlds.together.worldPreset.settings.VanillaWorldPresetSettings;
|
||||
import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
|
@ -22,15 +20,13 @@ import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
|||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class WorldPresets {
|
||||
|
||||
public static final TagRegistry.Simple<WorldPreset> WORLD_PRESETS =
|
||||
TagManager.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 Optional<ResourceKey<WorldPreset>> DEFAULT = Optional.of(net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL);
|
||||
public static ResourceKey<WorldPreset> DEFAULT = net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL;
|
||||
|
||||
public static Holder<WorldPreset> get(RegistryAccess access, ResourceKey<WorldPreset> key) {
|
||||
return ((access != null) ? access : BuiltinRegistries.ACCESS)
|
||||
|
@ -87,15 +83,11 @@ public class WorldPresets {
|
|||
|
||||
for (Map.Entry<ResourceKey<WorldPreset>, PresetBuilder> e : BUILDERS.entrySet()) {
|
||||
TogetherWorldPreset 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, VanillaWorldPresetSettings.DEFAULT);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface PresetBuilder {
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
package org.betterx.worlds.together.worldPreset.settings;
|
||||
|
||||
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 addDatapackBiomes(BiomeSource biomeSource, Set<Holder<Biome>> datapackBiomes) {
|
||||
return biomeSource;
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
package org.betterx.worlds.together.worldPreset.settings;
|
||||
|
||||
import org.betterx.worlds.together.WorldsTogether;
|
||||
|
||||
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 WorldPresetSettings DEFAULT = VanillaWorldPresetSettings.DEFAULT;
|
||||
public static final ResourceKey<Registry<Codec<? extends WorldPresetSettings>>> WORLD_PRESET_SETTINGS_REGISTRY =
|
||||
createRegistryKey(WorldsTogether.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(WorldsTogether.makeID("vanilla_world_preset_settings"), VanillaWorldPresetSettings.CODEC);
|
||||
}
|
||||
|
||||
public abstract Codec<? extends WorldPresetSettings> codec();
|
||||
public abstract WorldGenSettings repairSettingsOnLoad(RegistryAccess registryAccess, WorldGenSettings settings);
|
||||
public abstract BiomeSource addDatapackBiomes(BiomeSource biomeSource, Set<Holder<Biome>> datapackBiomes);
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue