Repaired world loading with Datapacks an bclib world preset

This commit is contained in:
Frank 2022-10-26 19:20:51 +02:00
parent 416ff1644e
commit e826dbc623
7 changed files with 47 additions and 48 deletions

View file

@ -23,7 +23,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Optional;
@Mixin(CreateWorldScreen.class)
public class CreateWorldScreenMixin {
public class CreateWorldScreen_Mixin {
@Shadow
@Final
public WorldGenSettingsComponent worldGenSettingsComponent;

View file

@ -23,19 +23,6 @@ import org.jetbrains.annotations.Nullable;
@Mixin(PrimaryLevelData.class)
public class PrimaryLevelDataMixin {
//TODO: 1.19.3 This was changed completley, Replaced by WorldDimensions.bake
// @Shadow
// @Final
// private WorldGenSettings worldGenSettings;
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/WorldOptions;Lnet/minecraft/world/level/storage/PrimaryLevelData$SpecialWorldProperty;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) {
// return WorldBootstrap.enforceInNewWorld(worldGenSettings);
// }
//
@Inject(method = "parse", at = @At("HEAD"))
private static void bcl_parse(
Dynamic<Tag> dynamic,
@ -50,20 +37,7 @@ public class PrimaryLevelDataMixin {
CallbackInfoReturnable<PrimaryLevelData> cir
) {
if (dynamic.getOps() instanceof RegistryOps<Tag> regOps) {
//bcl_lastRegistryAccess.set(Optional.of(regOps));
WorldBootstrap.InGUI.registryReadyOnLoadedWorld(Optional.of(regOps));
}
}
// //This is the way a 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();
// WorldBootstrap.InGUI.registryReadyOnLoadedWorld(registryOps);
// settings = WorldBootstrap.enforceInLoadedWorld(registryOps, settings);
// bcl_lastRegistryAccess.set(Optional.empty());
// return settings;
// }
}

View file

@ -1,15 +0,0 @@
package org.betterx.worlds.together.mixin.common;
import net.minecraft.world.level.levelgen.WorldDimensions;
import org.spongepowered.asm.mixin.Mixin;
@Mixin(value = WorldDimensions.class, priority = 100)
public class WorldDimensionsMixin {
//TODO:1.19.3 no general registry access available yet as the layerd access is generated after this
// @ModifyVariable(method = "bake", argsOnly = true, at = @At("HEAD"))
// Registry<LevelStem> wt_bake(Registry<LevelStem> dimensionRegistry) {
// final Registry<LevelStem> changedRegistry = WorldBootstrap.enforceInNewWorld(dimensionRegistry);
// return changedRegistry;
// }
}

View file

@ -0,0 +1,22 @@
package org.betterx.worlds.together.mixin.common;
import org.betterx.worlds.together.world.event.WorldBootstrap;
import net.minecraft.core.LayeredRegistryAccess;
import net.minecraft.server.RegistryLayer;
import net.minecraft.server.WorldStem;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
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);
}
}

View file

@ -14,11 +14,13 @@ import org.betterx.worlds.together.worldPreset.WorldPresets;
import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent;
import net.minecraft.core.Holder;
import net.minecraft.core.LayeredRegistryAccess;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.RegistryOps;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.RegistryLayer;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.WorldDimensions;
@ -27,6 +29,7 @@ import net.minecraft.world.level.storage.LevelResource;
import net.minecraft.world.level.storage.LevelStorageSource;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Consumer;
@ -41,11 +44,13 @@ public class WorldBootstrap {
}
public static RegistryAccess getLastRegistryAccessOrElseBuiltin() {
if (LAST_REGISTRY_ACCESS == null)
if (LAST_REGISTRY_ACCESS == null) {
WorldsTogether.LOGGER.error("Tried to read from global registry!");
}
return LAST_REGISTRY_ACCESS;
}
public static class Helpers {
private static void initializeWorldConfig(
LevelStorageSource.LevelStorageAccess levelStorageAccess,
@ -320,7 +325,20 @@ public class WorldBootstrap {
WorldEventsImpl.ON_FINALIZED_WORLD_LOAD.emit(e -> e.done(dimensionRegistry));
}
public static Registry<LevelStem> enforceInNewWorld(Registry<LevelStem> dimensionRegistry) {
return WorldGenUtil.repairBiomeSourceInAllDimensions(LAST_REGISTRY_ACCESS, dimensionRegistry);
public static LayeredRegistryAccess<RegistryLayer> enforceInLayeredRegistry(LayeredRegistryAccess<RegistryLayer> registries) {
RegistryAccess access = registries.compositeAccess();
InGUI.registryReady(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(
RegistryLayer.DIMENSIONS,
new RegistryAccess.ImmutableRegistryAccess(List.of(changedDimensions)).freeze()
);
}
return registries;
}
}

View file

@ -4,7 +4,7 @@
"package": "org.betterx.worlds.together.mixin.client",
"compatibilityLevel": "JAVA_17",
"client": [
"CreateWorldScreenMixin",
"CreateWorldScreen_Mixin",
"WorldGenSettingsComponentMixin",
"WorldOpenFlowsMixin"
],

View file

@ -18,12 +18,12 @@
"RegistryDataLoaderMixin",
"RegistryOpsAccessor",
"TagLoaderMixin",
"WorldDimensionsMixin",
"WorldGenPropertiesMixin",
"WorldLoaderMixin",
"WorldPresetAccessor",
"WorldPresetMixin",
"WorldPresetsBootstrapMixin"
"WorldPresetsBootstrapMixin",
"WorldStem_Mixin"
],
"injectors": {
"defaultRequire": 1