New event for finalizing ChunkGenerators

This commit is contained in:
Frank 2022-06-25 20:35:42 +02:00
parent 14443761d7
commit 4dc07f6567
7 changed files with 43 additions and 11 deletions

View file

@ -2,7 +2,6 @@ package org.betterx.bclib.api.v2.generator;
import org.betterx.bclib.BCLib;
import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
import org.betterx.bclib.interfaces.NoiseGeneratorSettingsProvider;
import org.betterx.bclib.mixin.common.ChunkGeneratorAccessor;
import org.betterx.worlds.together.WorldsTogether;
@ -175,7 +174,6 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator implements Resto
bs = referenceGenerator.getBiomeSource();
}
InternalBiomeAPI.applyModifications(bs, dimensionKey);
referenceGenerator = new BCLChunkGenerator(
generator.bclib_getStructureSetsRegistry(),
noiseProvider.bclib_getNoises(),

View file

@ -36,19 +36,21 @@ public class LevelGenEvents {
WorldEvents.ON_WORLD_LOAD.on(LevelGenEvents::onWorldLoad);
WorldEvents.WORLD_REGISTRY_READY.on(LevelGenEvents::onRegistryReady);
WorldEvents.ON_FINALIZE_LEVEL_STEM.on(LevelGenEvents::finalizeStem);
WorldEvents.PATCH_WORLD.on(LevelGenEvents::patchExistingWorld);
WorldEvents.ADAPT_WORLD_PRESET.on(LevelGenEvents::adaptWorldPresetSettings);
}
public static boolean patchExistingWorld(
private static boolean patchExistingWorld(
LevelStorageSource.LevelStorageAccess storageAccess,
Consumer<Boolean> allDone
) {
return DataFixerAPI.fixData(storageAccess, true, allDone);
}
public static Optional<Holder<WorldPreset>> adaptWorldPresetSettings(
private static Optional<Holder<WorldPreset>> adaptWorldPresetSettings(
Optional<Holder<WorldPreset>> currentPreset,
WorldGenSettings worldGenSettings
) {
@ -86,11 +88,11 @@ public class LevelGenEvents {
return currentPreset;
}
public static void onRegistryReady(RegistryAccess a) {
private static void onRegistryReady(RegistryAccess a) {
InternalBiomeAPI.initRegistry(a);
}
public static void prepareWorld(
private static void prepareWorld(
LevelStorageSource.LevelStorageAccess storageAccess,
Map<ResourceKey<LevelStem>, ChunkGenerator> dimensions,
boolean isNewWorld
@ -103,7 +105,7 @@ public class LevelGenEvents {
}
}
public static void prepareServerWorld(
private static void prepareServerWorld(
LevelStorageSource.LevelStorageAccess storageAccess,
Map<ResourceKey<LevelStem>, ChunkGenerator> dimensions,
boolean isNewWorld
@ -118,7 +120,15 @@ public class LevelGenEvents {
}
}
public static void onWorldLoad() {
private static void onWorldLoad() {
LifeCycleAPI._runBeforeLevelLoad();
}
private static void finalizeStem(
WorldGenSettings settings,
ResourceKey<LevelStem> dimension,
LevelStem levelStem
) {
InternalBiomeAPI.applyModifications(levelStem.generator().getBiomeSource(), dimension);
}
}

View file

@ -1,6 +1,6 @@
package org.betterx.worlds.together.mixin.common;
import org.betterx.worlds.together.surfaceRules.SurfaceRuleUtil;
import org.betterx.worlds.together.world.event.WorldBootstrap;
import net.minecraft.core.RegistryAccess;
import net.minecraft.server.MinecraftServer;
@ -29,6 +29,7 @@ public class MinecraftServerMixin {
@Inject(method = "createLevels", at = @At(value = "HEAD"))
private void together_addSurfaceRules(ChunkProgressListener worldGenerationProgressListener, CallbackInfo ci) {
SurfaceRuleUtil.injectSurfaceRulesToAllDimensions(this.worldData.worldGenSettings());
WorldBootstrap.finalizeWorldGenSettings(this.worldData.worldGenSettings());
}
}

View file

@ -0,0 +1,10 @@
package org.betterx.worlds.together.world.event;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.WorldGenSettings;
@FunctionalInterface
public interface OnFinalizeLevelStem {
void now(WorldGenSettings worldGenSettings, ResourceKey<LevelStem> dimensionKey, LevelStem stem);
}

View file

@ -5,6 +5,7 @@ import org.betterx.worlds.together.WorldsTogether;
import org.betterx.worlds.together.levelgen.WorldGenUtil;
import org.betterx.worlds.together.mixin.common.RegistryOpsAccessor;
import org.betterx.worlds.together.mixin.common.WorldPresetAccessor;
import org.betterx.worlds.together.surfaceRules.SurfaceRuleUtil;
import org.betterx.worlds.together.world.WorldConfig;
import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
import org.betterx.worlds.together.worldPreset.WorldGenSettingsComponentAccessor;
@ -287,6 +288,17 @@ public class WorldBootstrap {
}
}
public static void finalizeWorldGenSettings(WorldGenSettings worldGenSettings) {
for (var entry : worldGenSettings.dimensions().entrySet()) {
WorldEventsImpl.ON_FINALIZE_LEVEL_STEM.emit(e -> e.now(
worldGenSettings,
entry.getKey(),
entry.getValue()
));
}
SurfaceRuleUtil.injectSurfaceRulesToAllDimensions(worldGenSettings);
}
public static WorldGenSettings enforceInNewWorld(WorldGenSettings worldGenSettings) {
return WorldGenUtil.repairBiomeSourceInAllDimensions(LAST_REGISTRY_ACCESS, worldGenSettings);
}

View file

@ -5,7 +5,7 @@ public class WorldEvents {
public static final Event<BeforeWorldLoad> BEFORE_WORLD_LOAD = WorldEventsImpl.BEFORE_WORLD_LOAD;
public static final Event<BeforeServerWorldLoad> BEFORE_SERVER_WORLD_LOAD = WorldEventsImpl.BEFORE_SERVER_WORLD_LOAD;
public static final Event<OnWorldLoad> ON_WORLD_LOAD = WorldEventsImpl.ON_WORLD_LOAD;
public static final Event<OnFinalizeLevelStem> ON_FINALIZE_LEVEL_STEM = WorldEventsImpl.ON_FINALIZE_LEVEL_STEM;
public static final Event<OnWorldPatch> PATCH_WORLD = WorldEventsImpl.PATCH_WORLD;
public static final Event<OnAdaptWorldPresetSettings> ADAPT_WORLD_PRESET = WorldEventsImpl.ADAPT_WORLD_PRESET;
}

View file

@ -6,6 +6,7 @@ class WorldEventsImpl {
public static final EventImpl<BeforeServerWorldLoad> BEFORE_SERVER_WORLD_LOAD = new EventImpl<>();
public static final EventImpl<OnWorldLoad> ON_WORLD_LOAD = new EventImpl<>();
public static final EventImpl<OnFinalizeLevelStem> ON_FINALIZE_LEVEL_STEM = new EventImpl<>();
public static final PatchWorldEvent PATCH_WORLD = new PatchWorldEvent();
public static final AdaptWorldPresetSettingEvent ADAPT_WORLD_PRESET = new AdaptWorldPresetSettingEvent();