Skip to content

Commit

Permalink
Fixed MainMixin to manually parse options and start the DataFixer (
Browse files Browse the repository at this point in the history
  • Loading branch information
quiqueck committed Dec 5, 2021
1 parent 16b5dc3 commit a724f81
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/main/java/ru/bclib/mixin/common/MainMixin.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
package ru.bclib.mixin.common;

import joptsimple.ArgumentAcceptingOptionSpec;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import net.minecraft.server.Main;
import net.minecraft.server.dedicated.DedicatedServerSettings;
import net.minecraft.world.level.storage.LevelStorageSource;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import ru.bclib.api.LifeCycleAPI;
import ru.bclib.api.datafixer.DataFixerAPI;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;

@Mixin(Main.class)
abstract public class MainMixin {
@ModifyArg(method="main", at=@At(value="INVOKE_ASSIGN", target="Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;getSummary()Lnet/minecraft/world/level/storage/LevelSummary;"))
private static LevelStorageSource.LevelStorageAccess bclib_callServerFix(LevelStorageSource.LevelStorageAccess session){
DataFixerAPI.fixData(session, false, (didFix)->{/* not called when showUI==false */});
@Inject(method="main", at=@At(value="INVOKE", target="Lnet/minecraft/world/level/storage/LevelStorageSource;createDefault(Ljava/nio/file/Path;)Lnet/minecraft/world/level/storage/LevelStorageSource;"))
private static void bclib_callServerFix(String[] args, CallbackInfo ci){
OptionParser parser = new OptionParser();
ArgumentAcceptingOptionSpec<String> optionUniverse = parser.accepts("universe").withRequiredArg().defaultsTo(".", new String[0]);
ArgumentAcceptingOptionSpec<String> optionWorld = parser.accepts("world").withRequiredArg();
OptionSet options = parser.parse(args);

Path settingPath = Paths.get("server.properties", new String[0]);
DedicatedServerSettings settings = new DedicatedServerSettings(settingPath);

File file = new File(options.valueOf(optionUniverse));
String levelID = Optional.ofNullable(options.valueOf(optionWorld)).orElse(settings.getProperties().levelName);

LevelStorageSource levelStorageSource = LevelStorageSource.createDefault(file.toPath());
DataFixerAPI.fixData(levelStorageSource, levelID, false, (didFix)->{/* not called when showUI==false */});

LifeCycleAPI._runBeforeLevelLoad();
return session;
}
}

0 comments on commit a724f81

Please sign in to comment.