Fixed MainMixin
to manually parse options and start the DataFixer
(#55)
This commit is contained in:
parent
16b5dc3822
commit
a724f81091
1 changed files with 27 additions and 5 deletions
|
@ -1,19 +1,41 @@
|
||||||
package ru.bclib.mixin.common;
|
package ru.bclib.mixin.common;
|
||||||
|
|
||||||
|
import joptsimple.ArgumentAcceptingOptionSpec;
|
||||||
|
import joptsimple.OptionParser;
|
||||||
|
import joptsimple.OptionSet;
|
||||||
import net.minecraft.server.Main;
|
import net.minecraft.server.Main;
|
||||||
|
import net.minecraft.server.dedicated.DedicatedServerSettings;
|
||||||
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.injection.At;
|
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.LifeCycleAPI;
|
||||||
import ru.bclib.api.datafixer.DataFixerAPI;
|
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)
|
@Mixin(Main.class)
|
||||||
abstract public class MainMixin {
|
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;"))
|
@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 LevelStorageSource.LevelStorageAccess bclib_callServerFix(LevelStorageSource.LevelStorageAccess session){
|
private static void bclib_callServerFix(String[] args, CallbackInfo ci){
|
||||||
DataFixerAPI.fixData(session, false, (didFix)->{/* not called when showUI==false */});
|
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();
|
LifeCycleAPI._runBeforeLevelLoad();
|
||||||
return session;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue