Skip to content

Commit

Permalink
Improve Forge clientSideOnly support (#2236)
Browse files Browse the repository at this point in the history
* Improve support for `clientSideOnly` in mods.toml

* Fix comment

* Update ModsTomlValidationInspection.kt
  • Loading branch information
PaintNinja authored Feb 18, 2024
1 parent 986d133 commit 46c9d61
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/kotlin/toml/platform/forge/ModsTomlSchema.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ license="All rights reserved"
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.
Expand All @@ -74,7 +76,7 @@ authors="Love, Cheese and small house plants"
# 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='''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class ModsTomlCompletionContributor : CompletionContributor() {
extendBooleanValues("showAsResourcePack")
extendBooleanValues("logoBlur")
extendBooleanValues("mandatory")
extendBooleanValues("clientSideOnly")
}

private fun extendKnownValues(key: String, values: Set<String>) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ class ModsTomlValidationInspection : LocalInspectionTool() {
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")
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/test/kotlin/platform/forge/ModsTomlCompletionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class ModsTomlCompletionTest : BasePlatformTestCase() {
"license",
"showAsResourcePack",
"issueTrackerURL",
"clientSideOnly",
)
}

Expand Down

0 comments on commit 46c9d61

Please sign in to comment.