Repaired world loading with Datapacks an bclib world preset
This commit is contained in:
parent
416ff1644e
commit
e826dbc623
7 changed files with 47 additions and 48 deletions
|
@ -23,7 +23,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Mixin(CreateWorldScreen.class)
|
@Mixin(CreateWorldScreen.class)
|
||||||
public class CreateWorldScreenMixin {
|
public class CreateWorldScreen_Mixin {
|
||||||
@Shadow
|
@Shadow
|
||||||
@Final
|
@Final
|
||||||
public WorldGenSettingsComponent worldGenSettingsComponent;
|
public WorldGenSettingsComponent worldGenSettingsComponent;
|
|
@ -23,19 +23,6 @@ import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@Mixin(PrimaryLevelData.class)
|
@Mixin(PrimaryLevelData.class)
|
||||||
public class PrimaryLevelDataMixin {
|
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"))
|
@Inject(method = "parse", at = @At("HEAD"))
|
||||||
private static void bcl_parse(
|
private static void bcl_parse(
|
||||||
Dynamic<Tag> dynamic,
|
Dynamic<Tag> dynamic,
|
||||||
|
@ -50,20 +37,7 @@ public class PrimaryLevelDataMixin {
|
||||||
CallbackInfoReturnable<PrimaryLevelData> cir
|
CallbackInfoReturnable<PrimaryLevelData> cir
|
||||||
) {
|
) {
|
||||||
if (dynamic.getOps() instanceof RegistryOps<Tag> regOps) {
|
if (dynamic.getOps() instanceof RegistryOps<Tag> regOps) {
|
||||||
//bcl_lastRegistryAccess.set(Optional.of(regOps));
|
|
||||||
WorldBootstrap.InGUI.registryReadyOnLoadedWorld(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;
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
|
||||||
// }
|
|
||||||
}
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -14,11 +14,13 @@ import org.betterx.worlds.together.worldPreset.WorldPresets;
|
||||||
|
|
||||||
import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent;
|
import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent;
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.core.LayeredRegistryAccess;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.core.RegistryAccess;
|
import net.minecraft.core.RegistryAccess;
|
||||||
import net.minecraft.nbt.Tag;
|
import net.minecraft.nbt.Tag;
|
||||||
import net.minecraft.resources.RegistryOps;
|
import net.minecraft.resources.RegistryOps;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
|
import net.minecraft.server.RegistryLayer;
|
||||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||||
import net.minecraft.world.level.dimension.LevelStem;
|
import net.minecraft.world.level.dimension.LevelStem;
|
||||||
import net.minecraft.world.level.levelgen.WorldDimensions;
|
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 net.minecraft.world.level.storage.LevelStorageSource;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
@ -41,11 +44,13 @@ public class WorldBootstrap {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RegistryAccess getLastRegistryAccessOrElseBuiltin() {
|
public static RegistryAccess getLastRegistryAccessOrElseBuiltin() {
|
||||||
if (LAST_REGISTRY_ACCESS == null)
|
if (LAST_REGISTRY_ACCESS == null) {
|
||||||
WorldsTogether.LOGGER.error("Tried to read from global registry!");
|
WorldsTogether.LOGGER.error("Tried to read from global registry!");
|
||||||
|
}
|
||||||
return LAST_REGISTRY_ACCESS;
|
return LAST_REGISTRY_ACCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class Helpers {
|
public static class Helpers {
|
||||||
private static void initializeWorldConfig(
|
private static void initializeWorldConfig(
|
||||||
LevelStorageSource.LevelStorageAccess levelStorageAccess,
|
LevelStorageSource.LevelStorageAccess levelStorageAccess,
|
||||||
|
@ -320,7 +325,20 @@ public class WorldBootstrap {
|
||||||
WorldEventsImpl.ON_FINALIZED_WORLD_LOAD.emit(e -> e.done(dimensionRegistry));
|
WorldEventsImpl.ON_FINALIZED_WORLD_LOAD.emit(e -> e.done(dimensionRegistry));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Registry<LevelStem> enforceInNewWorld(Registry<LevelStem> dimensionRegistry) {
|
public static LayeredRegistryAccess<RegistryLayer> enforceInLayeredRegistry(LayeredRegistryAccess<RegistryLayer> registries) {
|
||||||
return WorldGenUtil.repairBiomeSourceInAllDimensions(LAST_REGISTRY_ACCESS, dimensionRegistry);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"package": "org.betterx.worlds.together.mixin.client",
|
"package": "org.betterx.worlds.together.mixin.client",
|
||||||
"compatibilityLevel": "JAVA_17",
|
"compatibilityLevel": "JAVA_17",
|
||||||
"client": [
|
"client": [
|
||||||
"CreateWorldScreenMixin",
|
"CreateWorldScreen_Mixin",
|
||||||
"WorldGenSettingsComponentMixin",
|
"WorldGenSettingsComponentMixin",
|
||||||
"WorldOpenFlowsMixin"
|
"WorldOpenFlowsMixin"
|
||||||
],
|
],
|
||||||
|
|
|
@ -18,12 +18,12 @@
|
||||||
"RegistryDataLoaderMixin",
|
"RegistryDataLoaderMixin",
|
||||||
"RegistryOpsAccessor",
|
"RegistryOpsAccessor",
|
||||||
"TagLoaderMixin",
|
"TagLoaderMixin",
|
||||||
"WorldDimensionsMixin",
|
|
||||||
"WorldGenPropertiesMixin",
|
"WorldGenPropertiesMixin",
|
||||||
"WorldLoaderMixin",
|
"WorldLoaderMixin",
|
||||||
"WorldPresetAccessor",
|
"WorldPresetAccessor",
|
||||||
"WorldPresetMixin",
|
"WorldPresetMixin",
|
||||||
"WorldPresetsBootstrapMixin"
|
"WorldPresetsBootstrapMixin",
|
||||||
|
"WorldStem_Mixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue