Datapack Biome Handling with Custom BiomeSource
This commit is contained in:
parent
e10994a1e8
commit
9d0a640173
28 changed files with 1109 additions and 619 deletions
|
@ -11,7 +11,7 @@ import org.betterx.bclib.api.dataexchange.DataExchangeAPI;
|
|||
import org.betterx.bclib.api.dataexchange.handler.autosync.*;
|
||||
import org.betterx.bclib.api.tag.TagAPI;
|
||||
import org.betterx.bclib.config.Configs;
|
||||
import org.betterx.bclib.presets.worldgen.WorldPresets;
|
||||
import org.betterx.bclib.presets.worldgen.BCLWorldPresets;
|
||||
import org.betterx.bclib.recipes.AnvilRecipe;
|
||||
import org.betterx.bclib.recipes.CraftingRecipes;
|
||||
import org.betterx.bclib.registry.BaseBlockEntities;
|
||||
|
@ -25,6 +25,7 @@ import java.util.List;
|
|||
|
||||
public class BCLib implements ModInitializer {
|
||||
public static final String MOD_ID = "bclib";
|
||||
public static final String TOGETHER_WORLDS = "worlds_together";
|
||||
public static final Logger LOGGER = new Logger(MOD_ID);
|
||||
|
||||
@Override
|
||||
|
@ -37,9 +38,9 @@ public class BCLib implements ModInitializer {
|
|||
TagAPI.init();
|
||||
CraftingRecipes.init();
|
||||
WorldDataAPI.registerModCache(MOD_ID);
|
||||
WorldDataAPI.registerModCache(MOD_ID);
|
||||
WorldDataAPI.registerModCache(TOGETHER_WORLDS);
|
||||
DataExchangeAPI.registerMod(MOD_ID);
|
||||
WorldPresets.registerPresets();
|
||||
BCLWorldPresets.registerPresets();
|
||||
AnvilRecipe.register();
|
||||
|
||||
DataExchangeAPI.registerDescriptors(List.of(
|
||||
|
|
|
@ -16,7 +16,7 @@ import org.betterx.bclib.api.datafixer.DataFixerAPI;
|
|||
import org.betterx.bclib.api.datafixer.ForcedLevelPatch;
|
||||
import org.betterx.bclib.api.datafixer.MigrationProfile;
|
||||
import org.betterx.bclib.config.Configs;
|
||||
import org.betterx.bclib.presets.worldgen.BCLChunkGenerator;
|
||||
import org.betterx.bclib.presets.worldgen.WorldGenUtilities;
|
||||
import org.betterx.bclib.util.MHelper;
|
||||
import org.betterx.bclib.world.generator.GeneratorOptions;
|
||||
|
||||
|
@ -45,7 +45,7 @@ final class BiomeSourcePatch extends ForcedLevelPatch {
|
|||
@Override
|
||||
protected Boolean runLevelDatPatch(CompoundTag root, MigrationProfile profile) {
|
||||
//make sure we have a working generators file before attempting to patch
|
||||
BCLChunkGenerator.migrateGeneratorSettings();
|
||||
WorldGenUtilities.migrateGeneratorSettings();
|
||||
|
||||
final CompoundTag worldGenSettings = root.getCompound("Data").getCompound("WorldGenSettings");
|
||||
final CompoundTag dimensions = worldGenSettings.getCompound("dimensions");
|
||||
|
@ -109,16 +109,16 @@ final class BiomeSourcePatch extends ForcedLevelPatch {
|
|||
Optional<WorldGenSettings> oWorldGen = WorldGenSettings.CODEC
|
||||
.parse(new Dynamic<>(registryOps, worldGenSettings))
|
||||
.result();
|
||||
|
||||
|
||||
Optional<LevelStem> oLevelStem = LevelStem.CODEC
|
||||
.parse(new Dynamic<>(registryOps, dimensionTag))
|
||||
.resultOrPartial(BCLib.LOGGER::error);
|
||||
|
||||
Optional<ChunkGenerator> netherGenerator = oLevelStem.map(l -> l.generator());
|
||||
int biomeSourceVersion = BCLChunkGenerator.getBiomeVersionForGenerator(netherGenerator.orElse(null));
|
||||
int targetVersion = BCLChunkGenerator.getBiomeVersionForCurrentWorld(dimensionKey);
|
||||
int biomeSourceVersion = WorldGenUtilities.getBiomeVersionForGenerator(netherGenerator.orElse(null));
|
||||
int targetVersion = WorldGenUtilities.getBiomeVersionForCurrentWorld(dimensionKey);
|
||||
if (biomeSourceVersion != targetVersion) {
|
||||
Optional<Holder<LevelStem>> refLevelStem = BCLChunkGenerator.referenceStemForVersion(
|
||||
Optional<Holder<LevelStem>> refLevelStem = WorldGenUtilities.referenceStemForVersion(
|
||||
dimensionKey,
|
||||
targetVersion,
|
||||
registryAccess,
|
||||
|
|
|
@ -73,22 +73,30 @@ import org.jetbrains.annotations.Nullable;
|
|||
|
||||
public class BiomeAPI {
|
||||
public static class Dimension {
|
||||
public static final Dimension NONE = new Dimension();
|
||||
public static final Dimension OVERWORLD = new Dimension();
|
||||
public static final Dimension NETHER = new Dimension();
|
||||
public static final Dimension END = new Dimension();
|
||||
public static final Dimension END_LAND = new Dimension(END);
|
||||
public static final Dimension END_VOID = new Dimension(END);
|
||||
public static final Dimension NONE = new Dimension("NONE");
|
||||
public static final Dimension OVERWORLD = new Dimension("OVERWORLD");
|
||||
public static final Dimension NETHER = new Dimension("NETHER");
|
||||
public static final Dimension BCL_NETHER = new Dimension("BCL_NETHER", NETHER);
|
||||
public static final Dimension OTHER_NETHER = new Dimension("OTHER_NETHER", NETHER);
|
||||
public static final Dimension END = new Dimension("END");
|
||||
public static final Dimension END_LAND = new Dimension("END_LAND", END);
|
||||
public static final Dimension END_VOID = new Dimension("END_VOID", END);
|
||||
public static final Dimension BCL_END_LAND = new Dimension("BCL_END_LAND", END_LAND);
|
||||
public static final Dimension BCL_END_VOID = new Dimension("BCL_END_VOID", END_VOID);
|
||||
public static final Dimension OTHER_END_LAND = new Dimension("OTHER_END_LAND", END_LAND);
|
||||
public static final Dimension OTHER_END_VOID = new Dimension("OTHER_END_VOID", END_VOID);
|
||||
|
||||
private static final Map<ResourceLocation, Dimension> DIMENSION_MAP = Maps.newHashMap();
|
||||
public final Dimension parentOrNull;
|
||||
private final String debugName;
|
||||
|
||||
public Dimension() {
|
||||
this(null);
|
||||
public Dimension(String debugName) {
|
||||
this(debugName, null);
|
||||
}
|
||||
|
||||
public Dimension(Dimension parentOrNull) {
|
||||
public Dimension(String debugName, Dimension parentOrNull) {
|
||||
this.parentOrNull = parentOrNull;
|
||||
this.debugName = debugName;
|
||||
}
|
||||
|
||||
public boolean is(Dimension d) {
|
||||
|
@ -96,6 +104,13 @@ public class BiomeAPI {
|
|||
if (parentOrNull != null) return parentOrNull.is(d);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String str = debugName;
|
||||
if (parentOrNull != null) str += " -> " + parentOrNull.toString();
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -207,17 +222,26 @@ public class BiomeAPI {
|
|||
}
|
||||
|
||||
public static BCLBiome registerSubBiome(BCLBiome parent, BCLBiome subBiome) {
|
||||
final Dimension dim = Dimension.DIMENSION_MAP.getOrDefault(parent.getID(), Dimension.NONE);
|
||||
return registerSubBiome(parent, subBiome, Dimension.DIMENSION_MAP.getOrDefault(parent.getID(), Dimension.NONE));
|
||||
}
|
||||
|
||||
public static BCLBiome registerSubBiome(BCLBiome parent, Biome subBiome, float genChance) {
|
||||
return registerSubBiome(parent,
|
||||
subBiome,
|
||||
genChance,
|
||||
Dimension.DIMENSION_MAP.getOrDefault(parent.getID(), Dimension.NONE));
|
||||
}
|
||||
|
||||
public static BCLBiome registerSubBiome(BCLBiome parent, BCLBiome subBiome, Dimension dim) {
|
||||
registerBiome(subBiome, dim);
|
||||
parent.addSubBiome(subBiome);
|
||||
|
||||
|
||||
return subBiome;
|
||||
}
|
||||
|
||||
public static BCLBiome registerSubBiome(BCLBiome parent, Biome biome, float genChance) {
|
||||
public static BCLBiome registerSubBiome(BCLBiome parent, Biome biome, float genChance, Dimension dim) {
|
||||
BCLBiome subBiome = new BCLBiome(biome, VanillaBiomeSettings.createVanilla().setGenChance(genChance).build());
|
||||
return registerSubBiome(parent, subBiome);
|
||||
return registerSubBiome(parent, subBiome, dim);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -228,10 +252,12 @@ public class BiomeAPI {
|
|||
* @return {@link BCLBiome}
|
||||
*/
|
||||
public static BCLBiome registerNetherBiome(BCLBiome bclBiome) {
|
||||
registerBiome(bclBiome, Dimension.NETHER);
|
||||
registerBiome(bclBiome, Dimension.BCL_NETHER);
|
||||
|
||||
ResourceKey<Biome> key = BiomeAPI.getBiomeKeyOrThrow(bclBiome.getBiomeHolder());
|
||||
bclBiome.forEachClimateParameter(p -> NetherBiomeData.addNetherBiome(key, p));
|
||||
if (bclBiome.allowFabricRegistration()) {
|
||||
bclBiome.forEachClimateParameter(p -> NetherBiomeData.addNetherBiome(key, p));
|
||||
}
|
||||
return bclBiome;
|
||||
}
|
||||
|
||||
|
@ -244,7 +270,7 @@ public class BiomeAPI {
|
|||
*/
|
||||
public static BCLBiome registerNetherBiome(Biome biome) {
|
||||
BCLBiome bclBiome = new BCLBiome(biome, null);
|
||||
registerBiome(bclBiome, Dimension.NETHER);
|
||||
registerBiome(bclBiome, Dimension.OTHER_NETHER);
|
||||
return bclBiome;
|
||||
}
|
||||
|
||||
|
@ -256,12 +282,14 @@ public class BiomeAPI {
|
|||
* @return {@link BCLBiome}
|
||||
*/
|
||||
public static BCLBiome registerEndLandBiome(BCLBiome biome) {
|
||||
registerBiome(biome, Dimension.END_LAND);
|
||||
registerBiome(biome, Dimension.BCL_END_LAND);
|
||||
|
||||
float weight = biome.getGenChance();
|
||||
ResourceKey<Biome> key = BiomeAPI.getBiomeKey(biome.getBiome());
|
||||
TheEndBiomeData.addEndBiomeReplacement(Biomes.END_HIGHLANDS, key, weight);
|
||||
TheEndBiomeData.addEndBiomeReplacement(Biomes.END_MIDLANDS, key, weight);
|
||||
if (biome.allowFabricRegistration()) {
|
||||
TheEndBiomeData.addEndBiomeReplacement(Biomes.END_HIGHLANDS, key, weight);
|
||||
TheEndBiomeData.addEndBiomeReplacement(Biomes.END_MIDLANDS, key, weight);
|
||||
}
|
||||
return biome;
|
||||
}
|
||||
|
||||
|
@ -275,7 +303,7 @@ public class BiomeAPI {
|
|||
public static BCLBiome registerEndLandBiome(Holder<Biome> biome) {
|
||||
BCLBiome bclBiome = new BCLBiome(biome.value(), null);
|
||||
|
||||
registerBiome(bclBiome, Dimension.END_LAND);
|
||||
registerBiome(bclBiome, Dimension.OTHER_END_LAND);
|
||||
return bclBiome;
|
||||
}
|
||||
|
||||
|
@ -291,7 +319,7 @@ public class BiomeAPI {
|
|||
BCLBiome bclBiome = new BCLBiome(biome.value(),
|
||||
VanillaBiomeSettings.createVanilla().setGenChance(genChance).build());
|
||||
|
||||
registerBiome(bclBiome, Dimension.END_LAND);
|
||||
registerBiome(bclBiome, Dimension.OTHER_END_LAND);
|
||||
return bclBiome;
|
||||
}
|
||||
|
||||
|
@ -307,7 +335,9 @@ public class BiomeAPI {
|
|||
|
||||
float weight = biome.getGenChance();
|
||||
ResourceKey<Biome> key = BiomeAPI.getBiomeKeyOrThrow(biome.getBiomeHolder());
|
||||
TheEndBiomeData.addEndBiomeReplacement(Biomes.SMALL_END_ISLANDS, key, weight);
|
||||
if (biome.allowFabricRegistration()) {
|
||||
TheEndBiomeData.addEndBiomeReplacement(Biomes.SMALL_END_ISLANDS, key, weight);
|
||||
}
|
||||
return biome;
|
||||
}
|
||||
|
||||
|
@ -501,8 +531,12 @@ public class BiomeAPI {
|
|||
}
|
||||
|
||||
public static boolean wasRegisteredAs(ResourceLocation biomeID, Dimension dim) {
|
||||
if (!Dimension.DIMENSION_MAP.containsKey(biomeID)) return false;
|
||||
return Dimension.DIMENSION_MAP.get(biomeID).is(dim);
|
||||
if (Dimension.DIMENSION_MAP.containsKey(biomeID) && Dimension.DIMENSION_MAP.get(biomeID).is(dim)) return true;
|
||||
BCLBiome biome = getBiome(biomeID);
|
||||
if (biome != null && biome != BiomeAPI.EMPTY_BIOME && biome.getParentBiome() != null) {
|
||||
return wasRegisteredAs(biome.getParentBiome().getID(), dim);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean wasRegisteredAsNetherBiome(ResourceLocation biomeID) {
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.betterx.bclib.gui.screens.ConfirmFixScreen;
|
|||
import org.betterx.bclib.gui.screens.LevelFixErrorScreen;
|
||||
import org.betterx.bclib.gui.screens.LevelFixErrorScreen.Listener;
|
||||
import org.betterx.bclib.gui.screens.ProgressScreen;
|
||||
import org.betterx.bclib.presets.worldgen.BCLChunkGenerator;
|
||||
import org.betterx.bclib.presets.worldgen.WorldGenUtilities;
|
||||
import org.betterx.bclib.util.Logger;
|
||||
|
||||
import java.io.*;
|
||||
|
@ -181,7 +181,7 @@ public class DataFixerAPI {
|
|||
|
||||
public static void createWorldData(LevelStorageAccess access, WorldGenSettings settings) {
|
||||
initializeWorldData(access, true);
|
||||
BCLChunkGenerator.initializeWorldData(settings);
|
||||
WorldGenUtilities.initializeWorldData(settings);
|
||||
WorldDataAPI.saveFile(BCLib.MOD_ID);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import net.fabricmc.api.EnvType;
|
|||
import net.fabricmc.api.Environment;
|
||||
|
||||
import org.betterx.bclib.gui.screens.WorldSetupScreen;
|
||||
import org.betterx.bclib.presets.worldgen.WorldPresets;
|
||||
import org.betterx.bclib.presets.worldgen.BCLWorldPresets;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
@ -21,7 +21,7 @@ public class WorldPresetsUI {
|
|||
}
|
||||
|
||||
public static void setupClientside() {
|
||||
registerCustomizeUI(WorldPresets.BCL_WORLD, (createWorldScreen, worldCreationContext) -> {
|
||||
registerCustomizeUI(BCLWorldPresets.BCL_WORLD, (createWorldScreen, worldCreationContext) -> {
|
||||
return new WorldSetupScreen(createWorldScreen, worldCreationContext);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -15,8 +15,7 @@ import net.fabricmc.api.Environment;
|
|||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.gui.gridlayout.GridCheckboxCell;
|
||||
import org.betterx.bclib.gui.gridlayout.GridLayout;
|
||||
import org.betterx.bclib.presets.worldgen.BCLChunkGenerator;
|
||||
import org.betterx.bclib.presets.worldgen.WorldPresets;
|
||||
import org.betterx.bclib.presets.worldgen.WorldGenUtilities;
|
||||
import org.betterx.bclib.world.generator.BCLBiomeSource;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -40,14 +39,14 @@ public class WorldSetupScreen extends BCLibScreen {
|
|||
|
||||
@Override
|
||||
protected void initLayout() {
|
||||
final int netherVersion = BCLChunkGenerator.getBiomeVersionForGenerator(context
|
||||
final int netherVersion = WorldGenUtilities.getBiomeVersionForGenerator(context
|
||||
.worldGenSettings()
|
||||
.dimensions()
|
||||
.getOrCreateHolderOrThrow(
|
||||
LevelStem.NETHER)
|
||||
.value()
|
||||
.generator());
|
||||
final int endVersion = BCLChunkGenerator.getBiomeVersionForGenerator(context
|
||||
final int endVersion = WorldGenUtilities.getBiomeVersionForGenerator(context
|
||||
.worldGenSettings()
|
||||
.dimensions()
|
||||
.getOrCreateHolderOrThrow(
|
||||
|
@ -150,7 +149,7 @@ public class WorldSetupScreen extends BCLibScreen {
|
|||
int biomeSourceVersion
|
||||
) {
|
||||
createWorldScreen.worldGenSettingsComponent.updateSettings(
|
||||
(registryAccess, worldGenSettings) -> WorldPresets.replaceGenerator(
|
||||
(registryAccess, worldGenSettings) -> WorldGenUtilities.replaceGenerator(
|
||||
dimensionKey,
|
||||
dimensionTypeKey,
|
||||
biomeSourceVersion,
|
||||
|
|
|
@ -13,7 +13,8 @@ import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
|||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import org.betterx.bclib.api.biomes.BiomeAPI;
|
||||
import org.betterx.bclib.presets.worldgen.WorldPresets;
|
||||
import org.betterx.bclib.presets.worldgen.BCLWorldPresets;
|
||||
import org.betterx.bclib.presets.worldgen.WorldGenUtilities;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
|
@ -35,15 +36,15 @@ 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 BCLWorldPresets.DEFAULT;
|
||||
}
|
||||
|
||||
//Make sure the WorldGenSettings match the default WorldPreset
|
||||
//Make sure the WorldGenSettings used to populate the create screen match the default WorldPreset
|
||||
@ModifyArg(method = "openFresh", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/WorldLoader;load(Lnet/minecraft/server/WorldLoader$InitConfig;Lnet/minecraft/server/WorldLoader$WorldDataSupplier;Lnet/minecraft/server/WorldLoader$ResultFactory;Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;"))
|
||||
private static WorldLoader.WorldDataSupplier<WorldGenSettings> bcl_NewDefaultSettings(WorldLoader.WorldDataSupplier<WorldGenSettings> worldDataSupplier) {
|
||||
return (resourceManager, dataPackConfig) -> {
|
||||
Pair<WorldGenSettings, RegistryAccess.Frozen> res = worldDataSupplier.get(resourceManager, dataPackConfig);
|
||||
return WorldPresets.defaultWorldDataSupplier(res.getSecond());
|
||||
return WorldGenUtilities.defaultWorldDataSupplier(res.getSecond());
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.betterx.bclib.mixin.common;
|
|||
|
||||
import net.minecraft.server.dedicated.DedicatedServerProperties;
|
||||
|
||||
import org.betterx.bclib.presets.worldgen.WorldPresets;
|
||||
import org.betterx.bclib.presets.worldgen.BCLWorldPresets;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
|
@ -12,6 +12,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 BCLWorldPresets.DEFAULT.orElseThrow().location().toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,52 @@
|
|||
package org.betterx.bclib.mixin.common;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.world.level.LevelSettings;
|
||||
import net.minecraft.world.level.dimension.BuiltinDimensionTypes;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.levelgen.WorldGenSettings;
|
||||
import net.minecraft.world.level.storage.LevelVersion;
|
||||
import net.minecraft.world.level.storage.PrimaryLevelData;
|
||||
|
||||
import org.betterx.bclib.presets.worldgen.WorldPresets;
|
||||
import com.mojang.datafixers.DataFixer;
|
||||
import com.mojang.serialization.Dynamic;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import org.betterx.bclib.presets.worldgen.WorldGenUtilities;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.Optional;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Mixin(PrimaryLevelData.class)
|
||||
public class PrimaryLevelDataMixin {
|
||||
@Shadow
|
||||
private LevelSettings settings;
|
||||
private static final ThreadLocal<Optional<RegistryOps<Tag>>> bcl_lastRegistryAccess = ThreadLocal.withInitial(
|
||||
() -> Optional.empty());
|
||||
|
||||
@Inject(method = "parse", at = @At("HEAD"))
|
||||
private static void bcl_parse(Dynamic<Tag> dynamic,
|
||||
DataFixer dataFixer,
|
||||
int i,
|
||||
@Nullable CompoundTag compoundTag,
|
||||
LevelSettings levelSettings,
|
||||
LevelVersion levelVersion,
|
||||
WorldGenSettings worldGenSettings,
|
||||
Lifecycle lifecycle,
|
||||
CallbackInfoReturnable<PrimaryLevelData> cir) {
|
||||
if (dynamic.getOps() instanceof RegistryOps<Tag> regOps) {
|
||||
bcl_lastRegistryAccess.set(Optional.of(regOps));
|
||||
}
|
||||
}
|
||||
|
||||
@ModifyArg(method = "parse", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/PrimaryLevelData;<init>(Lcom/mojang/datafixers/DataFixer;ILnet/minecraft/nbt/CompoundTag;ZIIIFJJIIIZIZZZLnet/minecraft/world/level/border/WorldBorder$Settings;IILjava/util/UUID;Ljava/util/Set;Lnet/minecraft/world/level/timers/TimerQueue;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/world/level/LevelSettings;Lnet/minecraft/world/level/levelgen/WorldGenSettings;Lcom/mojang/serialization/Lifecycle;)V"))
|
||||
private static WorldGenSettings bcl_fixSettings(WorldGenSettings settings) {
|
||||
settings = WorldPresets.fixSettingsInCurrentWorld(LevelStem.NETHER, BuiltinDimensionTypes.NETHER, settings);
|
||||
settings = WorldPresets.fixSettingsInCurrentWorld(LevelStem.END, BuiltinDimensionTypes.END, settings);
|
||||
Optional<RegistryOps<Tag>> registryOps = bcl_lastRegistryAccess.get();
|
||||
settings = WorldGenUtilities.fixSettingsInCurrentWorld(registryOps, settings);
|
||||
|
||||
bcl_lastRegistryAccess.set(Optional.empty());
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package org.betterx.bclib.mixin.common;
|
||||
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(RegistryOps.class)
|
||||
public interface RegistryOpsAccessor {
|
||||
@Accessor("registryAccess")
|
||||
RegistryAccess bcl_getRegistryAccess();
|
||||
}
|
|
@ -4,7 +4,7 @@ import net.minecraft.resources.ResourceKey;
|
|||
import net.minecraft.server.dedicated.DedicatedServerProperties;
|
||||
import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
||||
|
||||
import org.betterx.bclib.presets.worldgen.WorldPresets;
|
||||
import org.betterx.bclib.presets.worldgen.BCLWorldPresets;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
|
@ -19,6 +19,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 BCLWorldPresets.DEFAULT.orElseThrow();
|
||||
}
|
||||
}
|
|
@ -3,20 +3,12 @@ package org.betterx.bclib.mixin.common;
|
|||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.worldselection.WorldOpenFlows;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.server.ReloadableServerResources;
|
||||
import net.minecraft.server.WorldLoader;
|
||||
import net.minecraft.server.WorldStem;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.world.level.DataPackConfig;
|
||||
import net.minecraft.world.level.LevelSettings;
|
||||
import net.minecraft.world.level.levelgen.WorldGenSettings;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
import net.minecraft.world.level.storage.WorldData;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import org.betterx.bclib.api.LifeCycleAPI;
|
||||
import org.betterx.bclib.api.biomes.BiomeAPI;
|
||||
import org.betterx.bclib.api.dataexchange.DataExchangeAPI;
|
||||
|
@ -28,7 +20,6 @@ import org.spongepowered.asm.mixin.Shadow;
|
|||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(WorldOpenFlows.class)
|
||||
public abstract class WorldOpenFlowsMixin {
|
||||
|
@ -86,24 +77,4 @@ public abstract class WorldOpenFlowsMixin {
|
|||
DataFixerAPI.createWorldData(levelStorageAccess, worldData.worldGenSettings());
|
||||
LifeCycleAPI._runBeforeLevelLoad();
|
||||
}
|
||||
|
||||
@Inject(method = "loadWorldStem(Lnet/minecraft/server/WorldLoader$PackConfig;Lnet/minecraft/server/WorldLoader$WorldDataSupplier;)Lnet/minecraft/server/WorldStem;", at = @At("RETURN"))
|
||||
public void bcl_loadWorldStem(WorldLoader.PackConfig packConfig,
|
||||
WorldLoader.WorldDataSupplier<WorldData> worldDataSupplier,
|
||||
CallbackInfoReturnable<WorldStem> cir) {
|
||||
WorldStem result = cir.getReturnValue();
|
||||
}
|
||||
|
||||
@Inject(method = "method_41887", at = @At("RETURN"))
|
||||
private static void bcl_loadWorldStem(LevelStorageSource.LevelStorageAccess levelStorageAccess,
|
||||
ResourceManager resourceManager,
|
||||
DataPackConfig dataPackConfig,
|
||||
CallbackInfoReturnable<Pair> cir) {
|
||||
RegistryAccess.Writable writable = RegistryAccess.builtinCopy();
|
||||
RegistryOps<Tag> dynamicOps = RegistryOps.create(NbtOps.INSTANCE, writable);
|
||||
WorldData worldData = levelStorageAccess.getDataTag(dynamicOps,
|
||||
dataPackConfig,
|
||||
writable.allElementsLifecycle());
|
||||
Pair<WorldData, RegistryAccess> p = cir.getReturnValue();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package org.betterx.bclib.mixin.common;
|
||||
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Mixin(WorldPreset.class)
|
||||
public interface WorldPresetAccessor {
|
||||
@Accessor("dimensions")
|
||||
public Map<ResourceKey<LevelStem>, LevelStem> bcl_getDimensions();
|
||||
}
|
|
@ -2,7 +2,6 @@ package org.betterx.bclib.mixin.common;
|
|||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
|
@ -12,16 +11,15 @@ import net.minecraft.world.level.levelgen.presets.WorldPresets;
|
|||
import net.minecraft.world.level.levelgen.structure.StructureSet;
|
||||
import net.minecraft.world.level.levelgen.synth.NormalNoise;
|
||||
|
||||
import org.betterx.bclib.world.generator.BCLBiomeSource;
|
||||
import org.betterx.bclib.presets.worldgen.BCLWorldPresets;
|
||||
import org.betterx.bclib.presets.worldgen.WorldGenUtilities;
|
||||
import org.betterx.bclib.presets.worldgen.WorldPresetSettings;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Mixin(WorldPresets.Bootstrap.class)
|
||||
public abstract class WorldPresetsBootstrapMixin {
|
||||
@Shadow
|
||||
|
@ -53,52 +51,21 @@ 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) {
|
||||
WorldPreset preset_18 = new org.betterx.bclib.presets.worldgen.WorldPresets.SortableWorldPreset(
|
||||
Map.of(LevelStem.OVERWORLD,
|
||||
overworldStem,
|
||||
LevelStem.NETHER,
|
||||
org.betterx.bclib.presets.worldgen.WorldPresets.getBCLNetherLevelStem(this.biomes,
|
||||
this.netherDimensionType,
|
||||
this.structureSets,
|
||||
this.noises,
|
||||
this.netherNoiseSettings,
|
||||
Optional.empty()),
|
||||
LevelStem.END,
|
||||
org.betterx.bclib.presets.worldgen.WorldPresets.getBCLEndLevelStem(this.biomes,
|
||||
this.endDimensionType,
|
||||
this.structureSets,
|
||||
this.noises,
|
||||
this.endNoiseSettings,
|
||||
Optional.empty())
|
||||
), 0
|
||||
);
|
||||
WorldPresetSettings.bootstrap();
|
||||
WorldGenUtilities.Context netherContext = new WorldGenUtilities.Context(this.biomes,
|
||||
this.netherDimensionType,
|
||||
this.structureSets,
|
||||
this.noises,
|
||||
this.netherNoiseSettings);
|
||||
WorldGenUtilities.Context endContext = new WorldGenUtilities.Context(this.biomes,
|
||||
this.endDimensionType,
|
||||
this.structureSets,
|
||||
this.noises,
|
||||
this.endNoiseSettings);
|
||||
|
||||
WorldPreset preset_17 = new org.betterx.bclib.presets.worldgen.WorldPresets.SortableWorldPreset(
|
||||
Map.of(LevelStem.OVERWORLD,
|
||||
overworldStem,
|
||||
LevelStem.NETHER,
|
||||
org.betterx.bclib.presets.worldgen.WorldPresets.getBCLNetherLevelStem(this.biomes,
|
||||
this.netherDimensionType,
|
||||
this.structureSets,
|
||||
this.noises,
|
||||
this.netherNoiseSettings,
|
||||
Optional.of(BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE)),
|
||||
LevelStem.END,
|
||||
org.betterx.bclib.presets.worldgen.WorldPresets.getBCLEndLevelStem(this.biomes,
|
||||
this.endDimensionType,
|
||||
this.structureSets,
|
||||
this.noises,
|
||||
this.endNoiseSettings,
|
||||
Optional.of(BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE))
|
||||
), 0
|
||||
);
|
||||
|
||||
BuiltinRegistries.register(this.presets, org.betterx.bclib.presets.worldgen.WorldPresets.BCL_WORLD, preset_18);
|
||||
BuiltinRegistries.register(this.presets,
|
||||
org.betterx.bclib.presets.worldgen.WorldPresets.BCL_WORLD_17,
|
||||
preset_17);
|
||||
BCLWorldPresets.bootstrapPresets(presets, overworldStem, netherContext, endContext);
|
||||
|
||||
return overworldStem;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,35 +2,20 @@ package org.betterx.bclib.presets.worldgen;
|
|||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator;
|
||||
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
|
||||
import net.minecraft.world.level.levelgen.WorldGenSettings;
|
||||
import net.minecraft.world.level.levelgen.structure.StructureSet;
|
||||
import net.minecraft.world.level.levelgen.synth.NormalNoise;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.api.WorldDataAPI;
|
||||
import org.betterx.bclib.interfaces.NoiseGeneratorSettingsProvider;
|
||||
import org.betterx.bclib.util.ModUtil;
|
||||
import org.betterx.bclib.world.generator.BCLBiomeSource;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class BCLChunkGenerator extends NoiseBasedChunkGenerator {
|
||||
|
||||
private static String TAG_GENERATOR = "generator";
|
||||
private static final String TAG_VERSION = "version";
|
||||
private static final String TAG_BN_GEN_VERSION = "generator_version";
|
||||
|
||||
public static final Codec<BCLChunkGenerator> CODEC = RecordCodecBuilder
|
||||
.create((RecordCodecBuilder.Instance<BCLChunkGenerator> builderInstance) -> {
|
||||
final RecordCodecBuilder<BCLChunkGenerator, Registry<NormalNoise.NoiseParameters>> noiseGetter = RegistryOps
|
||||
|
@ -75,107 +60,6 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static int getBiomeVersionForGenerator(ChunkGenerator generator) {
|
||||
if (generator == null) return BCLBiomeSource.getVersionBiomeSource(null);
|
||||
return BCLBiomeSource.getVersionBiomeSource(generator.getBiomeSource());
|
||||
}
|
||||
|
||||
public static Optional<Holder<LevelStem>> referenceStemForVersion(
|
||||
ResourceKey<LevelStem> dimensionKey,
|
||||
int biomeSourceVersion,
|
||||
RegistryAccess registryAccess,
|
||||
long seed,
|
||||
boolean generateStructures,
|
||||
boolean generateBonusChest
|
||||
) {
|
||||
final WorldGenSettings referenceSettings;
|
||||
if (biomeSourceVersion == BCLBiomeSource.BIOME_SOURCE_VERSION_VANILLA) {
|
||||
referenceSettings = net.minecraft.world.level.levelgen.presets.WorldPresets.createNormalWorldFromPreset(
|
||||
registryAccess,
|
||||
seed,
|
||||
generateStructures,
|
||||
generateBonusChest);
|
||||
} else if (biomeSourceVersion == BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE) {
|
||||
referenceSettings = WorldPresets.createWorldFromPreset(
|
||||
WorldPresets.BCL_WORLD_17,
|
||||
registryAccess,
|
||||
seed,
|
||||
generateStructures,
|
||||
generateBonusChest);
|
||||
} else {
|
||||
referenceSettings = WorldPresets.createDefaultWorldFromPreset(
|
||||
registryAccess,
|
||||
seed,
|
||||
generateStructures,
|
||||
generateBonusChest);
|
||||
}
|
||||
return referenceSettings.dimensions().getHolder(dimensionKey);
|
||||
}
|
||||
|
||||
public static int getBiomeVersionForCurrentWorld(ResourceKey<LevelStem> key) {
|
||||
final CompoundTag settingsNbt = getSettingsNbt();
|
||||
if (!settingsNbt.contains(key.location().toString())) return BCLBiomeSource.DEFAULT_BIOME_SOURCE_VERSION;
|
||||
return settingsNbt.getInt(key.location().toString());
|
||||
}
|
||||
|
||||
private static void writeDimensionVersion(WorldGenSettings settings,
|
||||
CompoundTag generatorSettings,
|
||||
ResourceKey<LevelStem> key) {
|
||||
var dimension = settings.dimensions().getHolder(key);
|
||||
if (dimension.isPresent()) {
|
||||
generatorSettings.putInt(key.location().toString(),
|
||||
getBiomeVersionForGenerator(dimension.get().value().generator()));
|
||||
} else {
|
||||
generatorSettings.putInt(key.location().toString(), getBiomeVersionForGenerator(null));
|
||||
}
|
||||
}
|
||||
|
||||
public static void initializeWorldData(WorldGenSettings settings) {
|
||||
final CompoundTag settingsNbt = getSettingsNbt();
|
||||
writeDimensionVersion(settings, settingsNbt, LevelStem.NETHER);
|
||||
writeDimensionVersion(settings, settingsNbt, LevelStem.END);
|
||||
}
|
||||
|
||||
private static CompoundTag getSettingsNbt() {
|
||||
return WorldDataAPI.getCompoundTag(BCLib.MOD_ID, TAG_GENERATOR);
|
||||
}
|
||||
|
||||
public static void migrateGeneratorSettings() {
|
||||
final CompoundTag settingsNbt = getSettingsNbt();
|
||||
|
||||
if (settingsNbt.size() == 0) {
|
||||
BCLib.LOGGER.info("Found World without generator Settings. Setting up data...");
|
||||
int biomeSourceVersion = BCLBiomeSource.DEFAULT_BIOME_SOURCE_VERSION;
|
||||
|
||||
final CompoundTag bclRoot = WorldDataAPI.getRootTag(BCLib.MOD_ID);
|
||||
|
||||
String bclVersion = "0.0.0";
|
||||
if (bclRoot.contains(TAG_VERSION)) {
|
||||
bclVersion = bclRoot.getString(TAG_VERSION);
|
||||
}
|
||||
boolean isPre18 = !ModUtil.isLargerOrEqualVersion(bclVersion, "1.0.0");
|
||||
|
||||
if (isPre18) {
|
||||
BCLib.LOGGER.info("World was create pre 1.18!");
|
||||
biomeSourceVersion = BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE;
|
||||
}
|
||||
|
||||
if (WorldDataAPI.hasMod("betternether")) {
|
||||
BCLib.LOGGER.info("Found Data from BetterNether, using for migration.");
|
||||
final CompoundTag bnRoot = WorldDataAPI.getRootTag("betternether");
|
||||
biomeSourceVersion = "1.17".equals(bnRoot.getString(TAG_BN_GEN_VERSION))
|
||||
? BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE
|
||||
: BCLBiomeSource.BIOME_SOURCE_VERSION_HEX;
|
||||
}
|
||||
|
||||
BCLib.LOGGER.info("Set world to BiomeSource Version " + biomeSourceVersion);
|
||||
settingsNbt.putInt(LevelStem.NETHER.location().toString(), biomeSourceVersion);
|
||||
settingsNbt.putInt(LevelStem.END.location().toString(), biomeSourceVersion);
|
||||
|
||||
WorldDataAPI.saveFile(BCLib.MOD_ID);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BCLib - Chunk Generator (" + Integer.toHexString(hashCode()) + ")";
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package org.betterx.bclib.presets.worldgen;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.RegistryFileCodec;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import org.betterx.bclib.mixin.common.WorldPresetAccessor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class BCLWorldPreset extends WorldPreset {
|
||||
public final WorldPresetSettings settings;
|
||||
public final int sortOrder;
|
||||
public static final Codec<BCLWorldPreset> DIRECT_CODEC = RecordCodecBuilder.create(builderInstance -> {
|
||||
RecordCodecBuilder<BCLWorldPreset, Map<ResourceKey<LevelStem>, LevelStem>> dimensionsBuidler = Codec
|
||||
.unboundedMap(ResourceKey.codec(Registry.LEVEL_STEM_REGISTRY), LevelStem.CODEC)
|
||||
.fieldOf("dimensions")
|
||||
.forGetter(worldPreset -> worldPreset.getDimensions());
|
||||
|
||||
RecordCodecBuilder<BCLWorldPreset, Integer> sortBuilder = Codec.INT
|
||||
.fieldOf("sort_order")
|
||||
.forGetter(wp -> wp.sortOrder);
|
||||
|
||||
RecordCodecBuilder<BCLWorldPreset, WorldPresetSettings> settingsBuilder = WorldPresetSettings.CODEC
|
||||
.fieldOf("settings")
|
||||
.forGetter(wp -> wp.settings);
|
||||
|
||||
return builderInstance
|
||||
.group(dimensionsBuidler, sortBuilder, settingsBuilder)
|
||||
.apply(builderInstance, BCLWorldPreset::new);
|
||||
});
|
||||
|
||||
public static final Codec<Holder<WorldPreset>> CODEC = RegistryFileCodec.create(
|
||||
Registry.WORLD_PRESET_REGISTRY,
|
||||
(Codec<WorldPreset>) ((Object) DIRECT_CODEC));
|
||||
|
||||
public BCLWorldPreset(Map<ResourceKey<LevelStem>, LevelStem> map, int sortOrder, WorldPresetSettings settings) {
|
||||
super(map);
|
||||
this.sortOrder = sortOrder;
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
private Map<ResourceKey<LevelStem>, LevelStem> getDimensions() {
|
||||
return WorldPresetAccessor.class.cast(this).bcl_getDimensions();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,169 @@
|
|||
package org.betterx.bclib.presets.worldgen;
|
||||
|
||||
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.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.WorldGenSettings;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.interfaces.ChunkGeneratorAccessor;
|
||||
import org.betterx.bclib.interfaces.NoiseGeneratorSettingsProvider;
|
||||
import org.betterx.bclib.world.generator.BCLBiomeSource;
|
||||
import org.betterx.bclib.world.generator.BCLibNetherBiomeSource;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
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) -> {
|
||||
RecordCodecBuilder<BCLWorldPresetSettings, Integer> netherVersion = Codec.INT
|
||||
.fieldOf(LevelStem.NETHER.location().toString())
|
||||
.forGetter((BCLWorldPresetSettings settings) -> settings.netherVersion);
|
||||
|
||||
RecordCodecBuilder<BCLWorldPresetSettings, Integer> endVersion = Codec.INT
|
||||
.fieldOf(LevelStem.END.location().toString())
|
||||
.forGetter((BCLWorldPresetSettings settings) -> settings.endVersion);
|
||||
|
||||
|
||||
return builderInstance.group(netherVersion, endVersion)
|
||||
.apply(builderInstance, builderInstance.stable(BCLWorldPresetSettings::new));
|
||||
});
|
||||
public final int netherVersion;
|
||||
public final int endVersion;
|
||||
|
||||
public BCLWorldPresetSettings(int version) {
|
||||
this(version, version);
|
||||
}
|
||||
|
||||
public BCLWorldPresetSettings(int netherVersion, int endVersion) {
|
||||
this.netherVersion = netherVersion;
|
||||
this.endVersion = endVersion;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Codec<? extends WorldPresetSettings> codec() {
|
||||
return CODEC;
|
||||
}
|
||||
|
||||
public BCLWorldPreset buildPreset(LevelStem overworldStem,
|
||||
WorldGenUtilities.Context netherContext,
|
||||
WorldGenUtilities.Context endContext) {
|
||||
return new BCLWorldPreset(buildDimensionMap(overworldStem, netherContext, endContext), 1000, this);
|
||||
}
|
||||
|
||||
public Map<ResourceKey<LevelStem>, LevelStem> buildDimensionMap(LevelStem overworldStem,
|
||||
WorldGenUtilities.Context netherContext,
|
||||
WorldGenUtilities.Context endContext) {
|
||||
return Map.of(LevelStem.OVERWORLD,
|
||||
overworldStem,
|
||||
LevelStem.NETHER,
|
||||
createNetherStem(netherContext),
|
||||
LevelStem.END,
|
||||
createEndStem(endContext)
|
||||
);
|
||||
}
|
||||
|
||||
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 LevelStem createStem(WorldGenUtilities.Context ctx, ResourceKey<LevelStem> key) {
|
||||
if (key == LevelStem.NETHER) return createNetherStem(ctx);
|
||||
if (key == LevelStem.END) return createEndStem(ctx);
|
||||
return null;
|
||||
}
|
||||
|
||||
public LevelStem createNetherStem(WorldGenUtilities.Context ctx) {
|
||||
return WorldGenUtilities.getBCLNetherLevelStem(ctx, Optional.of(netherVersion));
|
||||
}
|
||||
|
||||
public LevelStem createEndStem(WorldGenUtilities.Context ctx) {
|
||||
return WorldGenUtilities.getBCLEndLevelStem(ctx, Optional.of(endVersion));
|
||||
}
|
||||
|
||||
public BiomeSource fixBiomeSource(BiomeSource biomeSource, Set<Holder<Biome>> datapackBiomes) {
|
||||
if (biomeSource instanceof BCLibNetherBiomeSource bs) {
|
||||
return bs.createCopyForDatapack(datapackBiomes);
|
||||
}
|
||||
return biomeSource;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public WorldGenSettings fixSettingsInCurrentWorld(RegistryAccess access, ResourceKey<LevelStem> dimensionKey,
|
||||
ResourceKey<DimensionType> dimensionTypeKey,
|
||||
WorldGenSettings settings) {
|
||||
var oldNether = settings.dimensions().getHolder(dimensionKey);
|
||||
int loaderVersion = WorldGenUtilities.getBiomeVersionForGenerator(oldNether
|
||||
.map(h -> h.value().generator())
|
||||
.orElse(null));
|
||||
|
||||
int targetVersion = getVersion(dimensionKey);
|
||||
if (loaderVersion != targetVersion) {
|
||||
BCLib.LOGGER.info("Enforcing Correct Generator for " + dimensionKey.location().toString() + ".");
|
||||
var chunkGenerator = oldNether.map(h -> h.value().generator()).orElse(null);
|
||||
Optional<Holder<LevelStem>> refLevelStem = WorldGenUtilities.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 (chunkGenerator instanceof ChunkGeneratorAccessor generator) {
|
||||
if (chunkGenerator instanceof NoiseGeneratorSettingsProvider noiseProvider) {
|
||||
final Set<Holder<Biome>> biomes = chunkGenerator.getBiomeSource().possibleBiomes();
|
||||
|
||||
referenceGenerator = new BCLChunkGenerator(generator.bclib_getStructureSetsRegistry(),
|
||||
noiseProvider.bclib_getNoises(),
|
||||
fixBiomeSource(referenceGenerator.getBiomeSource(), biomes),
|
||||
noiseProvider.bclib_getNoiseGeneratorSettingHolders());
|
||||
}
|
||||
}
|
||||
|
||||
return WorldGenUtilities.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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
package org.betterx.bclib.presets.worldgen;
|
||||
|
||||
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 org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.api.tag.TagAPI;
|
||||
import org.betterx.bclib.api.tag.TagType;
|
||||
import org.betterx.bclib.world.generator.BCLBiomeSource;
|
||||
|
||||
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 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),
|
||||
true);
|
||||
|
||||
/**
|
||||
* 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,
|
||||
WorldGenUtilities.Context netherContext,
|
||||
WorldGenUtilities.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,
|
||||
WorldGenUtilities.Context netherContext,
|
||||
WorldGenUtilities.Context endContext);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,382 @@
|
|||
package org.betterx.bclib.presets.worldgen;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.MappedRegistry;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
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;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
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.NoiseGeneratorSettings;
|
||||
import net.minecraft.world.level.levelgen.WorldGenSettings;
|
||||
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 com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Dynamic;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.api.WorldDataAPI;
|
||||
import org.betterx.bclib.mixin.common.RegistryOpsAccessor;
|
||||
import org.betterx.bclib.util.ModUtil;
|
||||
import org.betterx.bclib.world.generator.BCLBiomeSource;
|
||||
import org.betterx.bclib.world.generator.BCLibEndBiomeSource;
|
||||
import org.betterx.bclib.world.generator.BCLibNetherBiomeSource;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class WorldGenUtilities {
|
||||
private static final String TAG_VERSION = "version";
|
||||
private static final String TAG_BN_GEN_VERSION = "generator_version";
|
||||
private static String TAG_GENERATOR = "generator";
|
||||
|
||||
@NotNull
|
||||
public static LevelStem getBCLNetherLevelStem(Context context, Optional<Integer> version) {
|
||||
BCLibNetherBiomeSource netherSource = new BCLibNetherBiomeSource(context.biomes, version);
|
||||
return getBCLNetherLevelStem(context, netherSource);
|
||||
}
|
||||
|
||||
public static LevelStem getBCLNetherLevelStem(StemContext context, BiomeSource biomeSource) {
|
||||
return new LevelStem(
|
||||
context.dimension,
|
||||
new BCLChunkGenerator(
|
||||
context.structureSets,
|
||||
context.noiseParameters,
|
||||
biomeSource,
|
||||
context.generatorSettings)
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static LevelStem getBCLEndLevelStem(StemContext context, BiomeSource biomeSource) {
|
||||
return new LevelStem(
|
||||
context.dimension,
|
||||
new BCLChunkGenerator(
|
||||
context.structureSets,
|
||||
context.noiseParameters,
|
||||
biomeSource,
|
||||
context.generatorSettings)
|
||||
);
|
||||
}
|
||||
|
||||
public static LevelStem getBCLEndLevelStem(Context context, Optional<Integer> version) {
|
||||
BCLibEndBiomeSource endSource = new BCLibEndBiomeSource(context.biomes, version);
|
||||
return getBCLEndLevelStem(context, endSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Datapacks can change the world's generator. This Method will ensure, that the Generators contain
|
||||
* the correct BiomeSources for this world
|
||||
*
|
||||
* @param settings
|
||||
* @return
|
||||
*/
|
||||
public static WorldGenSettings fixSettingsInCurrentWorld(Optional<RegistryOps<Tag>> registryOps,
|
||||
WorldGenSettings settings) {
|
||||
if (registryOps.orElse(null) instanceof RegistryOpsAccessor acc) {
|
||||
return getWorldSettings().repairSettingsOnLoad(acc.bcl_getRegistryAccess(), settings);
|
||||
} else {
|
||||
BCLib.LOGGER.error("Unable to obtain registryAccess when enforcing generators.");
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
public static WorldGenSettings createWorldFromPreset(ResourceKey<WorldPreset> preset,
|
||||
RegistryAccess registryAccess,
|
||||
long seed,
|
||||
boolean generateStructures,
|
||||
boolean generateBonusChest) {
|
||||
WorldGenSettings settings = registryAccess
|
||||
.registryOrThrow(Registry.WORLD_PRESET_REGISTRY)
|
||||
.getHolderOrThrow(preset)
|
||||
.value()
|
||||
.createWorldGenSettings(seed, generateStructures, generateBonusChest);
|
||||
|
||||
for (LevelStem stem : settings.dimensions()) {
|
||||
if (stem.generator().getBiomeSource() instanceof BCLBiomeSource bcl) {
|
||||
bcl.setSeed(seed);
|
||||
}
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
public static WorldGenSettings createDefaultWorldFromPreset(RegistryAccess registryAccess,
|
||||
long seed,
|
||||
boolean generateStructures,
|
||||
boolean generateBonusChest) {
|
||||
return createWorldFromPreset(BCLWorldPresets.DEFAULT.orElseThrow(),
|
||||
registryAccess,
|
||||
seed,
|
||||
generateStructures,
|
||||
generateBonusChest);
|
||||
}
|
||||
|
||||
public static Pair<WorldGenSettings, RegistryAccess.Frozen> defaultWorldDataSupplier(RegistryAccess.Frozen frozen) {
|
||||
WorldGenSettings worldGenSettings = createDefaultWorldFromPreset(frozen);
|
||||
return Pair.of(worldGenSettings, frozen);
|
||||
}
|
||||
|
||||
public static WorldGenSettings createDefaultWorldFromPreset(RegistryAccess registryAccess, long seed) {
|
||||
return createDefaultWorldFromPreset(registryAccess, seed, true, false);
|
||||
}
|
||||
|
||||
public static WorldGenSettings createDefaultWorldFromPreset(RegistryAccess registryAccess) {
|
||||
return createDefaultWorldFromPreset(registryAccess, RandomSource.create().nextLong());
|
||||
}
|
||||
|
||||
public static WorldGenSettings replaceGenerator(
|
||||
ResourceKey<LevelStem> dimensionKey,
|
||||
ResourceKey<DimensionType> dimensionTypeKey,
|
||||
int biomeSourceVersion,
|
||||
RegistryAccess registryAccess,
|
||||
WorldGenSettings worldGenSettings
|
||||
) {
|
||||
Optional<Holder<LevelStem>> oLevelStem = referenceStemForVersion(
|
||||
dimensionKey,
|
||||
biomeSourceVersion,
|
||||
registryAccess,
|
||||
worldGenSettings.seed(),
|
||||
worldGenSettings.generateStructures(),
|
||||
worldGenSettings.generateStructures()
|
||||
);
|
||||
return replaceGenerator(dimensionKey,
|
||||
dimensionTypeKey,
|
||||
registryAccess,
|
||||
worldGenSettings,
|
||||
oLevelStem.map(l -> l.value().generator()).orElseThrow());
|
||||
}
|
||||
|
||||
public static WorldGenSettings replaceGenerator(
|
||||
ResourceKey<LevelStem> dimensionKey,
|
||||
ResourceKey<DimensionType> dimensionTypeKey,
|
||||
RegistryAccess registryAccess,
|
||||
WorldGenSettings worldGenSettings,
|
||||
ChunkGenerator generator
|
||||
) {
|
||||
Registry<DimensionType> dimensionTypeRegistry = registryAccess.registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY);
|
||||
Registry<LevelStem> newDimensions = withDimension(dimensionKey,
|
||||
dimensionTypeKey,
|
||||
dimensionTypeRegistry,
|
||||
worldGenSettings.dimensions(),
|
||||
generator);
|
||||
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,
|
||||
ResourceKey<DimensionType> dimensionTypeKey,
|
||||
Registry<DimensionType> dimensionTypeRegistry,
|
||||
Registry<LevelStem> inputDimensions,
|
||||
ChunkGenerator generator) {
|
||||
|
||||
LevelStem levelStem = inputDimensions.get(dimensionKey);
|
||||
Holder<DimensionType> dimensionType = levelStem == null
|
||||
? dimensionTypeRegistry.getOrCreateHolderOrThrow(dimensionTypeKey)
|
||||
: levelStem.typeHolder();
|
||||
return withDimension(dimensionKey, inputDimensions, new LevelStem(dimensionType, generator));
|
||||
}
|
||||
|
||||
public static Registry<LevelStem> withDimension(ResourceKey<LevelStem> dimensionKey,
|
||||
Registry<LevelStem> inputDimensions,
|
||||
LevelStem levelStem) {
|
||||
MappedRegistry<LevelStem> writableRegistry = new MappedRegistry<>(Registry.LEVEL_STEM_REGISTRY,
|
||||
Lifecycle.experimental(),
|
||||
null);
|
||||
writableRegistry.register(dimensionKey,
|
||||
levelStem,
|
||||
Lifecycle.stable());
|
||||
for (Map.Entry<ResourceKey<LevelStem>, LevelStem> entry : inputDimensions.entrySet()) {
|
||||
ResourceKey<LevelStem> resourceKey = entry.getKey();
|
||||
if (resourceKey == dimensionKey) continue;
|
||||
writableRegistry.register(resourceKey,
|
||||
entry.getValue(),
|
||||
inputDimensions.lifecycle(entry.getValue()));
|
||||
}
|
||||
return writableRegistry;
|
||||
}
|
||||
|
||||
public static int getBiomeVersionForGenerator(ChunkGenerator generator) {
|
||||
if (generator == null) return BCLBiomeSource.getVersionBiomeSource(null);
|
||||
return BCLBiomeSource.getVersionBiomeSource(generator.getBiomeSource());
|
||||
}
|
||||
|
||||
public static Optional<Holder<LevelStem>> referenceStemForVersion(
|
||||
ResourceKey<LevelStem> dimensionKey,
|
||||
int biomeSourceVersion,
|
||||
RegistryAccess registryAccess,
|
||||
long seed,
|
||||
boolean generateStructures,
|
||||
boolean generateBonusChest
|
||||
) {
|
||||
final WorldGenSettings referenceSettings;
|
||||
if (biomeSourceVersion == BCLBiomeSource.BIOME_SOURCE_VERSION_VANILLA) {
|
||||
referenceSettings = net.minecraft.world.level.levelgen.presets.WorldPresets.createNormalWorldFromPreset(
|
||||
registryAccess,
|
||||
seed,
|
||||
generateStructures,
|
||||
generateBonusChest);
|
||||
} else if (biomeSourceVersion == BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE) {
|
||||
referenceSettings = createWorldFromPreset(
|
||||
BCLWorldPresets.BCL_WORLD_17,
|
||||
registryAccess,
|
||||
seed,
|
||||
generateStructures,
|
||||
generateBonusChest);
|
||||
} else {
|
||||
referenceSettings = createDefaultWorldFromPreset(
|
||||
registryAccess,
|
||||
seed,
|
||||
generateStructures,
|
||||
generateBonusChest);
|
||||
}
|
||||
return referenceSettings.dimensions().getHolder(dimensionKey);
|
||||
}
|
||||
|
||||
public static int getBiomeVersionForCurrentWorld(ResourceKey<LevelStem> key) {
|
||||
final CompoundTag settingsNbt = 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,
|
||||
ResourceKey<LevelStem> key) {
|
||||
var dimension = settings.dimensions().getHolder(key);
|
||||
if (dimension.isPresent()) {
|
||||
return getBiomeVersionForGenerator(dimension.get().value().generator());
|
||||
} else {
|
||||
return getBiomeVersionForGenerator(null);
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeDimensionVersion(WorldGenSettings settings,
|
||||
CompoundTag generatorSettings,
|
||||
ResourceKey<LevelStem> key) {
|
||||
generatorSettings.putInt(key.location().toString(), getDimensionVersion(settings, key));
|
||||
}
|
||||
|
||||
public static void initializeWorldData(WorldGenSettings settings) {
|
||||
updateWorldData(getDimensionVersion(settings, LevelStem.NETHER), getDimensionVersion(settings, LevelStem.END));
|
||||
}
|
||||
|
||||
public static void updateWorldData(int netherVersion, int endVersion) {
|
||||
BCLWorldPresetSettings worldSettings = new BCLWorldPresetSettings(netherVersion, endVersion);
|
||||
final RegistryAccess registryAccess = RegistryAccess.builtinCopy();
|
||||
final RegistryOps<Tag> registryOps = RegistryOps.create(NbtOps.INSTANCE, registryAccess);
|
||||
final var codec = WorldPresetSettings.CODEC.orElse(worldSettings);
|
||||
final var encodeResult = codec.encodeStart(registryOps, worldSettings);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static CompoundTag getSettingsNbt() {
|
||||
return WorldDataAPI.getCompoundTag(BCLib.TOGETHER_WORLDS, TAG_GENERATOR);
|
||||
}
|
||||
|
||||
public static WorldPresetSettings getWorldSettings() {
|
||||
final RegistryAccess registryAccess = RegistryAccess.builtinCopy();
|
||||
final RegistryOps<Tag> registryOps = RegistryOps.create(NbtOps.INSTANCE, registryAccess);
|
||||
|
||||
Optional<WorldPresetSettings> oLevelStem = WorldPresetSettings.CODEC
|
||||
.parse(new Dynamic<>(registryOps, getSettingsNbt()))
|
||||
.resultOrPartial(BCLib.LOGGER::error);
|
||||
|
||||
return oLevelStem.orElse(BCLWorldPresetSettings.DEFAULT);
|
||||
}
|
||||
|
||||
public static void migrateGeneratorSettings() {
|
||||
final CompoundTag settingsNbt = getSettingsNbt();
|
||||
|
||||
if (settingsNbt.size() == 0) {
|
||||
BCLib.LOGGER.info("Found World without generator Settings. Setting up data...");
|
||||
int biomeSourceVersion = BCLBiomeSource.DEFAULT_BIOME_SOURCE_VERSION;
|
||||
|
||||
final CompoundTag bclRoot = WorldDataAPI.getRootTag(BCLib.MOD_ID);
|
||||
|
||||
String bclVersion = "0.0.0";
|
||||
if (bclRoot.contains(TAG_VERSION)) {
|
||||
bclVersion = bclRoot.getString(TAG_VERSION);
|
||||
}
|
||||
boolean isPre18 = !ModUtil.isLargerOrEqualVersion(bclVersion, "1.0.0");
|
||||
|
||||
if (isPre18) {
|
||||
BCLib.LOGGER.info("World was create pre 1.18!");
|
||||
biomeSourceVersion = BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE;
|
||||
}
|
||||
|
||||
if (WorldDataAPI.hasMod("betternether")) {
|
||||
BCLib.LOGGER.info("Found Data from BetterNether, using for migration.");
|
||||
final CompoundTag bnRoot = WorldDataAPI.getRootTag("betternether");
|
||||
biomeSourceVersion = "1.17".equals(bnRoot.getString(TAG_BN_GEN_VERSION))
|
||||
? BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE
|
||||
: BCLBiomeSource.BIOME_SOURCE_VERSION_HEX;
|
||||
}
|
||||
|
||||
BCLib.LOGGER.info("Set world to BiomeSource Version " + biomeSourceVersion);
|
||||
updateWorldData(biomeSourceVersion, biomeSourceVersion);
|
||||
}
|
||||
}
|
||||
|
||||
public static class StemContext {
|
||||
public final Holder<DimensionType> dimension;
|
||||
public final Registry<StructureSet> structureSets;
|
||||
public final Registry<NormalNoise.NoiseParameters> noiseParameters;
|
||||
public final Holder<NoiseGeneratorSettings> generatorSettings;
|
||||
|
||||
public StemContext(Holder<DimensionType> dimension,
|
||||
Registry<StructureSet> structureSets,
|
||||
Registry<NormalNoise.NoiseParameters> noiseParameters,
|
||||
Holder<NoiseGeneratorSettings> generatorSettings) {
|
||||
this.dimension = dimension;
|
||||
this.structureSets = structureSets;
|
||||
this.noiseParameters = noiseParameters;
|
||||
this.generatorSettings = generatorSettings;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Context extends StemContext {
|
||||
public final Registry<Biome> biomes;
|
||||
|
||||
public Context(Registry<Biome> biomes, Holder<DimensionType> dimension,
|
||||
Registry<StructureSet> structureSets,
|
||||
Registry<NormalNoise.NoiseParameters> noiseParameters,
|
||||
Holder<NoiseGeneratorSettings> generatorSettings) {
|
||||
super(dimension, structureSets, noiseParameters, generatorSettings);
|
||||
this.biomes = biomes;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package org.betterx.bclib.presets.worldgen;
|
||||
|
||||
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.levelgen.WorldGenSettings;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import org.betterx.bclib.BCLib;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public abstract Codec<? extends WorldPresetSettings> codec();
|
||||
public abstract WorldGenSettings repairSettingsOnLoad(RegistryAccess registryAccess, WorldGenSettings settings);
|
||||
}
|
|
@ -1,287 +0,0 @@
|
|||
package org.betterx.bclib.presets.worldgen;
|
||||
|
||||
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.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.WorldPresetTags;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
|
||||
import net.minecraft.world.level.levelgen.WorldGenSettings;
|
||||
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 com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.api.tag.TagAPI;
|
||||
import org.betterx.bclib.api.tag.TagType;
|
||||
import org.betterx.bclib.interfaces.ChunkGeneratorAccessor;
|
||||
import org.betterx.bclib.interfaces.NoiseGeneratorSettingsProvider;
|
||||
import org.betterx.bclib.world.generator.BCLBiomeSource;
|
||||
import org.betterx.bclib.world.generator.BCLibEndBiomeSource;
|
||||
import org.betterx.bclib.world.generator.BCLibNetherBiomeSource;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class WorldPresets {
|
||||
@NotNull
|
||||
public static LevelStem getBCLNetherLevelStem(Registry<Biome> biomes,
|
||||
Holder<DimensionType> dimension,
|
||||
Registry<StructureSet> structureSets,
|
||||
Registry<NormalNoise.NoiseParameters> noiseParameters,
|
||||
Holder<NoiseGeneratorSettings> generatorSettings,
|
||||
Optional<Integer> version) {
|
||||
BCLibNetherBiomeSource netherSource = new BCLibNetherBiomeSource(biomes, version);
|
||||
LevelStem bclNether = new LevelStem(
|
||||
dimension,
|
||||
new BCLChunkGenerator(
|
||||
structureSets,
|
||||
noiseParameters,
|
||||
netherSource,
|
||||
generatorSettings)
|
||||
);
|
||||
return bclNether;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static LevelStem getBCLEndLevelStem(Registry<Biome> biomes,
|
||||
Holder<DimensionType> dimension,
|
||||
Registry<StructureSet> structureSets,
|
||||
Registry<NormalNoise.NoiseParameters> noiseParameters,
|
||||
Holder<NoiseGeneratorSettings> generatorSettings,
|
||||
Optional<Integer> version) {
|
||||
BCLibEndBiomeSource netherSource = new BCLibEndBiomeSource(biomes, version);
|
||||
LevelStem bclEnd = new LevelStem(
|
||||
dimension,
|
||||
new BCLChunkGenerator(
|
||||
structureSets,
|
||||
noiseParameters,
|
||||
netherSource,
|
||||
generatorSettings)
|
||||
);
|
||||
return bclEnd;
|
||||
}
|
||||
|
||||
public static class SortableWorldPreset extends WorldPreset {
|
||||
public final int sortOrder;
|
||||
|
||||
public SortableWorldPreset(Map<ResourceKey<LevelStem>, LevelStem> map, int sortOrder) {
|
||||
super(map);
|
||||
this.sortOrder = sortOrder;
|
||||
}
|
||||
}
|
||||
|
||||
public static final TagType.Simple<WorldPreset> WORLD_PRESETS =
|
||||
TagAPI.registerType(BuiltinRegistries.WORLD_PRESET, "tags/worldgen/world_preset");
|
||||
|
||||
public static final ResourceKey<WorldPreset> BCL_WORLD = register(BCLib.makeID("normal"));
|
||||
public static final ResourceKey<WorldPreset> BCL_WORLD_17 = register(BCLib.makeID("legacy_17"), false);
|
||||
|
||||
public static Optional<ResourceKey<WorldPreset>> DEFAULT = Optional.of(BCL_WORLD);
|
||||
|
||||
public static WorldGenSettings createWorldFromPreset(ResourceKey<WorldPreset> preset,
|
||||
RegistryAccess registryAccess,
|
||||
long seed,
|
||||
boolean generateStructures,
|
||||
boolean generateBonusChest) {
|
||||
WorldGenSettings settings = registryAccess
|
||||
.registryOrThrow(Registry.WORLD_PRESET_REGISTRY)
|
||||
.getHolderOrThrow(preset)
|
||||
.value()
|
||||
.createWorldGenSettings(seed, generateStructures, generateBonusChest);
|
||||
|
||||
for (LevelStem stem : settings.dimensions()) {
|
||||
if (stem.generator().getBiomeSource() instanceof BCLBiomeSource bcl) {
|
||||
bcl.setSeed(seed);
|
||||
}
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
public static WorldGenSettings createDefaultWorldFromPreset(RegistryAccess registryAccess,
|
||||
long seed,
|
||||
boolean generateStructures,
|
||||
boolean generateBonusChest) {
|
||||
return createWorldFromPreset(DEFAULT.orElseThrow(),
|
||||
registryAccess,
|
||||
seed,
|
||||
generateStructures,
|
||||
generateBonusChest);
|
||||
}
|
||||
|
||||
public static Pair<WorldGenSettings, RegistryAccess.Frozen> defaultWorldDataSupplier(RegistryAccess.Frozen frozen) {
|
||||
WorldGenSettings worldGenSettings = createDefaultWorldFromPreset(frozen);
|
||||
return Pair.of(worldGenSettings, frozen);
|
||||
}
|
||||
|
||||
public static WorldGenSettings createDefaultWorldFromPreset(RegistryAccess registryAccess, long seed) {
|
||||
return createDefaultWorldFromPreset(registryAccess, seed, true, false);
|
||||
}
|
||||
|
||||
public static WorldGenSettings createDefaultWorldFromPreset(RegistryAccess registryAccess) {
|
||||
return createDefaultWorldFromPreset(registryAccess, RandomSource.create().nextLong());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public static WorldGenSettings fixSettingsInCurrentWorld(ResourceKey<LevelStem> dimensionKey,
|
||||
ResourceKey<DimensionType> dimensionTypeKey,
|
||||
WorldGenSettings settings) {
|
||||
var oldNether = settings.dimensions().getHolder(dimensionKey);
|
||||
int loaderVersion = BCLChunkGenerator.getBiomeVersionForGenerator(oldNether
|
||||
.map(h -> h.value().generator())
|
||||
.orElse(null));
|
||||
|
||||
int targetVersion = BCLChunkGenerator.getBiomeVersionForCurrentWorld(dimensionKey);
|
||||
if (loaderVersion != targetVersion) {
|
||||
BCLib.LOGGER.info("Enforcing Correct Generator for " + dimensionKey.location().toString() + ".");
|
||||
var chunkGenerator = oldNether.map(h -> h.value().generator()).orElse(null);
|
||||
RegistryAccess access = RegistryAccess.builtinCopy();
|
||||
Optional<Holder<LevelStem>> refLevelStem = BCLChunkGenerator.referenceStemForVersion(
|
||||
dimensionKey,
|
||||
targetVersion,
|
||||
access,
|
||||
settings.seed(),
|
||||
settings.generateStructures(),
|
||||
settings.generateStructures()
|
||||
);
|
||||
|
||||
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 (chunkGenerator instanceof ChunkGeneratorAccessor generator) {
|
||||
if (chunkGenerator instanceof NoiseGeneratorSettingsProvider noiseProvider) {
|
||||
//TODO: Make sure our BiomeSource reuses the BiomeList from the Datapack Source
|
||||
referenceGenerator = new BCLChunkGenerator(generator.bclib_getStructureSetsRegistry(),
|
||||
noiseProvider.bclib_getNoises(),
|
||||
referenceGenerator.getBiomeSource(),
|
||||
noiseProvider.bclib_getNoiseGeneratorSettingHolders());
|
||||
}
|
||||
}
|
||||
|
||||
return WorldPresets.replaceGenerator(dimensionKey,
|
||||
dimensionTypeKey,
|
||||
access,
|
||||
settings,
|
||||
referenceGenerator);
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
public static WorldGenSettings replaceGenerator(
|
||||
ResourceKey<LevelStem> dimensionKey,
|
||||
ResourceKey<DimensionType> dimensionTypeKey,
|
||||
int biomeSourceVersion,
|
||||
RegistryAccess registryAccess,
|
||||
WorldGenSettings worldGenSettings
|
||||
) {
|
||||
Optional<Holder<LevelStem>> oLevelStem = BCLChunkGenerator.referenceStemForVersion(
|
||||
dimensionKey,
|
||||
biomeSourceVersion,
|
||||
registryAccess,
|
||||
worldGenSettings.seed(),
|
||||
worldGenSettings.generateStructures(),
|
||||
worldGenSettings.generateStructures()
|
||||
);
|
||||
return replaceGenerator(dimensionKey,
|
||||
dimensionTypeKey,
|
||||
registryAccess,
|
||||
worldGenSettings,
|
||||
oLevelStem.map(l -> l.value().generator()).orElseThrow());
|
||||
}
|
||||
|
||||
public static WorldGenSettings replaceGenerator(
|
||||
ResourceKey<LevelStem> dimensionKey,
|
||||
ResourceKey<DimensionType> dimensionTypeKey,
|
||||
RegistryAccess registryAccess,
|
||||
WorldGenSettings worldGenSettings,
|
||||
ChunkGenerator generator
|
||||
) {
|
||||
Registry<DimensionType> registry = registryAccess.registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY);
|
||||
Registry<LevelStem> registry2 = withDimension(dimensionKey, dimensionTypeKey, registry,
|
||||
worldGenSettings.dimensions(),
|
||||
generator);
|
||||
return new WorldGenSettings(worldGenSettings.seed(),
|
||||
worldGenSettings.generateStructures(),
|
||||
worldGenSettings.generateBonusChest(),
|
||||
registry2);
|
||||
}
|
||||
|
||||
public static Registry<LevelStem> withDimension(ResourceKey<LevelStem> dimensionKey,
|
||||
ResourceKey<DimensionType> dimensionTypeKey,
|
||||
Registry<DimensionType> registry,
|
||||
Registry<LevelStem> registry2,
|
||||
ChunkGenerator chunkGenerator) {
|
||||
LevelStem levelStem = registry2.get(dimensionKey);
|
||||
Holder<DimensionType> holder = levelStem == null
|
||||
? registry.getOrCreateHolderOrThrow(dimensionTypeKey)
|
||||
: levelStem.typeHolder();
|
||||
return withDimension(dimensionKey, registry2, holder, chunkGenerator);
|
||||
}
|
||||
|
||||
public static Registry<LevelStem> withDimension(ResourceKey<LevelStem> dimensionKey, Registry<LevelStem> registry,
|
||||
Holder<DimensionType> holder,
|
||||
ChunkGenerator chunkGenerator) {
|
||||
MappedRegistry<LevelStem> writableRegistry = new MappedRegistry<LevelStem>(Registry.LEVEL_STEM_REGISTRY,
|
||||
Lifecycle.experimental(),
|
||||
null);
|
||||
writableRegistry.register(dimensionKey,
|
||||
new LevelStem(holder, chunkGenerator),
|
||||
Lifecycle.stable());
|
||||
for (Map.Entry<ResourceKey<LevelStem>, LevelStem> entry : registry.entrySet()) {
|
||||
ResourceKey<LevelStem> resourceKey = entry.getKey();
|
||||
if (resourceKey == dimensionKey) continue;
|
||||
writableRegistry.register(resourceKey,
|
||||
entry.getValue(),
|
||||
registry.lifecycle(entry.getValue()));
|
||||
}
|
||||
return writableRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public 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() {
|
||||
}
|
||||
}
|
|
@ -56,7 +56,7 @@ public class ModUtil {
|
|||
|
||||
private static ModMetadata readJSON(InputStream is, String sourceFile) throws IOException {
|
||||
try (com.google.gson.stream.JsonReader reader = new JsonReader(new InputStreamReader(is,
|
||||
StandardCharsets.UTF_8))) {
|
||||
StandardCharsets.UTF_8))) {
|
||||
JsonObject data = new JsonParser().parse(reader)
|
||||
.getAsJsonObject();
|
||||
Version ver;
|
||||
|
@ -261,6 +261,8 @@ public class ModUtil {
|
|||
* @return The version of the locally installed Mod
|
||||
*/
|
||||
public static String getModVersion(String modID) {
|
||||
if (modID == BCLib.TOGETHER_WORLDS) modID = BCLib.MOD_ID;
|
||||
|
||||
Optional<ModContainer> optional = FabricLoader.getInstance()
|
||||
.getModContainer(modID);
|
||||
if (optional.isPresent()) {
|
||||
|
|
|
@ -232,8 +232,8 @@ public class BCLBiome extends BCLBiomeSettings {
|
|||
public void afterRegistration() {
|
||||
if (!this.structureTags.isEmpty()) {
|
||||
structureTags.forEach(tagKey ->
|
||||
TagAPI.addBiomeTag(tagKey, biome)
|
||||
);
|
||||
TagAPI.addBiomeTag(tagKey, biome)
|
||||
);
|
||||
}
|
||||
|
||||
if (this.surfaceInit != null) {
|
||||
|
@ -358,4 +358,13 @@ public class BCLBiome extends BCLBiomeSettings {
|
|||
}
|
||||
|
||||
private final boolean didLoadConfig = false;
|
||||
|
||||
public boolean isEdgeBiome() {
|
||||
if (getParentBiome() == null) return false;
|
||||
return getParentBiome().edge == this;
|
||||
}
|
||||
|
||||
public boolean allowFabricRegistration() {
|
||||
return !isEdgeBiome();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,13 +2,16 @@ package org.betterx.bclib.world.generator;
|
|||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.betterx.bclib.api.biomes.BiomeAPI;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class BCLBiomeSource extends BiomeSource {
|
||||
public static int BIOME_SOURCE_VERSION_NONE = -1;
|
||||
|
@ -66,4 +69,34 @@ public abstract class BCLBiomeSource extends BiomeSource {
|
|||
return BCLBiomeSource.BIOME_SOURCE_VERSION_VANILLA;
|
||||
}
|
||||
}
|
||||
|
||||
public BCLBiomeSource createCopyForDatapack(Set<Holder<Biome>> datapackBiomes) {
|
||||
Set<Holder<Biome>> mutableSet = Sets.newHashSet();
|
||||
mutableSet.addAll(datapackBiomes);
|
||||
return cloneForDatapack(mutableSet);
|
||||
}
|
||||
|
||||
protected abstract BCLBiomeSource cloneForDatapack(Set<Holder<Biome>> datapackBiomes);
|
||||
|
||||
public interface ValidBiomePredicate {
|
||||
boolean isValid(Holder<Biome> biome, ResourceLocation location);
|
||||
}
|
||||
|
||||
protected static List<Holder<Biome>> getBiomes(Registry<Biome> biomeRegistry,
|
||||
List<String> exclude,
|
||||
List<String> include,
|
||||
BCLibNetherBiomeSource.ValidBiomePredicate test) {
|
||||
return biomeRegistry.stream()
|
||||
.filter(biome -> biomeRegistry.getResourceKey(biome).isPresent())
|
||||
.map(biome -> biomeRegistry.getOrCreateHolderOrThrow(biomeRegistry.getResourceKey(biome)
|
||||
.get()))
|
||||
.filter(biome -> {
|
||||
ResourceLocation location = biome.unwrapKey().orElseThrow().location();
|
||||
final String strLocation = location.toString();
|
||||
if (exclude.contains(strLocation)) return false;
|
||||
if (include.contains(strLocation)) return true;
|
||||
|
||||
return test.isValid(biome, location);
|
||||
}).toList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,8 +27,10 @@ import org.betterx.bclib.world.generator.map.hex.HexBiomeMap;
|
|||
import org.betterx.bclib.world.generator.map.square.SquareBiomeMap;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class BCLibEndBiomeSource extends BCLBiomeSource {
|
||||
|
@ -72,7 +74,15 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
|
|||
}
|
||||
|
||||
private BCLibEndBiomeSource(Registry<Biome> biomeRegistry, long seed, Optional<Integer> version, boolean initMaps) {
|
||||
super(biomeRegistry, getBiomes(biomeRegistry), seed, version);
|
||||
this(biomeRegistry, getBiomes(biomeRegistry), seed, version, initMaps);
|
||||
}
|
||||
|
||||
private BCLibEndBiomeSource(Registry<Biome> biomeRegistry,
|
||||
List<Holder<Biome>> list,
|
||||
long seed,
|
||||
Optional<Integer> version,
|
||||
boolean initMaps) {
|
||||
super(biomeRegistry, list, seed, version);
|
||||
|
||||
endLandBiomePicker = new BiomePicker(biomeRegistry);
|
||||
endVoidBiomePicker = new BiomePicker(biomeRegistry);
|
||||
|
@ -122,39 +132,47 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
|
|||
}
|
||||
}
|
||||
|
||||
private static List<Holder<Biome>> getBiomes(Registry<Biome> biomeRegistry) {
|
||||
List<String> includeLand = Configs.BIOMES_CONFIG.getEntry("force_include",
|
||||
protected BCLBiomeSource cloneForDatapack(Set<Holder<Biome>> datapackBiomes) {
|
||||
datapackBiomes.addAll(getBclBiomes(this.biomeRegistry));
|
||||
return new BCLibEndBiomeSource(this.biomeRegistry,
|
||||
datapackBiomes.stream().toList(),
|
||||
this.currentSeed,
|
||||
Optional.of(biomeSourceVersion),
|
||||
true);
|
||||
}
|
||||
|
||||
private static List<Holder<Biome>> getBclBiomes(Registry<Biome> biomeRegistry) {
|
||||
List<String> include = Configs.BIOMES_CONFIG.getEntry("force_include",
|
||||
"end_land_biomes",
|
||||
StringArrayEntry.class).getValue();
|
||||
List<String> includeVoid = Configs.BIOMES_CONFIG.getEntry("force_include",
|
||||
include.addAll(Configs.BIOMES_CONFIG.getEntry("force_include",
|
||||
"end_void_biomes",
|
||||
StringArrayEntry.class).getValue());
|
||||
|
||||
return getBiomes(biomeRegistry, new ArrayList<>(0), include, BCLibEndBiomeSource::isValidBCLEndBiome);
|
||||
}
|
||||
|
||||
private static List<Holder<Biome>> getBiomes(Registry<Biome> biomeRegistry) {
|
||||
List<String> include = Configs.BIOMES_CONFIG.getEntry("force_include",
|
||||
"end_land_biomes",
|
||||
StringArrayEntry.class).getValue();
|
||||
include.addAll(Configs.BIOMES_CONFIG.getEntry("force_include",
|
||||
"end_void_biomes",
|
||||
StringArrayEntry.class).getValue());
|
||||
|
||||
return biomeRegistry.stream()
|
||||
.filter(biome -> biomeRegistry.getResourceKey(biome).isPresent())
|
||||
.map(biome -> biomeRegistry.getOrCreateHolderOrThrow(biomeRegistry.getResourceKey(biome)
|
||||
.get()))
|
||||
.filter(biome -> {
|
||||
ResourceLocation key = biome.unwrapKey().orElseThrow().location();
|
||||
return getBiomes(biomeRegistry, new ArrayList<>(0), include, BCLibEndBiomeSource::isValidEndBiome);
|
||||
}
|
||||
|
||||
|
||||
if (includeLand.contains(key.toString()) || includeVoid.contains(key.toString())) {
|
||||
return true;
|
||||
}
|
||||
private static boolean isValidEndBiome(Holder<Biome> biome, ResourceLocation location) {
|
||||
return biome.is(BiomeTags.IS_END) ||
|
||||
BiomeAPI.wasRegisteredAsEndBiome(location);
|
||||
}
|
||||
|
||||
final boolean isEndBiome = biome.is(BiomeTags.IS_END) ||
|
||||
BiomeAPI.wasRegisteredAsEndBiome(key);
|
||||
|
||||
|
||||
BCLBiome bclBiome = BiomeAPI.getBiome(key);
|
||||
if (bclBiome != BiomeAPI.EMPTY_BIOME) {
|
||||
if (bclBiome.getParentBiome() != null) {
|
||||
bclBiome = bclBiome.getParentBiome();
|
||||
}
|
||||
key = bclBiome.getID();
|
||||
}
|
||||
return isEndBiome;
|
||||
}).toList();
|
||||
private static boolean isValidBCLEndBiome(Holder<Biome> biome, ResourceLocation location) {
|
||||
return biome.is(BiomeTags.IS_END) ||
|
||||
BiomeAPI.wasRegisteredAs(location, BiomeAPI.Dimension.BCL_END_LAND) ||
|
||||
BiomeAPI.wasRegisteredAs(location, BiomeAPI.Dimension.BCL_END_VOID);
|
||||
}
|
||||
|
||||
public static float getLegacyHeightValue(SimplexNoise simplexNoise, int i, int j) {
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.betterx.bclib.world.generator.map.square.SquareBiomeMap;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public class BCLibNetherBiomeSource extends BCLBiomeSource {
|
||||
private static int lastWorldHeight;
|
||||
|
@ -65,7 +66,15 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
|
|||
long seed,
|
||||
Optional<Integer> version,
|
||||
boolean initMaps) {
|
||||
super(biomeRegistry, getBiomes(biomeRegistry), seed, version);
|
||||
this(biomeRegistry, getBiomes(biomeRegistry), seed, version, initMaps);
|
||||
}
|
||||
|
||||
private BCLibNetherBiomeSource(Registry<Biome> biomeRegistry,
|
||||
List<Holder<Biome>> list,
|
||||
long seed,
|
||||
Optional<Integer> version,
|
||||
boolean initMaps) {
|
||||
super(biomeRegistry, list, seed, version);
|
||||
|
||||
biomePicker = new BiomePicker(biomeRegistry);
|
||||
|
||||
|
@ -77,6 +86,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
|
|||
biomePicker.addBiome(bclBiome);
|
||||
} else {
|
||||
BCLBiome bclBiome = BiomeAPI.getBiome(key);
|
||||
|
||||
if (bclBiome != BiomeAPI.EMPTY_BIOME) {
|
||||
if (bclBiome.getParentBiome() == null) {
|
||||
biomePicker.addBiome(bclBiome);
|
||||
|
@ -91,6 +101,15 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
|
|||
}
|
||||
}
|
||||
|
||||
protected BCLBiomeSource cloneForDatapack(Set<Holder<Biome>> datapackBiomes) {
|
||||
datapackBiomes.addAll(getBclBiomes(this.biomeRegistry));
|
||||
return new BCLibNetherBiomeSource(this.biomeRegistry,
|
||||
datapackBiomes.stream().toList(),
|
||||
this.currentSeed,
|
||||
Optional.of(biomeSourceVersion),
|
||||
true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set world height, used when Nether is larger than vanilla 128 blocks tall.
|
||||
*
|
||||
|
@ -100,27 +119,34 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
|
|||
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();
|
||||
List<String> exclude = Configs.BIOMES_CONFIG.getEntry("force_exclude", "nether_biomes", StringArrayEntry.class)
|
||||
.getValue();
|
||||
|
||||
return getBiomes(biomeRegistry, exclude, include, BCLibNetherBiomeSource::isValidBCLNetherBiome);
|
||||
}
|
||||
|
||||
|
||||
private static List<Holder<Biome>> getBiomes(Registry<Biome> biomeRegistry) {
|
||||
List<String> include = Configs.BIOMES_CONFIG.getEntry("force_include", "nether_biomes", StringArrayEntry.class)
|
||||
.getValue();
|
||||
List<String> exclude = Configs.BIOMES_CONFIG.getEntry("force_exclude", "nether_biomes", StringArrayEntry.class)
|
||||
.getValue();
|
||||
|
||||
return biomeRegistry.stream()
|
||||
.filter(biome -> biomeRegistry.getResourceKey(biome).isPresent())
|
||||
.map(biome -> biomeRegistry.getOrCreateHolderOrThrow(biomeRegistry.getResourceKey(biome)
|
||||
.get()))
|
||||
.filter(biome -> {
|
||||
ResourceLocation location = biome.unwrapKey().orElseThrow().location();
|
||||
final String strLocation = location.toString();
|
||||
if (exclude.contains(strLocation)) return false;
|
||||
if (include.contains(strLocation)) return true;
|
||||
return getBiomes(biomeRegistry, exclude, include, BCLibNetherBiomeSource::isValidNetherBiome);
|
||||
}
|
||||
|
||||
return
|
||||
NetherBiomeData.canGenerateInNether(biome.unwrapKey().get()) ||
|
||||
biome.is(BiomeTags.IS_NETHER) ||
|
||||
BiomeAPI.wasRegisteredAsNetherBiome(location);
|
||||
}).toList();
|
||||
|
||||
private static boolean isValidNetherBiome(Holder<Biome> biome, ResourceLocation location) {
|
||||
return NetherBiomeData.canGenerateInNether(biome.unwrapKey().get()) ||
|
||||
biome.is(BiomeTags.IS_NETHER) ||
|
||||
BiomeAPI.wasRegisteredAsNetherBiome(location);
|
||||
}
|
||||
|
||||
private static boolean isValidBCLNetherBiome(Holder<Biome> biome, ResourceLocation location) {
|
||||
return BiomeAPI.wasRegisteredAs(location, BiomeAPI.Dimension.BCL_NETHER);
|
||||
}
|
||||
|
||||
public static <T> void debug(Object el, Registry<T> reg) {
|
||||
|
|
|
@ -18,6 +18,53 @@ import java.util.Objects;
|
|||
|
||||
public class BiomePicker {
|
||||
public final Map<BCLBiome, ActualBiome> all = new HashMap<>();
|
||||
public final Registry<Biome> biomeRegistry;
|
||||
private final List<ActualBiome> biomes = Lists.newArrayList();
|
||||
private final List<String> allowedBiomes;
|
||||
private WeighTree<ActualBiome> tree;
|
||||
|
||||
public BiomePicker(Registry<Biome> biomeRegistry) {
|
||||
this(biomeRegistry, null);
|
||||
}
|
||||
|
||||
public BiomePicker(Registry<Biome> biomeRegistry, List<Holder<Biome>> allowedBiomes) {
|
||||
this.biomeRegistry = biomeRegistry;
|
||||
this.allowedBiomes = allowedBiomes != null ? allowedBiomes
|
||||
.stream()
|
||||
.map(h -> h.unwrapKey())
|
||||
.filter(o -> o.isPresent())
|
||||
.map(o -> o.get().location().toString()).toList() : null;
|
||||
}
|
||||
|
||||
private boolean isAllowed(BCLBiome b) {
|
||||
if (allowedBiomes == null) return true;
|
||||
return allowedBiomes.contains(b.getID().toString());
|
||||
}
|
||||
|
||||
private ActualBiome create(BCLBiome bclBiome) {
|
||||
ActualBiome e = all.get(bclBiome);
|
||||
if (e != null) return e;
|
||||
return new ActualBiome(bclBiome);
|
||||
}
|
||||
|
||||
public void addBiome(BCLBiome biome) {
|
||||
biomes.add(create(biome));
|
||||
}
|
||||
|
||||
public ActualBiome getBiome(WorldgenRandom random) {
|
||||
return biomes.isEmpty() ? null : tree.get(random);
|
||||
}
|
||||
|
||||
public void rebuild() {
|
||||
if (biomes.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
WeightedList<ActualBiome> list = new WeightedList<>();
|
||||
biomes.forEach(biome -> {
|
||||
list.add(biome, biome.bclBiome.getGenChance());
|
||||
});
|
||||
tree = new WeighTree<>(list);
|
||||
}
|
||||
|
||||
public class ActualBiome {
|
||||
public final BCLBiome bclBiome;
|
||||
|
@ -36,10 +83,16 @@ public class BiomePicker {
|
|||
this.biome = biomeRegistry.getOrCreateHolderOrThrow(key);
|
||||
|
||||
bclBiome.forEachSubBiome((b, w) -> {
|
||||
subbiomes.add(create(b), w);
|
||||
if (isAllowed(b))
|
||||
subbiomes.add(create(b), w);
|
||||
});
|
||||
|
||||
edge = bclBiome.getEdge() != null ? create(bclBiome.getEdge()) : null;
|
||||
if (bclBiome.getEdge() != null && isAllowed(bclBiome.getEdge())) {
|
||||
edge = create(bclBiome.getEdge());
|
||||
} else {
|
||||
edge = null;
|
||||
}
|
||||
|
||||
parent = bclBiome.getParentBiome() != null ? create(bclBiome.getParentBiome()) : null;
|
||||
}
|
||||
|
||||
|
@ -72,37 +125,4 @@ public class BiomePicker {
|
|||
return bclBiome.isSame(e.bclBiome);
|
||||
}
|
||||
}
|
||||
|
||||
private ActualBiome create(BCLBiome bclBiome) {
|
||||
ActualBiome e = all.get(bclBiome);
|
||||
if (e != null) return e;
|
||||
return new ActualBiome(bclBiome);
|
||||
}
|
||||
|
||||
private final List<ActualBiome> biomes = Lists.newArrayList();
|
||||
public final Registry<Biome> biomeRegistry;
|
||||
private WeighTree<ActualBiome> tree;
|
||||
|
||||
public BiomePicker(Registry<Biome> biomeRegistry) {
|
||||
this.biomeRegistry = biomeRegistry;
|
||||
}
|
||||
|
||||
public void addBiome(BCLBiome biome) {
|
||||
biomes.add(create(biome));
|
||||
}
|
||||
|
||||
public ActualBiome getBiome(WorldgenRandom random) {
|
||||
return biomes.isEmpty() ? null : tree.get(random);
|
||||
}
|
||||
|
||||
public void rebuild() {
|
||||
if (biomes.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
WeightedList<ActualBiome> list = new WeightedList<>();
|
||||
biomes.forEach(biome -> {
|
||||
list.add(biome, biome.bclBiome.getGenChance());
|
||||
});
|
||||
tree = new WeighTree<>(list);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
"MainMixin",
|
||||
"MinecraftServerMixin",
|
||||
"MobSpawnSettingsAccessor",
|
||||
"MultiPackResourceManagerMixin",
|
||||
"NetherBiomeDataMixin",
|
||||
"NoiseBasedChunkGeneratorMixin",
|
||||
"NoiseGeneratorSettingsMixin",
|
||||
|
@ -34,6 +33,7 @@
|
|||
"PrimaryLevelDataMixin",
|
||||
"RecipeManagerAccessor",
|
||||
"RecipeManagerMixin",
|
||||
"RegistryOpsAccessor",
|
||||
"ServerLevelMixin",
|
||||
"ShovelItemAccessor",
|
||||
"StructuresAccessor",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue