Make sure all dimensions get checked for new surface rules
This commit is contained in:
parent
bdf30109f6
commit
9e4931e1af
4 changed files with 42 additions and 31 deletions
|
@ -26,8 +26,7 @@ import net.minecraft.world.level.block.state.BlockState;
|
|||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.chunk.PalettedContainer;
|
||||
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.GenerationStep.Decoration;
|
||||
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
||||
|
@ -53,7 +52,6 @@ import org.betterx.bclib.interfaces.BiomeSourceAccessor;
|
|||
import org.betterx.bclib.interfaces.NoiseGeneratorSettingsProvider;
|
||||
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
|
||||
import org.betterx.bclib.interfaces.SurfaceRuleProvider;
|
||||
import org.betterx.bclib.mixin.client.MinecraftMixin;
|
||||
import org.betterx.bclib.mixin.common.BiomeGenerationSettingsAccessor;
|
||||
import org.betterx.bclib.mixin.common.MobSpawnSettingsAccessor;
|
||||
import org.betterx.bclib.util.CollectionsUtil;
|
||||
|
@ -125,9 +123,8 @@ public class BiomeAPI {
|
|||
private static final Map<Holder<PlacedFeature>, Integer> FEATURE_ORDER = Maps.newHashMap();
|
||||
private static final MutableInt FEATURE_ORDER_ID = new MutableInt(0);
|
||||
|
||||
private static final Map<ResourceKey<DimensionType>, List<BiConsumer<ResourceLocation, Holder<Biome>>>> MODIFICATIONS = Maps.newHashMap();
|
||||
private static final Map<ResourceKey<LevelStem>, List<BiConsumer<ResourceLocation, Holder<Biome>>>> MODIFICATIONS = Maps.newHashMap();
|
||||
private static final Map<ResourceKey, List<BiConsumer<ResourceLocation, Holder<Biome>>>> TAG_ADDERS = Maps.newHashMap();
|
||||
private static final Set<SurfaceRuleProvider> MODIFIED_SURFACE_PROVIDERS = new HashSet<>(8);
|
||||
|
||||
public static final BCLBiome NETHER_WASTES_BIOME = registerNetherBiome(getFromRegistry(Biomes.NETHER_WASTES).value());
|
||||
public static final BCLBiome CRIMSON_FOREST_BIOME = registerNetherBiome(getFromRegistry(Biomes.CRIMSON_FOREST).value());
|
||||
|
@ -183,12 +180,10 @@ public class BiomeAPI {
|
|||
/**
|
||||
* For internal use only.
|
||||
* <p>
|
||||
* This method gets called before a world is loaded/created to flush cashes we build. The Method is
|
||||
* called from {@link MinecraftMixin}
|
||||
* This method gets called before a world is loaded/created to flush cashes we build.
|
||||
*/
|
||||
public static void prepareNewLevel() {
|
||||
MODIFIED_SURFACE_PROVIDERS.forEach(p -> p.bclib_clearBiomeSources());
|
||||
MODIFIED_SURFACE_PROVIDERS.clear();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -559,7 +554,7 @@ public class BiomeAPI {
|
|||
* @param dimensionID {@link ResourceLocation} dimension ID, example: Level.OVERWORLD or "minecraft:overworld".
|
||||
* @param modification {@link BiConsumer} with {@link ResourceKey} biome ID and {@link Biome} parameters.
|
||||
*/
|
||||
public static void registerBiomeModification(ResourceKey<DimensionType> dimensionID,
|
||||
public static void registerBiomeModification(ResourceKey<LevelStem> dimensionID,
|
||||
BiConsumer<ResourceLocation, Holder<Biome>> modification) {
|
||||
List<BiConsumer<ResourceLocation, Holder<Biome>>> modifications = MODIFICATIONS.computeIfAbsent(dimensionID,
|
||||
k -> Lists.newArrayList());
|
||||
|
@ -572,7 +567,7 @@ public class BiomeAPI {
|
|||
* @param modification {@link BiConsumer} with {@link ResourceLocation} biome ID and {@link Biome} parameters.
|
||||
*/
|
||||
public static void registerOverworldBiomeModification(BiConsumer<ResourceLocation, Holder<Biome>> modification) {
|
||||
registerBiomeModification(BuiltinDimensionTypes.OVERWORLD, modification);
|
||||
registerBiomeModification(LevelStem.OVERWORLD, modification);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -581,7 +576,7 @@ public class BiomeAPI {
|
|||
* @param modification {@link BiConsumer} with {@link ResourceLocation} biome ID and {@link Biome} parameters.
|
||||
*/
|
||||
public static void registerNetherBiomeModification(BiConsumer<ResourceLocation, Holder<Biome>> modification) {
|
||||
registerBiomeModification(BuiltinDimensionTypes.NETHER, modification);
|
||||
registerBiomeModification(LevelStem.NETHER, modification);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -590,7 +585,7 @@ public class BiomeAPI {
|
|||
* @param modification {@link BiConsumer} with {@link ResourceLocation} biome ID and {@link Biome} parameters.
|
||||
*/
|
||||
public static void registerEndBiomeModification(BiConsumer<ResourceLocation, Holder<Biome>> modification) {
|
||||
registerBiomeModification(BuiltinDimensionTypes.END, modification);
|
||||
registerBiomeModification(LevelStem.END, modification);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -695,7 +690,7 @@ public class BiomeAPI {
|
|||
// Provided by all the BiomeSources that use the same generator.
|
||||
// This happens for example when using the MiningDimensions, which reuses the generator for the
|
||||
// Nethering Dimension
|
||||
MODIFIED_SURFACE_PROVIDERS.add(provider);
|
||||
//MODIFIED_SURFACE_PROVIDERS.add(provider);
|
||||
provider.bclib_addBiomeSource(source);
|
||||
} else {
|
||||
BCLib.LOGGER.warning("No generator for " + source);
|
||||
|
@ -704,7 +699,7 @@ public class BiomeAPI {
|
|||
((BiomeSourceAccessor) source).bclRebuildFeatures();
|
||||
}
|
||||
|
||||
public static void applyModifications(BiomeSource source, ResourceKey<DimensionType> dimension) {
|
||||
public static void applyModifications(BiomeSource source, ResourceKey<LevelStem> dimension) {
|
||||
BCLib.LOGGER.info("Apply Modifications for " + dimension.location() + " BiomeSource " + source);
|
||||
final Set<Holder<Biome>> biomes = source.possibleBiomes();
|
||||
List<BiConsumer<ResourceLocation, Holder<Biome>>> modifications = MODIFICATIONS.get(dimension);
|
||||
|
|
|
@ -6,8 +6,6 @@ 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.BuiltinDimensionTypes;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator;
|
||||
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
|
||||
|
@ -22,7 +20,9 @@ import org.betterx.bclib.api.biomes.BiomeAPI;
|
|||
import org.betterx.bclib.interfaces.NoiseGeneratorSettingsProvider;
|
||||
import org.betterx.bclib.interfaces.SurfaceRuleProvider;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class BCLChunkGenerator extends NoiseBasedChunkGenerator {
|
||||
|
||||
|
@ -59,23 +59,14 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator {
|
|||
}
|
||||
|
||||
public static void injectNoiseSettings(WorldGenSettings settings) {
|
||||
injectNoiseSettings(LevelStem.NETHER, BuiltinDimensionTypes.NETHER, settings);
|
||||
injectNoiseSettings(LevelStem.END, BuiltinDimensionTypes.END, settings);
|
||||
BCLChunkGenerator.injectNoiseSettings(settings, BCLChunkGenerator.ALL_DIMENSIONS);
|
||||
}
|
||||
|
||||
public static void injectNoiseSettings(ResourceKey<LevelStem> dimensionKey,
|
||||
ResourceKey<DimensionType> dimensionTypeKey,
|
||||
WorldGenSettings settings) {
|
||||
Optional<Holder<LevelStem>> loadedStem = settings.dimensions().getHolder(dimensionKey);
|
||||
final ChunkGenerator loadedChunkGenerator = loadedStem.map(h -> h.value().generator()).orElse(null);
|
||||
injectNoiseSettings(dimensionTypeKey, loadedChunkGenerator);
|
||||
}
|
||||
|
||||
public static void injectNoiseSettings(ResourceKey<DimensionType> dimensionTypeKey,
|
||||
ChunkGenerator loadedChunkGenerator) {
|
||||
BCLib.LOGGER.debug("Correcting Noise Settings for " + dimensionTypeKey.location().toString());
|
||||
BCLib.LOGGER.debug("Correcting Noise Settings for " + dimensionKey.location().toString());
|
||||
final BiomeSource loadedBiomeSource = loadedChunkGenerator.getBiomeSource();
|
||||
BiomeAPI.applyModifications(loadedBiomeSource, dimensionTypeKey);
|
||||
BiomeAPI.applyModifications(loadedBiomeSource, dimensionKey);
|
||||
|
||||
if (loadedChunkGenerator instanceof NoiseBasedChunkGenerator nbc) {
|
||||
if (((Object) nbc.generatorSettings().value()) instanceof SurfaceRuleProvider srp) {
|
||||
|
@ -87,6 +78,26 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
public static final Predicate<ResourceKey<LevelStem>> NON_MANAGED_DIMENSIONS = dim -> dim != LevelStem.NETHER && dim != LevelStem.END;
|
||||
public static final Predicate<ResourceKey<LevelStem>> ALL_DIMENSIONS = dim -> true;
|
||||
|
||||
public static void injectNoiseSettings(WorldGenSettings settings, Predicate<ResourceKey<LevelStem>> filter) {
|
||||
List<ResourceKey<LevelStem>> otherDimensions = settings
|
||||
.dimensions()
|
||||
.entrySet()
|
||||
.stream()
|
||||
.map(e -> e.getKey())
|
||||
.filter(filter)
|
||||
.toList();
|
||||
|
||||
for (ResourceKey<LevelStem> key : otherDimensions) {
|
||||
Optional<Holder<LevelStem>> stem = settings.dimensions().getHolder(key);
|
||||
if (stem.isPresent()) {
|
||||
injectNoiseSettings(key, stem.get().value().generator());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Codec<? extends ChunkGenerator> codec() {
|
||||
return CODEC;
|
||||
|
|
|
@ -32,6 +32,7 @@ public class PrimaryLevelDataMixin {
|
|||
private static final ThreadLocal<Optional<RegistryOps<Tag>>> bcl_lastRegistryAccess = ThreadLocal.withInitial(
|
||||
() -> Optional.empty());
|
||||
|
||||
//This is the way a created (new) world is initializing the PrimaryLevelData
|
||||
@ModifyArg(method = "<init>(Lnet/minecraft/world/level/LevelSettings;Lnet/minecraft/world/level/levelgen/WorldGenSettings;Lcom/mojang/serialization/Lifecycle;)V", 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_fixOtherSettings(WorldGenSettings worldGenSettings) {
|
||||
BCLChunkGenerator.injectNoiseSettings(worldGenSettings);
|
||||
|
@ -53,6 +54,8 @@ public class PrimaryLevelDataMixin {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//This is the way an loaded (existing) world is initializing the PrimaryLevelData
|
||||
@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) {
|
||||
Optional<RegistryOps<Tag>> registryOps = bcl_lastRegistryAccess.get();
|
||||
|
|
|
@ -170,7 +170,7 @@ public class BCLWorldPresetSettings extends WorldPresetSettings {
|
|||
if (loadedChunkGenerator instanceof NoiseGeneratorSettingsProvider noiseProvider) {
|
||||
final Set<Holder<Biome>> biomes = loadedChunkGenerator.getBiomeSource().possibleBiomes();
|
||||
final BiomeSource bs = fixBiomeSource(referenceGenerator.getBiomeSource(), biomes);
|
||||
BiomeAPI.applyModifications(bs, dimensionTypeKey);
|
||||
BiomeAPI.applyModifications(bs, dimensionKey);
|
||||
referenceGenerator = new BCLChunkGenerator(generator.bclib_getStructureSetsRegistry(),
|
||||
noiseProvider.bclib_getNoises(),
|
||||
bs,
|
||||
|
@ -185,7 +185,7 @@ public class BCLWorldPresetSettings extends WorldPresetSettings {
|
|||
settings,
|
||||
referenceGenerator);
|
||||
} else {
|
||||
BCLChunkGenerator.injectNoiseSettings(dimensionTypeKey, loadedChunkGenerator);
|
||||
BCLChunkGenerator.injectNoiseSettings(dimensionKey, loadedChunkGenerator);
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
@ -193,6 +193,8 @@ public class BCLWorldPresetSettings extends WorldPresetSettings {
|
|||
public WorldGenSettings repairSettingsOnLoad(RegistryAccess registryAccess, WorldGenSettings settings) {
|
||||
settings = fixSettingsInCurrentWorld(registryAccess, LevelStem.NETHER, BuiltinDimensionTypes.NETHER, settings);
|
||||
settings = fixSettingsInCurrentWorld(registryAccess, LevelStem.END, BuiltinDimensionTypes.END, settings);
|
||||
BCLChunkGenerator.injectNoiseSettings(settings, BCLChunkGenerator.NON_MANAGED_DIMENSIONS);
|
||||
return settings;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue