diff --git a/fmlcore/src/main/java/net/minecraftforge/fml/ModContainer.java b/fmlcore/src/main/java/net/minecraftforge/fml/ModContainer.java index cbe678c6f8..40f0748e15 100644 --- a/fmlcore/src/main/java/net/minecraftforge/fml/ModContainer.java +++ b/fmlcore/src/main/java/net/minecraftforge/fml/ModContainer.java @@ -58,7 +58,8 @@ public abstract class ModContainer this.modInfo = info; this.modLoadingStage = ModLoadingStage.CONSTRUCT; - final String displayTestString = info.getConfig().getConfigElement("displayTest").orElse("MATCH_VERSION"); // missing defaults to DEFAULT type + final String displayTestString = info.getConfig().getConfigElement("displayTest") + .orElseGet(() -> info.getOwningFile().isClientSideOnly() ? "IGNORE_ALL_VERSION" : "MATCH_VERSION"); Supplier displayTestSupplier = switch (displayTestString) { case "MATCH_VERSION" -> // default displaytest checks for version string match () -> new IExtensionPoint.DisplayTest(() -> this.modInfo.getVersion().toString(), diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModDiscoverer.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModDiscoverer.java index 4bcb1a773d..2b111a3445 100644 --- a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModDiscoverer.java +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModDiscoverer.java @@ -12,6 +12,7 @@ import cpw.mods.modlauncher.Launcher; import cpw.mods.modlauncher.api.IModuleLayerManager; import cpw.mods.modlauncher.util.ServiceLoaderUtils; import net.minecraftforge.fml.loading.EarlyLoadingException; +import net.minecraftforge.fml.loading.FMLLoader; import net.minecraftforge.fml.loading.ImmediateWindowHandler; import net.minecraftforge.fml.loading.LogMarkers; import net.minecraftforge.fml.loading.UniqueModListBuilder; @@ -70,6 +71,7 @@ public class ModDiscoverer { List discoveryErrorData = new ArrayList<>(); boolean successfullyLoadedMods = true; List brokenFiles = new ArrayList<>(); + boolean distIsDedicatedServer = FMLLoader.getDist().isDedicatedServer(); ImmediateWindowHandler.updateProgress("Discovering mod files"); //Loop all mod locators to get the prime mods to load from. for (IModLocator locator : modLocatorList) { @@ -88,8 +90,17 @@ public class ModDiscoverer { if (!badModFiles.isEmpty()) { LOGGER.error(LogMarkers.SCAN, "Locator {} returned {} files which is are not ModFile instances! They will be skipped!", locator, badModFiles.size()); brokenFiles.addAll(badModFiles.stream().map(IModFile::getModFileInfo).toList()); + locatedFiles.removeAll(badModFiles); } - locatedFiles.removeAll(badModFiles); + + if (distIsDedicatedServer) { + var clientOnlyModFiles = locatedFiles.stream().filter(file -> file.getModFileInfo().isClientSideOnly()).toList(); + if (!clientOnlyModFiles.isEmpty()) { + LOGGER.warn(LogMarkers.SCAN, "Locator {} returned {} files which are client-side-only mods, but we're on a dedicated server. They will be skipped!", locator, clientOnlyModFiles.size()); + locatedFiles.removeAll(clientOnlyModFiles); + } + } + LOGGER.debug(LogMarkers.SCAN, "Locator {} found {} valid mod files", locator, locatedFiles.size()); handleLocatedFiles(loadedFiles, locatedFiles); } catch (InvalidModFileException imfe) { diff --git a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFileInfo.java b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFileInfo.java index 6bfae72597..751ed3371d 100644 --- a/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFileInfo.java +++ b/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFileInfo.java @@ -45,6 +45,7 @@ public class ModFileInfo implements IModFileInfo, IConfigurable private final URL issueURL; private final List languageSpecs; private final boolean showAsResourcePack; + private final boolean clientSideOnly; private final boolean showAsDataPack; private final List mods; private final Map properties; @@ -69,6 +70,8 @@ public class ModFileInfo implements IModFileInfo, IConfigurable .orElse(""); this.showAsResourcePack = config.getConfigElement("showAsResourcePack") .orElse(false); + this.clientSideOnly = config.getConfigElement("clientSideOnly") + .orElse(false); this.showAsDataPack = config.getConfigElement("showAsDataPack") .orElse(false); this.usesServices = config.>getConfigElement("services") @@ -129,6 +132,12 @@ public class ModFileInfo implements IModFileInfo, IConfigurable return this.showAsResourcePack; } + @Override + public boolean isClientSideOnly() + { + return this.clientSideOnly; + } + @Override public boolean showAsDataPack() { diff --git a/mdk/src/main/resources/META-INF/mods.toml b/mdk/src/main/resources/META-INF/mods.toml index 95e8668984..80795f1f53 100644 --- a/mdk/src/main/resources/META-INF/mods.toml +++ b/mdk/src/main/resources/META-INF/mods.toml @@ -12,6 +12,9 @@ loaderVersion="${loader_version_range}" #mandatory This is typically bumped ever license="${mod_license}" # A URL to refer people to when problems occur with this mod #issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional +# If your mod is purely client-side and has no multiplayer functionality (be it dedicated servers or Open to LAN), +# set this to true, and Forge will set the correct displayTest for you and skip loading your mod on dedicated servers. +#clientSideOnly=true #optional - defaults to false if absent # A list of mods - how many allowed here is determined by the individual mod loader [[mods]] #mandatory # The modid of the mod @@ -36,7 +39,7 @@ authors="${mod_authors}" #optional # IGNORE_ALL_VERSION means that your mod will not cause a red X if it's present on the client or the server. This is a special case and should only be used if your mod has no server component. # NONE means that no display test is set on your mod. You need to do this yourself, see IExtensionPoint.DisplayTest for more information. You can define any scheme you wish with this value. # IMPORTANT NOTE: this is NOT an instruction as to which environments (CLIENT or DEDICATED SERVER) your mod loads on. Your mod should load (and maybe do nothing!) whereever it finds itself. -#displayTest="MATCH_VERSION" # MATCH_VERSION is the default if nothing is specified (#optional) +#displayTest="MATCH_VERSION" # if nothing is specified, MATCH_VERSION is the default when clientSideOnly=false, otherwise IGNORE_ALL_VERSION when clientSideOnly=true (#optional) # The description text for the mod (multi line!) (#mandatory) description='''${mod_description}''' @@ -67,4 +70,4 @@ description='''${mod_description}''' # that your mod requires GL version 3.2 or higher. Other features will be added. They are side aware so declaring this won't # stop your mod loading on the server for example. #[features.${mod_id}] -#openGLVersion="[3.2,)" \ No newline at end of file +#openGLVersion="[3.2,)"