Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make server configs used across saves by default #376

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jetbrains_annotations_version=24.0.1
slf4j_api_version=2.0.7
apache_maven_artifact_version=3.8.5
jarjar_version=0.4.0
fancy_mod_loader_version=1.0.17
fancy_mod_loader_version=2.0.0
mojang_logging_version=1.1.1
log4j_version=2.19.0
guava_version=31.1.2-jre
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package net.neoforged.neoforge.server;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
Expand Down Expand Up @@ -40,6 +41,7 @@
import net.neoforged.fml.config.ConfigTracker;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.fml.loading.FMLEnvironment;
import net.neoforged.fml.loading.FMLPaths;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.common.util.LogicalSidedProvider;
import net.neoforged.neoforge.common.world.BiomeModifier;
Expand Down Expand Up @@ -82,14 +84,26 @@ private static Path getServerConfigPath(final MinecraftServer server) {
throw new RuntimeException(e);
}
}
final Path explanation = serverConfig.resolve("readme.txt");
if (!Files.exists(explanation)) {
try {
Files.writeString(explanation, """
Any server configs put in this folder will override the corresponding server config from <instance path>/config/<config path>.
If the config being transferred is in a subfolder of the base config folder make sure to include that folder here in the path to the file you are overwriting.
For example if you are overwriting a config with the path <instance path>/config/ExampleMod/config-server.toml, you would need to put it in serverconfig/ExampleMod/config-server.toml
""", StandardCharsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return serverConfig;
}

public static void handleServerAboutToStart(final MinecraftServer server) {
currentServer = server;
// on the dedi server we need to force the stuff to setup properly
LogicalSidedProvider.setServer(() -> server);
ConfigTracker.INSTANCE.loadConfigs(ModConfig.Type.SERVER, getServerConfigPath(server));
ConfigTracker.INSTANCE.loadConfigs(ModConfig.Type.SERVER, FMLPaths.CONFIGDIR.get(), getServerConfigPath(server));
runModifiers(server);
NeoForge.EVENT_BUS.post(new ServerAboutToStartEvent(server));
}
Expand Down Expand Up @@ -130,7 +144,7 @@ public static void handleServerStopped(final MinecraftServer server) {
latch.countDown();
exitLatch = null;
}
ConfigTracker.INSTANCE.unloadConfigs(ModConfig.Type.SERVER, getServerConfigPath(server));
ConfigTracker.INSTANCE.unloadConfigs(ModConfig.Type.SERVER);
}

public static MinecraftServer getCurrentServer() {
Expand Down
Loading