mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-27 15:33:18 +00:00
147 lines
9.0 KiB
Diff
147 lines
9.0 KiB
Diff
--- a/net/minecraft/server/Main.java
|
|
+++ b/net/minecraft/server/Main.java
|
|
@@ -83,6 +_,17 @@
|
|
OptionSpec<Void> optionspec13 = optionparser.accepts("jfrProfile");
|
|
OptionSpec<Path> optionspec14 = optionparser.accepts("pidFile").withRequiredArg().withValuesConvertedBy(new PathConverter());
|
|
OptionSpec<String> optionspec15 = optionparser.nonOptions();
|
|
+ optionparser.accepts("allowUpdates").withRequiredArg().ofType(Boolean.class).defaultsTo(Boolean.TRUE); // Forge: allow mod updates to proceed
|
|
+ optionparser.accepts("gameDir").withRequiredArg().ofType(File.class).defaultsTo(new File(".")); //Forge: Consume this argument, we use it in the launcher, and the client side.
|
|
+ final OptionSpec<net.minecraft.core.BlockPos> spawnPosOpt;
|
|
+ OptionSpec<Void> uniqueWorld = null;
|
|
+ boolean gametestEnabled = Boolean.getBoolean("forge.gameTestServer");
|
|
+ if (gametestEnabled) {
|
|
+ spawnPosOpt = optionparser.accepts("spawnPos").withRequiredArg().withValuesConvertedBy(new net.minecraftforge.gametest.BlockPosValueConverter()).defaultsTo(new net.minecraft.core.BlockPos(0, 60, 0));
|
|
+ uniqueWorld = optionparser.accepts("uniqueWorld");
|
|
+ } else {
|
|
+ spawnPosOpt = null;
|
|
+ }
|
|
|
|
try {
|
|
OptionSet optionset = optionparser.parse(p_129699_);
|
|
@@ -91,6 +_,14 @@
|
|
return;
|
|
}
|
|
|
|
+ Path path2 = Paths.get("eula.txt");
|
|
+ Eula eula = new Eula(path2);
|
|
+
|
|
+ if (!eula.hasAgreedToEULA()) {
|
|
+ LOGGER.info("You need to agree to the EULA in order to run the server. Go to eula.txt for more info.");
|
|
+ return;
|
|
+ }
|
|
+
|
|
Path path = optionset.valueOf(optionspec14);
|
|
if (path != null) {
|
|
writePidFile(path);
|
|
@@ -105,24 +_,29 @@
|
|
Bootstrap.validate();
|
|
Util.startTimerHackThread();
|
|
Path path1 = Paths.get("server.properties");
|
|
+ if (!optionset.has(optionspec1)) {
|
|
+ // Load mods before we load almost anything else anymore. Single spot now. Only loads if they haven't passed the initserver param
|
|
+ net.minecraftforge.server.loading.ServerModLoader.load();
|
|
+ }
|
|
DedicatedServerSettings dedicatedserversettings = new DedicatedServerSettings(path1);
|
|
dedicatedserversettings.forceSave();
|
|
RegionFileVersion.configure(dedicatedserversettings.getProperties().regionFileComression);
|
|
- Path path2 = Paths.get("eula.txt");
|
|
- Eula eula = new Eula(path2);
|
|
+
|
|
if (optionset.has(optionspec1)) {
|
|
LOGGER.info("Initialized '{}' and '{}'", path1.toAbsolutePath(), path2.toAbsolutePath());
|
|
return;
|
|
}
|
|
|
|
- if (!eula.hasAgreedToEULA()) {
|
|
- LOGGER.info("You need to agree to the EULA in order to run the server. Go to eula.txt for more info.");
|
|
- return;
|
|
- }
|
|
-
|
|
File file1 = new File(optionset.valueOf(optionspec9));
|
|
Services services = Services.create(new YggdrasilAuthenticationService(Proxy.NO_PROXY), file1);
|
|
String s = Optional.ofNullable(optionset.valueOf(optionspec10)).orElse(dedicatedserversettings.getProperties().levelName);
|
|
+ // Forge: make each gametest use a timestamped world name
|
|
+ if (uniqueWorld != null && optionset.has(uniqueWorld))
|
|
+ s = "gametest_world\\" + java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss.SSS").format(java.time.LocalDateTime.now());
|
|
+ if (s == null || s.isEmpty() || new File(file1, s).getAbsolutePath().equals(new File(s).getAbsolutePath())) {
|
|
+ LOGGER.error("Invalid world directory specified, must not be null, empty or the same directory as your universe! " + s);
|
|
+ return;
|
|
+ }
|
|
LevelStorageSource levelstoragesource = LevelStorageSource.createDefault(file1.toPath());
|
|
LevelStorageSource.LevelStorageAccess levelstoragesource$levelstorageaccess = levelstoragesource.validateAndCreateAccess(s);
|
|
Dynamic<?> dynamic;
|
|
@@ -173,6 +_,10 @@
|
|
|
|
PackRepository packrepository = ServerPacksSource.createPackRepository(levelstoragesource$levelstorageaccess);
|
|
|
|
+ if (dynamic != null) {
|
|
+ net.minecraftforge.common.ForgeHooks.readAdditionalLevelSaveData(levelstoragesource$levelstorageaccess, levelstoragesource$levelstorageaccess.getLevelDirectory());
|
|
+ }
|
|
+
|
|
WorldStem worldstem;
|
|
try {
|
|
WorldLoader.InitConfig worldloader$initconfig = loadOrCreateConfig(dedicatedserversettings.getProperties(), dynamic1, flag, packrepository);
|
|
@@ -214,6 +_,16 @@
|
|
worlddimensions = dedicatedserverproperties.createDimensions(p_308589_.datapackWorldgen());
|
|
}
|
|
|
|
+ //Forge: Do a write-read-cycle to inject modded dimensions on first start of a dedicated server into its generated world dimensions list.
|
|
+ var dynamicops = net.minecraft.resources.RegistryOps.create(net.minecraft.nbt.NbtOps.INSTANCE, p_308589_.datapackWorldgen());
|
|
+ worlddimensions = WorldDimensions.CODEC.encoder()
|
|
+ .encodeStart(dynamicops, worlddimensions)
|
|
+ .flatMap((writtenPayloadWithModdedDimensions) ->
|
|
+ WorldDimensions.CODEC.decoder().parse(dynamicops, writtenPayloadWithModdedDimensions)
|
|
+ )
|
|
+ .resultOrPartial(LOGGER::error)
|
|
+ .orElse(worlddimensions);
|
|
+
|
|
WorldDimensions.Complete worlddimensions$complete = worlddimensions.bake(registry);
|
|
Lifecycle lifecycle = worlddimensions$complete.lifecycle().add(p_308589_.datapackWorldgen().allRegistriesLifecycle());
|
|
return new WorldLoader.DataLoadOutput<>(
|
|
@@ -244,9 +_,16 @@
|
|
|
|
WorldData worlddata = worldstem.worldData();
|
|
levelstoragesource$levelstorageaccess.saveDataTag(registryaccess$frozen, worlddata);
|
|
- final DedicatedServer dedicatedserver = MinecraftServer.spin(
|
|
+ final MinecraftServer dedicatedserver = MinecraftServer.spin(
|
|
p_296433_ -> {
|
|
- DedicatedServer dedicatedserver1 = new DedicatedServer(
|
|
+ MinecraftServer dedicatedserver1;
|
|
+ if (gametestEnabled) {
|
|
+ net.minecraftforge.gametest.ForgeGameTestHooks.registerGametests();
|
|
+ var tests = net.minecraft.gametest.framework.GameTestRegistry.getAllTestFunctions();
|
|
+ var spawnPos = optionset.valueOf(spawnPosOpt);
|
|
+ dedicatedserver1 = net.minecraft.gametest.framework.GameTestServer.create(p_296433_, levelstoragesource$levelstorageaccess, packrepository, tests, spawnPos);
|
|
+ } else {
|
|
+ dedicatedserver1 = new DedicatedServer(
|
|
p_296433_,
|
|
levelstoragesource$levelstorageaccess,
|
|
packrepository,
|
|
@@ -256,12 +_,13 @@
|
|
services,
|
|
LoggerChunkProgressListener::createFromGameruleRadius
|
|
);
|
|
+ }
|
|
dedicatedserver1.setPort(optionset.valueOf(optionspec11));
|
|
dedicatedserver1.setDemo(optionset.has(optionspec2));
|
|
dedicatedserver1.setId(optionset.valueOf(optionspec12));
|
|
boolean flag2 = !optionset.has(optionspec) && !optionset.valuesOf(optionspec15).contains("nogui");
|
|
- if (flag2 && !GraphicsEnvironment.isHeadless()) {
|
|
- dedicatedserver1.showGui();
|
|
+ if (flag2 && !GraphicsEnvironment.isHeadless() && dedicatedserver1 instanceof DedicatedServer ds) {
|
|
+ ds.showGui();
|
|
}
|
|
|
|
return dedicatedserver1;
|
|
@@ -270,7 +_,10 @@
|
|
Thread thread = new Thread("Server Shutdown Thread") {
|
|
@Override
|
|
public void run() {
|
|
+ // FORGE: Halting as GameTestServer will cause issues as it always calls System#exit on both crash and normal exit, so skip it
|
|
+ if (!(dedicatedserver instanceof net.minecraft.gametest.framework.GameTestServer))
|
|
dedicatedserver.halt(true);
|
|
+ org.apache.logging.log4j.LogManager.shutdown(); // we're manually managing the logging shutdown on the server. Make sure we do it here at the end.
|
|
}
|
|
};
|
|
thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER));
|