Streamlined WorldBootstrap
This commit is contained in:
parent
d9a586741e
commit
b4f9fdf95f
13 changed files with 172 additions and 141 deletions
|
@ -38,22 +38,21 @@ public class LevelGenEvents {
|
|||
}
|
||||
|
||||
public static void register() {
|
||||
WorldEvents.BEFORE_WORLD_LOAD.on(LevelGenEvents::prepareWorld);
|
||||
WorldEvents.BEFORE_SERVER_WORLD_LOAD.on(LevelGenEvents::prepareServerWorld);
|
||||
WorldEvents.BEFORE_WORLD_LOAD.on(LevelGenEvents::beforeWorldLoad);
|
||||
|
||||
WorldEvents.ON_WORLD_LOAD.on(LevelGenEvents::onWorldLoad);
|
||||
WorldEvents.WORLD_REGISTRY_READY.on(LevelGenEvents::onRegistryReady);
|
||||
WorldEvents.WORLD_REGISTRY_READY.on(LevelGenEvents::worldRegistryReady);
|
||||
WorldEvents.ON_FINALIZE_LEVEL_STEM.on(LevelGenEvents::finalizeStem);
|
||||
WorldEvents.ON_FINALIZED_WORLD_LOAD.on(LevelGenEvents::finalizedWorldLoad);
|
||||
|
||||
WorldEvents.PATCH_WORLD.on(LevelGenEvents::patchExistingWorld);
|
||||
WorldEvents.ADAPT_WORLD_PRESET.on(LevelGenEvents::adaptWorldPresetSettings);
|
||||
WorldEvents.ADAPT_WORLD_PRESET.on(LevelGenEvents::adaptWorldPreset);
|
||||
|
||||
WorldEvents.BEFORE_ADDING_TAGS.on(LevelGenEvents::appplyTags);
|
||||
WorldEvents.BEFORE_ADDING_TAGS.on(LevelGenEvents::applyBiomeTags);
|
||||
}
|
||||
|
||||
|
||||
private static void appplyTags(
|
||||
private static void applyBiomeTags(
|
||||
String directory,
|
||||
Map<ResourceLocation, List<TagLoader.EntryWithSource>> tagsMap
|
||||
) {
|
||||
|
@ -67,10 +66,10 @@ public class LevelGenEvents {
|
|||
LevelStorageSource.LevelStorageAccess storageAccess,
|
||||
Consumer<Boolean> allDone
|
||||
) {
|
||||
return DataFixerAPI.fixData(storageAccess, true, allDone);
|
||||
return DataFixerAPI.fixData(storageAccess, allDone != null, allDone);
|
||||
}
|
||||
|
||||
private static Optional<Holder<WorldPreset>> adaptWorldPresetSettings(
|
||||
private static Optional<Holder<WorldPreset>> adaptWorldPreset(
|
||||
Optional<Holder<WorldPreset>> currentPreset,
|
||||
WorldDimensions worldDims
|
||||
) {
|
||||
|
@ -110,14 +109,15 @@ public class LevelGenEvents {
|
|||
return currentPreset;
|
||||
}
|
||||
|
||||
private static void onRegistryReady(RegistryAccess a) {
|
||||
private static void worldRegistryReady(RegistryAccess a) {
|
||||
InternalBiomeAPI.initRegistry(a);
|
||||
}
|
||||
|
||||
private static void prepareWorld(
|
||||
private static void beforeWorldLoad(
|
||||
LevelStorageSource.LevelStorageAccess storageAccess,
|
||||
Map<ResourceKey<LevelStem>, ChunkGenerator> dimensions,
|
||||
boolean isNewWorld
|
||||
boolean isNewWorld,
|
||||
boolean isServer
|
||||
) {
|
||||
setupWorld();
|
||||
if (isNewWorld) {
|
||||
|
@ -128,22 +128,6 @@ public class LevelGenEvents {
|
|||
}
|
||||
}
|
||||
|
||||
private static void prepareServerWorld(
|
||||
LevelStorageSource.LevelStorageAccess storageAccess,
|
||||
Map<ResourceKey<LevelStem>, ChunkGenerator> dimensions,
|
||||
boolean isNewWorld
|
||||
) {
|
||||
setupWorld();
|
||||
|
||||
if (isNewWorld) {
|
||||
WorldConfig.saveFile(BCLib.MOD_ID);
|
||||
DataFixerAPI.initializePatchData();
|
||||
} else {
|
||||
LevelGenUtil.migrateGeneratorSettings();
|
||||
DataFixerAPI.fixData(storageAccess, false, (didFix) -> {/* not called when showUI==false */});
|
||||
}
|
||||
}
|
||||
|
||||
private static void onWorldLoad() {
|
||||
LifeCycleAPI._runBeforeLevelLoad();
|
||||
}
|
||||
|
|
|
@ -1,18 +1,32 @@
|
|||
package org.betterx.bclib.mixin.client;
|
||||
|
||||
import org.betterx.bclib.client.BCLibClient;
|
||||
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.server.packs.resources.PreparableReloadListener;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@Mixin(ModelManager.class)
|
||||
public class ModelManagerMixin {
|
||||
//TODO: 1.19.3 Disabled for now
|
||||
// @Inject(method = "prepare", at = @At("HEAD"))
|
||||
// private void bclib_loadCustomModels(
|
||||
// ResourceManager resourceManager,
|
||||
// ProfilerFiller profilerFiller,
|
||||
// CallbackInfoReturnable<ModelBakery> info
|
||||
// ) {
|
||||
// BCLibClient.modelBakery.loadCustomModels(resourceManager);
|
||||
// }
|
||||
@Inject(method = "reload", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/util/profiling/ProfilerFiller;startTick()V"))
|
||||
private void bclib_loadCustomModels(
|
||||
PreparableReloadListener.PreparationBarrier preparationBarrier,
|
||||
ResourceManager resourceManager,
|
||||
ProfilerFiller profilerFiller,
|
||||
ProfilerFiller profilerFiller2,
|
||||
Executor executor,
|
||||
Executor executor2,
|
||||
CallbackInfoReturnable<CompletableFuture<Void>> cir
|
||||
) {
|
||||
BCLibClient.modelBakery.loadCustomModels(resourceManager);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
|||
import net.minecraft.world.level.levelgen.structure.StructureSet;
|
||||
import net.minecraft.world.level.levelgen.synth.NormalNoise;
|
||||
|
||||
import java.util.Map;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
public class WorldGenUtil {
|
||||
|
@ -228,7 +229,7 @@ public class WorldGenUtil {
|
|||
RegistryAccess registryAccess,
|
||||
Registry<LevelStem> dimensionRegistry
|
||||
) {
|
||||
var dimensions = TogetherWorldPreset.loadWorldDimensions();
|
||||
Map<ResourceKey<LevelStem>, ChunkGenerator> dimensions = TogetherWorldPreset.loadWorldDimensions();
|
||||
for (var entry : dimensionRegistry.entrySet()) {
|
||||
boolean didRepair = false;
|
||||
ResourceKey<LevelStem> key = entry.getKey();
|
||||
|
|
|
@ -36,7 +36,7 @@ public class CreateWorldScreen_Mixin {
|
|||
WorldGenSettingsComponent worldGenSettingsComponent,
|
||||
CallbackInfo ci
|
||||
) {
|
||||
WorldBootstrap.InGUI.registryReadyOnNewWorld(worldGenSettingsComponent);
|
||||
//WorldBootstrap.InGUI.registryReadyOnNewWorld(worldGenSettingsComponent);
|
||||
}
|
||||
|
||||
//Change the WorldPreset that is selected by default on the Create World Screen
|
||||
|
@ -51,9 +51,4 @@ public class CreateWorldScreen_Mixin {
|
|||
WorldBootstrap.InGUI.registryReadyOnNewWorld(this.worldGenSettingsComponent);
|
||||
WorldBootstrap.InGUI.setupNewWorld(cir.getReturnValue(), this.worldGenSettingsComponent);
|
||||
}
|
||||
|
||||
@Inject(method = "onCreate", at = @At("HEAD"))
|
||||
void wt_onCreate(CallbackInfo ci) {
|
||||
System.out.println("there");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,13 +35,13 @@ public abstract class WorldOpenFlowsMixin {
|
|||
WorldBootstrap.InGUI.setupLoadedWorld(levelID, this.levelSource);
|
||||
|
||||
if (WorldBootstrap.InGUI.applyWorldPatches(levelSource, levelID, (appliedFixes) -> {
|
||||
WorldBootstrap.InGUI.finishedWorldLoad(levelID, this.levelSource);
|
||||
WorldBootstrap.finishedWorldLoad();
|
||||
this.doLoadLevel(screen, levelID, false, false);
|
||||
})) {
|
||||
//cancel call when fix-screen is presented
|
||||
ci.cancel();
|
||||
} else {
|
||||
WorldBootstrap.InGUI.finishedWorldLoad(levelID, this.levelSource);
|
||||
WorldBootstrap.finishedWorldLoad();
|
||||
if (WorldsTogether.SURPRESS_EXPERIMENTAL_DIALOG) {
|
||||
this.doLoadLevel(screen, levelID, false, false);
|
||||
//cancel call as we manually start the level load here
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.util.Properties;
|
|||
@Mixin(DedicatedServerProperties.class)
|
||||
public class DedicatedServerPropertiesMixin {
|
||||
//Make sure the default server properties use our Default World Preset by default (read from "level-type")
|
||||
@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"))
|
||||
@ModifyArg(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/dedicated/DedicatedServerProperties$WorldDimensionData;<init>(Lcom/google/gson/JsonObject;Ljava/lang/String;)V"))
|
||||
protected String wt_defaultPreset(String string) {
|
||||
if (WorldsTogether.FORCE_SERVER_TO_BETTERX_PRESET) {
|
||||
return WorldPresets.getDEFAULT().location().toString();
|
||||
|
|
|
@ -15,9 +15,12 @@ import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
|||
|
||||
@Mixin(value = Main.class, priority = 200)
|
||||
abstract public class MainMixin {
|
||||
private static LevelStorageSource.LevelStorageAccess bcl_levelStorageAccess = null;
|
||||
|
||||
@ModifyVariable(method = "main", ordinal = 0, at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;getSummary()Lnet/minecraft/world/level/storage/LevelSummary;"))
|
||||
private static LevelStorageSource.LevelStorageAccess bc_createAccess(LevelStorageSource.LevelStorageAccess levelStorageAccess) {
|
||||
WorldBootstrap.DedicatedServer.setupWorld(levelStorageAccess);
|
||||
bcl_levelStorageAccess = levelStorageAccess;
|
||||
WorldBootstrap.DedicatedServer.applyWorldPatches(levelStorageAccess);
|
||||
return levelStorageAccess;
|
||||
}
|
||||
|
||||
|
@ -27,13 +30,7 @@ abstract public class MainMixin {
|
|||
if (dynamicOps instanceof RegistryOps<Tag> regOps) {
|
||||
WorldBootstrap.DedicatedServer.registryReady(regOps);
|
||||
}
|
||||
WorldBootstrap.DedicatedServer.setupWorld(bcl_levelStorageAccess);
|
||||
return dynamicOps;
|
||||
}
|
||||
|
||||
//TODO: 1.19.3 this may be obsolete, as datapacks are handled differently now
|
||||
// @ModifyArg(method = "method_43613", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/PrimaryLevelData;<init>(Lnet/minecraft/world/level/LevelSettings;Lnet/minecraft/world/level/levelgen/WorldOptions;Lnet/minecraft/world/level/storage/PrimaryLevelData$SpecialWorldProperty;Lcom/mojang/serialization/Lifecycle;)V"))
|
||||
// private static WorldGenSettings bcl_onCreateLevelData(WorldGenSettings worldGenSettings) {
|
||||
// WorldBootstrap.DedicatedServer.applyDatapackChangesOnNewWorld(worldGenSettings);
|
||||
// return worldGenSettings;
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -12,11 +12,10 @@ import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
|||
|
||||
@Mixin(WorldStem.class)
|
||||
public class WorldStem_Mixin {
|
||||
|
||||
//TODO:1.19.3 no general registry access available yet as the layerd access is generated after this
|
||||
@ModifyVariable(method = "<init>", argsOnly = true, at = @At(value = "INVOKE", target = "Ljava/lang/Record;<init>()V", shift = At.Shift.AFTER))
|
||||
LayeredRegistryAccess<RegistryLayer> wt_bake(LayeredRegistryAccess<RegistryLayer> registries) {
|
||||
return WorldBootstrap.enforceInLayeredRegistry(registries);
|
||||
LayeredRegistryAccess<RegistryLayer> rNew = WorldBootstrap.enforceInLayeredRegistry(registries);
|
||||
return rNew;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ public interface BeforeWorldLoad {
|
|||
void prepareWorld(
|
||||
LevelStorageSource.LevelStorageAccess storageAccess,
|
||||
Map<ResourceKey<LevelStem>, ChunkGenerator> settings,
|
||||
boolean isNewWorld
|
||||
boolean isNewWorld,
|
||||
boolean isServer
|
||||
);
|
||||
}
|
||||
|
|
|
@ -78,17 +78,17 @@ public class WorldBootstrap {
|
|||
);
|
||||
}
|
||||
|
||||
private static Map<ResourceKey<LevelStem>, ChunkGenerator> defaultServerDimensions() {
|
||||
private static WorldDimensions defaultServerDimensions() {
|
||||
final Holder<WorldPreset> defaultPreset = defaultServerPreset();
|
||||
return defaultServerDimensions(defaultPreset);
|
||||
}
|
||||
|
||||
private static Map<ResourceKey<LevelStem>, ChunkGenerator> defaultServerDimensions(Holder<WorldPreset> defaultPreset) {
|
||||
final Map<ResourceKey<LevelStem>, ChunkGenerator> dimensions;
|
||||
private static WorldDimensions defaultServerDimensions(Holder<WorldPreset> defaultPreset) {
|
||||
final WorldDimensions dimensions;
|
||||
if (defaultPreset.value() instanceof TogetherWorldPreset t) {
|
||||
dimensions = t.getDimensionsMap();
|
||||
dimensions = t.getWorldDimensions();
|
||||
} else {
|
||||
dimensions = TogetherWorldPreset.getDimensionsMap(net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL);
|
||||
dimensions = TogetherWorldPreset.getWorldDimensions(net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL);
|
||||
}
|
||||
return dimensions;
|
||||
}
|
||||
|
@ -118,35 +118,38 @@ public class WorldBootstrap {
|
|||
File levelDat = levelStorageAccess.getLevelPath(LevelResource.LEVEL_DATA_FILE).toFile();
|
||||
if (!levelDat.exists()) {
|
||||
WorldsTogether.LOGGER.info("Creating a new World, no fixes needed");
|
||||
final Map<ResourceKey<LevelStem>, ChunkGenerator> settings = Helpers.defaultServerDimensions();
|
||||
final WorldDimensions dimensions = Helpers.defaultServerDimensions();
|
||||
|
||||
Helpers.initializeWorldConfig(levelStorageAccess, true);
|
||||
WorldEventsImpl.BEFORE_SERVER_WORLD_LOAD.emit(e -> e.prepareWorld(
|
||||
levelStorageAccess, settings, true
|
||||
));
|
||||
WorldBootstrap.setupWorld(
|
||||
levelStorageAccess, TogetherWorldPreset.getDimensionMap(dimensions),
|
||||
true, true
|
||||
);
|
||||
|
||||
Optional<Holder<WorldPreset>> currentPreset = Optional.of(Helpers.defaultServerPreset());
|
||||
writeWorldPresets(dimensions, currentPreset);
|
||||
finishedWorldLoad();
|
||||
} else {
|
||||
Helpers.initializeWorldConfig(levelStorageAccess, false);
|
||||
WorldEventsImpl.BEFORE_SERVER_WORLD_LOAD.emit(e -> e.prepareWorld(
|
||||
levelStorageAccess,
|
||||
TogetherWorldPreset.loadWorldDimensions(),
|
||||
false
|
||||
));
|
||||
WorldEventsImpl.ON_WORLD_LOAD.emit(OnWorldLoad::onLoad);
|
||||
WorldBootstrap.setupWorld(
|
||||
levelStorageAccess, TogetherWorldPreset.loadWorldDimensions(),
|
||||
false, true
|
||||
);
|
||||
finishedWorldLoad();
|
||||
}
|
||||
}
|
||||
|
||||
//Needs to get called after setupWorld
|
||||
public static void applyDatapackChangesOnNewWorld(WorldDimensions worldDims) {
|
||||
Optional<Holder<WorldPreset>> currentPreset = Optional.of(Helpers.defaultServerPreset());
|
||||
currentPreset = WorldEventsImpl.ADAPT_WORLD_PRESET.emit(currentPreset, worldDims);
|
||||
|
||||
if (currentPreset.map(Holder::value).orElse(null) instanceof WorldPresetAccessor acc) {
|
||||
TogetherWorldPreset.writeWorldPresetSettings(acc.bcl_getDimensions());
|
||||
} else {
|
||||
WorldsTogether.LOGGER.error("Failed writing together File");
|
||||
TogetherWorldPreset.writeWorldPresetSettings(worldDims.dimensions());
|
||||
public static boolean applyWorldPatches(
|
||||
LevelStorageSource.LevelStorageAccess levelStorageAccess
|
||||
) {
|
||||
boolean result = false;
|
||||
if (levelStorageAccess.getLevelPath(LevelResource.LEVEL_DATA_FILE).toFile().exists()) {
|
||||
try {
|
||||
result = WorldEventsImpl.PATCH_WORLD.applyPatches(levelStorageAccess, null);
|
||||
} catch (Exception e) {
|
||||
WorldsTogether.LOGGER.error("Failed to initialize data in world", e);
|
||||
}
|
||||
}
|
||||
WorldEventsImpl.ON_WORLD_LOAD.emit(OnWorldLoad::onLoad);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,13 +159,13 @@ public class WorldBootstrap {
|
|||
}
|
||||
|
||||
public static void registryReadyOnLoadedWorld(Optional<RegistryOps<Tag>> registryOps) {
|
||||
if (registryOps.orElse(null) instanceof RegistryOpsAccessor acc) {
|
||||
Helpers.onRegistryReady(acc.bcl_getRegistryAccess());
|
||||
}
|
||||
// if (registryOps.orElse(null) instanceof RegistryOpsAccessor acc) {
|
||||
// Helpers.onRegistryReady(acc.bcl_getRegistryAccess());
|
||||
// }
|
||||
}
|
||||
|
||||
public static void registryReady(RegistryAccess access) {
|
||||
Helpers.onRegistryReady(access);
|
||||
//Helpers.onRegistryReady(access);
|
||||
}
|
||||
|
||||
public static void setupNewWorld(
|
||||
|
@ -195,35 +198,16 @@ public class WorldBootstrap {
|
|||
Optional<Holder<WorldPreset>> currentPreset,
|
||||
WorldDimensions worldDims
|
||||
) {
|
||||
Helpers.initializeWorldConfig(levelStorageAccess, true);
|
||||
|
||||
|
||||
final Map<ResourceKey<LevelStem>, ChunkGenerator> dimensions;
|
||||
final WorldDimensions dimensions;
|
||||
if (currentPreset.map(Holder::value).orElse(null) instanceof TogetherWorldPreset t) {
|
||||
dimensions = t.getDimensionsMap();
|
||||
dimensions = t.getWorldDimensions();
|
||||
} else {
|
||||
dimensions = TogetherWorldPreset.getDimensionsMap(net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL);
|
||||
dimensions = TogetherWorldPreset.getWorldDimensions(net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL);
|
||||
}
|
||||
|
||||
// Helpers.setupWorld();
|
||||
// DataFixerAPI.initializePatchData();
|
||||
WorldEventsImpl.BEFORE_WORLD_LOAD.emit(e -> e.prepareWorld(
|
||||
levelStorageAccess,
|
||||
dimensions,
|
||||
true
|
||||
));
|
||||
|
||||
currentPreset = WorldEventsImpl.ADAPT_WORLD_PRESET.emit(currentPreset, worldDims);
|
||||
|
||||
if (currentPreset.map(Holder::value).orElse(null) instanceof WorldPresetAccessor acc) {
|
||||
TogetherWorldPreset.writeWorldPresetSettings(acc.bcl_getDimensions());
|
||||
} else {
|
||||
WorldsTogether.LOGGER.error("Failed writing together File");
|
||||
TogetherWorldPreset.writeWorldPresetSettings(worldDims.dimensions());
|
||||
}
|
||||
|
||||
//LifeCycleAPI._runBeforeLevelLoad();
|
||||
WorldEventsImpl.ON_WORLD_LOAD.emit(OnWorldLoad::onLoad);
|
||||
setupWorld(levelStorageAccess, TogetherWorldPreset.getDimensionMap(dimensions), true, false);
|
||||
writeWorldPresets(worldDims, currentPreset);
|
||||
finishedWorldLoad();
|
||||
|
||||
return currentPreset;
|
||||
}
|
||||
|
@ -238,18 +222,11 @@ public class WorldBootstrap {
|
|||
WorldGenUtil.clearPreloadedWorldPresets();
|
||||
try {
|
||||
var levelStorageAccess = levelSource.createAccess(levelID);
|
||||
try {
|
||||
Helpers.initializeWorldConfig(levelStorageAccess, false);
|
||||
|
||||
//Helpers.setupWorld();
|
||||
WorldEventsImpl.BEFORE_WORLD_LOAD.emit(e -> e.prepareWorld(
|
||||
levelStorageAccess,
|
||||
TogetherWorldPreset.loadWorldDimensions(),
|
||||
false
|
||||
));
|
||||
} catch (Exception e) {
|
||||
WorldsTogether.LOGGER.error("Failed to initialize data in world", e);
|
||||
}
|
||||
WorldBootstrap.setupWorld(
|
||||
levelStorageAccess,
|
||||
TogetherWorldPreset.loadWorldDimensions(),
|
||||
false, false
|
||||
);
|
||||
levelStorageAccess.close();
|
||||
} catch (Exception e) {
|
||||
WorldsTogether.LOGGER.error("Failed to acquire storage access", e);
|
||||
|
@ -273,14 +250,6 @@ public class WorldBootstrap {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static void finishedWorldLoad(
|
||||
String levelID,
|
||||
LevelStorageSource levelSource
|
||||
) {
|
||||
//LifeCycleAPI._runBeforeLevelLoad();
|
||||
WorldEventsImpl.ON_WORLD_LOAD.emit(OnWorldLoad::onLoad);
|
||||
WorldGenUtil.clearPreloadedWorldPresets();
|
||||
}
|
||||
}
|
||||
|
||||
public static class InFreshLevel {
|
||||
|
@ -300,6 +269,39 @@ public class WorldBootstrap {
|
|||
}
|
||||
}
|
||||
|
||||
private static void setupWorld(
|
||||
LevelStorageSource.LevelStorageAccess levelStorageAccess,
|
||||
Map<ResourceKey<LevelStem>, ChunkGenerator> dimensions,
|
||||
boolean newWorld, boolean isServer
|
||||
) {
|
||||
try {
|
||||
Helpers.initializeWorldConfig(levelStorageAccess, newWorld);
|
||||
WorldEventsImpl.BEFORE_WORLD_LOAD.emit(e -> e.prepareWorld(
|
||||
levelStorageAccess,
|
||||
dimensions,
|
||||
newWorld, isServer
|
||||
));
|
||||
} catch (Exception e) {
|
||||
WorldsTogether.LOGGER.error("Failed to initialize data in world", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeWorldPresets(WorldDimensions dimensions, Optional<Holder<WorldPreset>> currentPreset) {
|
||||
currentPreset = WorldEventsImpl.ADAPT_WORLD_PRESET.emit(currentPreset, dimensions);
|
||||
|
||||
if (currentPreset.map(Holder::value).orElse(null) instanceof WorldPresetAccessor acc) {
|
||||
TogetherWorldPreset.writeWorldPresetSettings(acc.bcl_getDimensions());
|
||||
} else {
|
||||
WorldsTogether.LOGGER.error("Failed writing together File");
|
||||
TogetherWorldPreset.writeWorldPresetSettings(dimensions);
|
||||
}
|
||||
}
|
||||
|
||||
public static void finishedWorldLoad() {
|
||||
WorldEventsImpl.ON_WORLD_LOAD.emit(OnWorldLoad::onLoad);
|
||||
WorldGenUtil.clearPreloadedWorldPresets();
|
||||
}
|
||||
|
||||
public static void finalizeWorldGenSettings(Registry<LevelStem> dimensionRegistry) {
|
||||
String output = "World Dimensions: ";
|
||||
for (var entry : dimensionRegistry.entrySet()) {
|
||||
|
@ -327,18 +329,22 @@ public class WorldBootstrap {
|
|||
|
||||
public static LayeredRegistryAccess<RegistryLayer> enforceInLayeredRegistry(LayeredRegistryAccess<RegistryLayer> registries) {
|
||||
RegistryAccess access = registries.compositeAccess();
|
||||
InGUI.registryReady(access);
|
||||
Helpers.onRegistryReady(access);
|
||||
final Registry<LevelStem> dimensions = access.registryOrThrow(Registry.LEVEL_STEM_REGISTRY);
|
||||
final Registry<LevelStem> changedDimensions = WorldGenUtil.repairBiomeSourceInAllDimensions(access, dimensions);
|
||||
if (dimensions != changedDimensions) {
|
||||
if (Configs.MAIN_CONFIG.verboseLogging()) {
|
||||
WorldsTogether.LOGGER.info("Loading originally configured Dimensions in World.");
|
||||
}
|
||||
return registries.replaceFrom(
|
||||
registries = registries.replaceFrom(
|
||||
RegistryLayer.DIMENSIONS,
|
||||
new RegistryAccess.ImmutableRegistryAccess(List.of(changedDimensions)).freeze()
|
||||
);
|
||||
//this will generate a new access object we have to use from now on...
|
||||
Helpers.onRegistryReady(registries.compositeAccess());
|
||||
}
|
||||
return registries;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.betterx.worlds.together.world.event;
|
|||
public class WorldEvents {
|
||||
public static final Event<OnWorldRegistryReady> WORLD_REGISTRY_READY = WorldEventsImpl.WORLD_REGISTRY_READY;
|
||||
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<OnFinalizeWorldLoad> ON_FINALIZED_WORLD_LOAD = WorldEventsImpl.ON_FINALIZED_WORLD_LOAD;
|
||||
|
|
|
@ -6,7 +6,6 @@ import org.jetbrains.annotations.ApiStatus;
|
|||
public class WorldEventsImpl {
|
||||
public static final EventImpl<OnWorldRegistryReady> WORLD_REGISTRY_READY = new EventImpl<>();
|
||||
public static final EventImpl<BeforeWorldLoad> BEFORE_WORLD_LOAD = new EventImpl<>();
|
||||
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<>();
|
||||
|
|
|
@ -9,9 +9,12 @@ import org.betterx.worlds.together.world.event.WorldBootstrap;
|
|||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.Dynamic;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.minecraft.core.MappedRegistry;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.nbt.Tag;
|
||||
|
@ -19,6 +22,7 @@ import net.minecraft.resources.RegistryOps;
|
|||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.levelgen.WorldDimensions;
|
||||
import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -30,6 +34,8 @@ public class TogetherWorldPreset extends WorldPreset {
|
|||
public final int sortOrder;
|
||||
|
||||
private static int NEXT_IN_SORT_ORDER = 1000;
|
||||
private final WorldDimensions worldDimensions;
|
||||
|
||||
|
||||
public TogetherWorldPreset(
|
||||
Map<ResourceKey<LevelStem>, LevelStem> map,
|
||||
|
@ -44,6 +50,20 @@ public class TogetherWorldPreset extends WorldPreset {
|
|||
) {
|
||||
super(map);
|
||||
this.sortOrder = sortOrder;
|
||||
this.worldDimensions = buildWorldDimensions(map);
|
||||
}
|
||||
|
||||
public static WorldDimensions buildWorldDimensions(Map<ResourceKey<LevelStem>, LevelStem> map) {
|
||||
Registry<LevelStem> registry = new MappedRegistry<>(Registry.LEVEL_STEM_REGISTRY, Lifecycle.experimental());
|
||||
for (var entry : map.entrySet()) {
|
||||
Registry.register(registry, entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
return new WorldDimensions(registry);
|
||||
}
|
||||
|
||||
public WorldDimensions getWorldDimensions() {
|
||||
return this.worldDimensions;
|
||||
}
|
||||
|
||||
public TogetherWorldPreset withDimensions(Registry<LevelStem> dimensions) {
|
||||
|
@ -68,6 +88,10 @@ public class TogetherWorldPreset extends WorldPreset {
|
|||
return getDimensions().get(key);
|
||||
}
|
||||
|
||||
public static void writeWorldPresetSettings(WorldDimensions dimensions) {
|
||||
writeWorldPresetSettings(dimensions.dimensions());
|
||||
}
|
||||
|
||||
public static void writeWorldPresetSettings(Registry<LevelStem> dimensions) {
|
||||
DimensionsWrapper wrapper = new DimensionsWrapper(dimensions);
|
||||
writeWorldPresetSettings(wrapper);
|
||||
|
@ -129,7 +153,10 @@ public class TogetherWorldPreset extends WorldPreset {
|
|||
|
||||
public static Registry<LevelStem> getDimensions(ResourceKey<WorldPreset> key) {
|
||||
RegistryAccess access = WorldBootstrap.getLastRegistryAccessOrElseBuiltin();
|
||||
var preset = access.registryOrThrow(Registry.WORLD_PRESET_REGISTRY).getHolder(key);
|
||||
var preset = (access == null
|
||||
? BuiltinRegistries.WORLD_PRESET
|
||||
: access.registryOrThrow(Registry.WORLD_PRESET_REGISTRY))
|
||||
.getHolder(key);
|
||||
if (preset.isEmpty()) return null;
|
||||
return preset
|
||||
.get()
|
||||
|
@ -144,6 +171,15 @@ public class TogetherWorldPreset extends WorldPreset {
|
|||
return DimensionsWrapper.build(reg);
|
||||
}
|
||||
|
||||
public static @NotNull Map<ResourceKey<LevelStem>, ChunkGenerator> getDimensionMap(WorldDimensions worldDims) {
|
||||
return DimensionsWrapper.build(worldDims.dimensions());
|
||||
}
|
||||
|
||||
public static @NotNull WorldDimensions getWorldDimensions(ResourceKey<WorldPreset> key) {
|
||||
Registry<LevelStem> reg = getDimensions(key);
|
||||
return new WorldDimensions(reg);
|
||||
}
|
||||
|
||||
private static class DimensionsWrapper {
|
||||
public static final Codec<DimensionsWrapper> CODEC = RecordCodecBuilder.create(instance -> instance
|
||||
.group(Codec.unboundedMap(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue