Skip to content

Commit

Permalink
Merge branch '2022.1' into 2022.2
Browse files Browse the repository at this point in the history
  • Loading branch information
RedNesto committed Jun 14, 2022
2 parents 82ae46f + dcb7973 commit 4b37a8b
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 9 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ kotlin.code.style=official
ideaVersion = 222-EAP-SNAPSHOT
ideaVersionName = 2022.2

coreVersion = 1.5.19
coreVersion = 1.5.20
downloadIdeaSources = true

pluginTomlVersion = 222.2964.16
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ class MinecraftClassCreateAction :
override fun isAvailable(dataContext: DataContext): Boolean {
val psi = dataContext.getData(CommonDataKeys.PSI_ELEMENT)
val module = psi?.findModule() ?: return false
val isModModule = MinecraftFacet.getInstance(module, FabricModuleType, ForgeModuleType) != null
val isFabricMod = MinecraftFacet.getInstance(module, FabricModuleType) != null
val isForgeMod = MinecraftFacet.getInstance(module, ForgeModuleType) != null
val hasMcVersion = MinecraftFacet.getInstance(module, McpModuleType)?.getSettings()?.minecraftVersion != null

return isModModule && hasMcVersion && super.isAvailable(dataContext)
return (isFabricMod || isForgeMod && hasMcVersion) && super.isAvailable(dataContext)
}

override fun checkPackageExists(directory: PsiDirectory): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package com.demonwav.mcdev.platform.architectury.creator

import com.demonwav.mcdev.creator.buildsystem.BuildSystem
import com.demonwav.mcdev.platform.BaseTemplate
import com.demonwav.mcdev.platform.forge.util.ForgeConstants
import com.demonwav.mcdev.platform.forge.util.ForgePackAdditionalData
import com.demonwav.mcdev.platform.forge.util.ForgePackDescriptor
import com.demonwav.mcdev.util.License
Expand Down Expand Up @@ -178,6 +179,7 @@ object ArchitecturyTemplate : BaseTemplate() {
}

