User: paint_ninja Date: 18 Feb 24 21:45 Revision: 46c9d61150c33e4143deff933925373e0ec602c1 Summary: Improve Forge `clientSideOnly` support (#2236) * Improve support for `clientSideOnly` in mods.toml * Fix comment * Update ModsTomlValidationInspection.kt TeamCity URL: https://ci.mcdev.io/viewModification.html?tab=vcsModificationFiles&modId=9152&personal=false Index: src/main/kotlin/toml/platform/forge/ModsTomlSchema.kt =================================================================== --- src/main/kotlin/toml/platform/forge/ModsTomlSchema.kt (revision 986d133b8e602518ff809c207d21dfb7d2f10a71) +++ src/main/kotlin/toml/platform/forge/ModsTomlSchema.kt (revision 46c9d61150c33e4143deff933925373e0ec602c1) @@ -48,6 +48,8 @@ showAsResourcePack=false # A URL to refer people to when problems occur with this mod. issueTrackerURL="http://my.issue.tracker/" +# 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=false # A list of mods - how many allowed here is determined by the individual mod loader [[mods]] # The modid of the mod. @@ -74,7 +76,7 @@ # 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!) description=''' Index: src/main/kotlin/toml/platform/forge/completion/ModsTomlCompletionContributor.kt =================================================================== --- src/main/kotlin/toml/platform/forge/completion/ModsTomlCompletionContributor.kt (revision 986d133b8e602518ff809c207d21dfb7d2f10a71) +++ src/main/kotlin/toml/platform/forge/completion/ModsTomlCompletionContributor.kt (revision 46c9d61150c33e4143deff933925373e0ec602c1) @@ -58,6 +58,7 @@ extendBooleanValues("showAsResourcePack") extendBooleanValues("logoBlur") extendBooleanValues("mandatory") + extendBooleanValues("clientSideOnly") } private fun extendKnownValues(key: String, values: Set) = Index: src/main/kotlin/toml/platform/forge/inspections/ModsTomlValidationInspection.kt =================================================================== --- src/main/kotlin/toml/platform/forge/inspections/ModsTomlValidationInspection.kt (revision 986d133b8e602518ff809c207d21dfb7d2f10a71) +++ src/main/kotlin/toml/platform/forge/inspections/ModsTomlValidationInspection.kt (revision 46c9d61150c33e4143deff933925373e0ec602c1) @@ -112,8 +112,17 @@ holder.registerProblem(value, TextRange(1, endOffset), "Order $order does not exist") } } + "clientSideOnly" -> { + val forgeVersion = runCatching { + keyValue.findMcpModule()?.getSettings()?.platformVersion?.let(SemanticVersion::parse) + }.getOrNull() + val minVersion = ForgeConstants.CLIENT_ONLY_MANIFEST_VERSION + if (forgeVersion != null && forgeVersion < minVersion) { + holder.registerProblem(keyValue.key, "ClientSideOnly is only available since $minVersion") - } - } + } + } + } + } override fun visitKeySegment(keySegment: TomlKeySegment) { val key = keySegment.parent as? TomlKey ?: return Index: src/test/kotlin/platform/forge/ModsTomlCompletionTest.kt =================================================================== --- src/test/kotlin/platform/forge/ModsTomlCompletionTest.kt (revision 986d133b8e602518ff809c207d21dfb7d2f10a71) +++ src/test/kotlin/platform/forge/ModsTomlCompletionTest.kt (revision 46c9d61150c33e4143deff933925373e0ec602c1) @@ -53,6 +53,7 @@ "license", "showAsResourcePack", "issueTrackerURL", + "clientSideOnly", ) }