[Fixed] Server Crash on Startup

This commit is contained in:
Frank 2023-12-18 17:50:56 +01:00
parent f274de6f6f
commit 60963e449b
3 changed files with 24 additions and 23 deletions

View file

@ -1,12 +1,9 @@
package org.betterx.bclib.config; package org.betterx.bclib.config;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
public class Configs { public class Configs {
// Client and Server-Config must be the first entries. They are not part of the Auto-Sync process // Client and Server-Config must be the first entries. They are not part of the Auto-Sync process
// But will be needed by other Auto-Sync Config-Files // But will be needed by other Auto-Sync Config-Files
@Environment(EnvType.CLIENT) //@Environment(EnvType.CLIENT)
public static final ClientConfig CLIENT_CONFIG = new ClientConfig(); public static final ClientConfig CLIENT_CONFIG = new ClientConfig();
public static final ServerConfig SERVER_CONFIG = new ServerConfig(); public static final ServerConfig SERVER_CONFIG = new ServerConfig();

View file

@ -7,21 +7,23 @@ import net.minecraft.server.Main;
import net.minecraft.world.level.storage.LevelStorageSource; import net.minecraft.world.level.storage.LevelStorageSource;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.ModifyVariable;
@Mixin(value = Main.class, priority = 200) @Mixin(value = Main.class, priority = 200)
abstract public class MainMixin { abstract public class MainMixin {
@Unique
private static LevelStorageSource.LevelStorageAccess bcl_levelStorageAccess = null; 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;")) @ModifyVariable(method = "main", ordinal = 0, at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;getDataTag()Lcom/mojang/serialization/Dynamic;"))
private static LevelStorageSource.LevelStorageAccess bc_createAccess(LevelStorageSource.LevelStorageAccess levelStorageAccess) { private static LevelStorageSource.LevelStorageAccess bc_createAccess(LevelStorageSource.LevelStorageAccess levelStorageAccess) {
bcl_levelStorageAccess = levelStorageAccess; bcl_levelStorageAccess = levelStorageAccess;
WorldBootstrap.DedicatedServer.applyWorldPatches(levelStorageAccess); WorldBootstrap.DedicatedServer.applyWorldPatches(levelStorageAccess);
return levelStorageAccess; return levelStorageAccess;
} }
@ModifyArg(method = "main", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;saveDataTag(Lnet/minecraft/core/RegistryAccess;Lnet/minecraft/world/level/storage/WorldData;)V")) @ModifyArg(method = "main", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;saveDataTag(Lnet/minecraft/core/RegistryAccess;Lnet/minecraft/world/level/storage/WorldData;)V"))
private static RegistryAccess bcl_onCreate(RegistryAccess registryAccess) { private static RegistryAccess bcl_onCreate(RegistryAccess registryAccess) {
WorldBootstrap.DedicatedServer.registryReady(registryAccess); WorldBootstrap.DedicatedServer.registryReady(registryAccess);

View file

@ -114,25 +114,27 @@ public class WorldBootstrap {
} }
public static void setupWorld(LevelStorageSource.LevelStorageAccess levelStorageAccess) { public static void setupWorld(LevelStorageSource.LevelStorageAccess levelStorageAccess) {
File levelDat = levelStorageAccess.getLevelPath(LevelResource.LEVEL_DATA_FILE).toFile(); if (levelStorageAccess != null && levelStorageAccess.hasWorldData()) {
if (!levelDat.exists()) { File levelDat = levelStorageAccess.getLevelPath(LevelResource.LEVEL_DATA_FILE).toFile();
WorldsTogether.LOGGER.info("Creating a new World, no fixes needed"); if (!levelDat.exists()) {
final WorldDimensions dimensions = Helpers.defaultServerDimensions(); WorldsTogether.LOGGER.info("Creating a new World, no fixes needed");
final WorldDimensions dimensions = Helpers.defaultServerDimensions();
WorldBootstrap.setupWorld( WorldBootstrap.setupWorld(
levelStorageAccess, TogetherWorldPreset.getDimensionMap(dimensions), levelStorageAccess, TogetherWorldPreset.getDimensionMap(dimensions),
true, true true, true
); );
Holder<WorldPreset> currentPreset = Helpers.defaultServerPreset(); Holder<WorldPreset> currentPreset = Helpers.defaultServerPreset();
writeWorldPresets(dimensions, currentPreset); writeWorldPresets(dimensions, currentPreset);
finishedWorldLoad(); finishedWorldLoad();
} else { } else {
WorldBootstrap.setupWorld( WorldBootstrap.setupWorld(
levelStorageAccess, TogetherWorldPreset.loadWorldDimensions(), levelStorageAccess, TogetherWorldPreset.loadWorldDimensions(),
false, true false, true
); );
finishedWorldLoad(); finishedWorldLoad();
}
} }
} }