[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;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
public class Configs {
// 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
@Environment(EnvType.CLIENT)
//@Environment(EnvType.CLIENT)
public static final ClientConfig CLIENT_CONFIG = new ClientConfig();
public static final ServerConfig SERVER_CONFIG = new ServerConfig();

View file

@ -7,15 +7,17 @@ import net.minecraft.server.Main;
import net.minecraft.world.level.storage.LevelStorageSource;
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.ModifyArg;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
@Mixin(value = Main.class, priority = 200)
abstract public class MainMixin {
@Unique
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) {
bcl_levelStorageAccess = levelStorageAccess;
WorldBootstrap.DedicatedServer.applyWorldPatches(levelStorageAccess);

View file

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