fun applyModsToml(project: Project, buildSystem: BuildSystem, config: ArchitecturyProjectConfig): String {
val hasDisplayTestInManifest = config.forgeVersion >= ForgeConstants.DISPLAY_TEST_MANIFEST_VERSION
val nextMcVersion = when (val part = config.mcVersion.parts.getOrNull(1)) {
// Mimics the code used to get the next Minecraft version in Forge's MDK
// https://github.com/MinecraftForge/MinecraftForge/blob/0ff8a596fc1ef33d4070be89dd5cb4851f93f731/build.gradle#L884
Expand All @@ -188,6 +190,7 @@ object ArchitecturyTemplate : BaseTemplate() {
val props = mutableMapOf(
"ARTIFACT_ID" to buildSystem.artifactId,
"MOD_NAME" to config.pluginName,
"DISPLAY_TEST" to hasDisplayTestInManifest,
"FORGE_SPEC_VERSION" to config.forgeVersion.parts[0].versionString,
"ARCHITECTURY_API_VERSION" to config.architecturyApiVersion.toString(),
"MC_VERSION" to config.mcVersion.toString(),
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/platform/forge/creator/Fg3Template.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package com.demonwav.mcdev.platform.forge.creator

import com.demonwav.mcdev.creator.buildsystem.BuildSystem
import com.demonwav.mcdev.platform.BaseTemplate
import com.demonwav.mcdev.platform.forge.util.ForgeConstants
import com.demonwav.mcdev.platform.forge.util.ForgePackAdditionalData
import com.demonwav.mcdev.platform.forge.util.ForgePackDescriptor
import com.demonwav.mcdev.util.MinecraftTemplates.Companion.FG3_1_17_MAIN_CLASS_TEMPLATE
Expand Down Expand Up @@ -183,6 +184,7 @@ object Fg3Template : BaseTemplate() {
}

fun applyModsToml(project: Project, buildSystem: BuildSystem, config: ForgeProjectConfig): String {
val hasDisplayTestInManifest = config.forgeVersion >= ForgeConstants.DISPLAY_TEST_MANIFEST_VERSION
val nextMcVersion = when (val part = config.mcVersion.parts.getOrNull(1)) {
// Mimics the code used to get the next Minecraft version in Forge's MDK
// https://github.com/MinecraftForge/MinecraftForge/blob/0ff8a596fc1ef33d4070be89dd5cb4851f93f731/build.gradle#L884
Expand All @@ -193,6 +195,7 @@ object Fg3Template : BaseTemplate() {
val props = mutableMapOf(
"ARTIFACT_ID" to buildSystem.artifactId,
"MOD_NAME" to config.pluginName,
"DISPLAY_TEST" to hasDisplayTestInManifest,
"FORGE_SPEC_VERSION" to config.forgeVersion.parts[0].versionString,
"MC_VERSION" to config.mcVersion.toString(),
"MC_NEXT_VERSION" to "1.$nextMcVersion",
Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/platform/forge/util/ForgeConstants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

package com.demonwav.mcdev.platform.forge.util

import com.demonwav.mcdev.util.SemanticVersion

object ForgeConstants {

const val SIDED_PROXY_ANNOTATION = "net.minecraftforge.fml.common.SidedProxy"
Expand All @@ -32,9 +34,12 @@ object ForgeConstants {
// From https://github.com/MinecraftForge/MinecraftForge/blob/0ff8a596fc1ef33d4070be89dd5cb4851f93f731/src/fmllauncher/java/net/minecraftforge/fml/loading/StringSubstitutor.java
val KNOWN_SUBSTITUTIONS = setOf(JAR_VERSION_VAR, "\${global.mcVersion}", "\${global.forgeVersion}")

val DISPLAY_TESTS = setOf("MATCH_VERSION", "IGNORE_SERVER_VERSION", "IGNORE_ALL_VERSION", "NONE")
val DEPENDENCY_SIDES = setOf("BOTH", "CLIENT", "SERVER")
val DEPENDENCY_ORDER = setOf("NONE", "BEFORE", "AFTER")

// From https://github.com/MinecraftForge/MinecraftForge/blob/38a5400a8c878fe39cd389e6d4f68619d2738b88/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/ModInfo.java#L45
val MOD_ID_REGEX = "^[a-z][a-z0-9_-]{1,63}$".toRegex()

val DISPLAY_TEST_MANIFEST_VERSION = SemanticVersion.release(41, 0, 15)
}
3 changes: 2 additions & 1 deletion src/main/kotlin/platform/mcp/McpModuleSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class McpModuleSettings : PersistentStateComponent<McpModuleSettings.State> {
var minecraftVersion: String? = null,
var mcpVersion: String? = null,
var mappingFile: String? = null,
var srgType: SrgType? = null
var srgType: SrgType? = null,
var platformVersion: String? = null
)

private var state: State = State(srgType = SrgType.SRG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,28 @@ object McpModelFG3Handler : McpModelDataHandler {
) {
val data = resolverCtx.getExtraProject(gradleModule, McpModelFG3::class.java) ?: return

var version: String? = null
var mcVersion: String? = null
var forgeVersion: String? = null
for (minecraftDepVersion in data.minecraftDepVersions) {
val index = minecraftDepVersion.indexOf('-')
if (index == -1) {
continue
}
version = minecraftDepVersion.substring(0, minecraftDepVersion.indexOf('-'))
mcVersion = minecraftDepVersion.substring(0, index)

val forgeVersionEnd = minecraftDepVersion.indexOf('_')
if (forgeVersionEnd != -1) {
forgeVersion = minecraftDepVersion.substring(index + 1, forgeVersionEnd)
}
break
}

val state = McpModuleSettings.State(
version,
mcVersion,
data.mcpVersion,
data.taskOutputLocation.absolutePath,
SrgType.TSRG
SrgType.TSRG,
forgeVersion
)

val gradleProjectPath = gradleModule.gradleProject.projectIdentifier.projectPath
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/toml/platform/forge/ModsTomlSchema.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ logoBlur=false
credits="Thanks for this example mod goes to Java"
# A text field displayed in the mod UI.
authors="Love, Cheese and small house plants"
# Display Test controls the display for your mod in the server connection screen
# MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod.
# IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod.
# 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)
# The description text for the mod (multi line!)
description='''
This is a long form description of the mod. You can write whatever you want here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ModsTomlCompletionContributor : CompletionContributor() {
extend(CompletionType.BASIC, inModsTomlKey(), ModsTomlKeyCompletionProvider)
extendKnownValues("modLoader", "javafml")
extendKnownValues("version", ForgeConstants.KNOWN_SUBSTITUTIONS)
extendKnownValues("displayTest", ForgeConstants.DISPLAY_TESTS)
extendKnownValues("ordering", ForgeConstants.DEPENDENCY_ORDER)
extendKnownValues("side", ForgeConstants.DEPENDENCY_SIDES)
extendBooleanValues("showAsResourcePack")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import com.demonwav.mcdev.toml.TomlElementVisitor
import com.demonwav.mcdev.toml.platform.forge.ModsTomlSchema
import com.demonwav.mcdev.toml.stringValue
import com.demonwav.mcdev.toml.tomlType
import com.demonwav.mcdev.util.SemanticVersion
import com.demonwav.mcdev.util.findMcpModule
import com.intellij.codeInspection.InspectionManager
import com.intellij.codeInspection.LocalInspectionTool
import com.intellij.codeInspection.ProblemDescriptor
Expand Down Expand Up @@ -65,6 +67,22 @@ class ModsTomlValidationInspection : LocalInspectionTool() {
holder.registerProblem(value, TextRange(1, endOffset), "Mod ID is invalid")
}
}
"displayTest" -> {
val value = keyValue.value ?: return
val test = value.stringValue() ?: return
if (test !in ForgeConstants.DISPLAY_TESTS) {
val endOffset = if (value.text.endsWith('"')) test.length + 1 else test.length
holder.registerProblem(value, TextRange(1, endOffset), "DisplayTest $test does not exist")
}

val forgeVersion = runCatching {
keyValue.findMcpModule()?.getSettings()?.platformVersion?.let(SemanticVersion::parse)
}.getOrNull()
val minVersion = ForgeConstants.DISPLAY_TEST_MANIFEST_VERSION
if (forgeVersion != null && forgeVersion < minVersion) {
holder.registerProblem(keyValue.key, "DisplayTest is only available since $minVersion")
}
}
"side" -> {
val value = keyValue.value ?: return
val side = value.stringValue() ?: return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ logoFile="icon.png" #optional
authors="${AUTHOR_LIST}" #optional
#else
#authors="Love, Cheese and small house plants" #optional
#end
#if (${DISPLAY_TEST})
# Display Test controls the display for your mod in the server connection screen
# MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod.
# IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod.
# 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)

#end
# The description text for the mod (multi line!) (#mandatory)
description='''
Expand Down Expand Up @@ -79,4 +89,4 @@ ${DESCRIPTION}
versionRange = "[${ARCHITECTURY_API_VERSION},)"
ordering = "AFTER"
side = "BOTH"
#end
#end
10 changes: 10 additions & 0 deletions src/main/resources/fileTemplates/j2ee/forge/mods.toml.ft
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ updateJSONURL="${UPDATE_URL}" #optional
authors="${AUTHOR_LIST}" #optional
#else
#authors="Love, Cheese and small house plants" #optional
#end
#if (${DISPLAY_TEST})
# Display Test controls the display for your mod in the server connection screen
# MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod.
# IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod.
# 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)

#end
# The description text for the mod (multi line!) (#mandatory)
description='''
Expand Down
13 changes: 13 additions & 0 deletions src/test/kotlin/platform/forge/ModsTomlCompletionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class ModsTomlCompletionTest : BasePlatformTestCase() {
"logoBlur",
"credits",
"authors",
"displayTest",
"description"
)
}
Expand Down Expand Up @@ -89,6 +90,18 @@ class ModsTomlCompletionTest : BasePlatformTestCase() {
myFixture.testCompletionVariants("boolean/mods.toml", "true", "false")
}

@Test
@DisplayName("Display Test Value")
fun displayTestValue() {
myFixture.testCompletionVariants(
"displayTestValue/mods.toml",
"MATCH_VERSION",
"IGNORE_SERVER_VERSION",
"IGNORE_ALL_VERSION",
"NONE"
)
}

@Test
@DisplayName("Dependency Ordering Value")
fun orderingValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ mandatory=true
"""
[[mods]]
modId="examplemod"
displayTest="<error descr="DisplayTest IGNORE_SERV does not exist">IGNORE_SERV</error>"
[[dependencies.examplemod]]
modId="forge"
ordering="<error descr="Order BEFO does not exist">BEFO</error>"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[[mods]]
displayTest=<caret>

0 comments on commit 4b37a8b

Please sign in to comment.