User: rednesto Date: 09 Jul 23 16:26 Revision: f2f3b1c9dace3985c194b061b2e9761c6ca875d9 Summary: Add separate field for mod/plugin ID Fixes #2007 Fixes #2039 Fixes #2047 TeamCity URL: https://ci.mcdev.io/viewModification.html?tab=vcsModificationFiles&modId=8621&personal=false Index: src/main/kotlin/creator/step/ModIdStep.kt =================================================================== --- src/main/kotlin/creator/step/ModIdStep.kt (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) +++ src/main/kotlin/creator/step/ModIdStep.kt (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -0,0 +1,104 @@ +/* + * Minecraft Development for IntelliJ + * + * https://mcdev.io/ + * + * Copyright (C) 2023 minecraft-dev + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, version 3.0 only. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.demonwav.mcdev.creator.step + +import com.demonwav.mcdev.creator.storeToData +import com.intellij.ide.wizard.AbstractNewProjectWizardStep +import com.intellij.ide.wizard.NewProjectWizardBaseData +import com.intellij.ide.wizard.NewProjectWizardStep +import com.intellij.openapi.project.Project +import com.intellij.openapi.ui.validation.AFTER_GRAPH_PROPAGATION +import com.intellij.openapi.ui.validation.CHECK_NON_EMPTY +import com.intellij.openapi.ui.validation.and +import com.intellij.openapi.ui.validation.validationErrorIf +import com.intellij.openapi.util.Key +import com.intellij.ui.dsl.builder.COLUMNS_MEDIUM +import com.intellij.ui.dsl.builder.Panel +import com.intellij.ui.dsl.builder.bindText +import com.intellij.ui.dsl.builder.columns +import com.intellij.ui.dsl.builder.textValidation + +private val validModIdRegex = "[a-z][a-z0-9-_]{1,63}".toRegex() +private val invalidModIdRegex = "[^a-z0-9-_]+".toRegex() + +private val validForgeModIdRegex = "[a-z][a-z0-9_]{1,63}".toRegex() +private val invalidForgeModIdRegex = "[^a-z0-9_]+".toRegex() + +abstract class AbstractModIdStep( + parent: NewProjectWizardStep, + private val validRegex: Regex = validModIdRegex, + private val invalidRegex: Regex = invalidModIdRegex +) : AbstractNewProjectWizardStep(parent) { + private val baseData = data.getUserData(NewProjectWizardBaseData.KEY) + ?: throw IllegalStateException("Mod id step created without base step") + val idProperty = propertyGraph.lazyProperty(::suggestId) + var id by idProperty + + private val idValidation = validationErrorIf("Id must match $validRegex") { !it.matches(validRegex) } + + init { + idProperty.dependsOn(baseData.nameProperty, ::suggestId) + storeToData() + } + + fun suggestId(): String { + val sanitized = baseData.name.lowercase().replace(invalidRegex, "_") + if (sanitized.length > 64) { + return sanitized.substring(0, 64) + } + return sanitized + } + + abstract val label: String + + override fun setupUI(builder: Panel) { + with(builder) { + row(label) { + textField() + .bindText(idProperty) + .columns(COLUMNS_MEDIUM) + .validationRequestor(AFTER_GRAPH_PROPAGATION(propertyGraph)) + .textValidation(CHECK_NON_EMPTY and idValidation) + } + } + } + + override fun setupProject(project: Project) { + data.putUserData(KEY, id) + } + + companion object { + val KEY = Key.create("${AbstractModIdStep::class.java.name}.id") + } +} + +class ModIdStep(parent: NewProjectWizardStep) : AbstractModIdStep(parent) { + override val label = "Mod Id:" +} + +class ForgeStyleModIdStep(parent: NewProjectWizardStep) : + AbstractModIdStep(parent, validForgeModIdRegex, invalidForgeModIdRegex) { + override val label = "Mod Id:" +} + +class PluginIdStep(parent: NewProjectWizardStep) : AbstractModIdStep(parent) { + override val label = "Plugin Id:" +} Index: src/main/kotlin/platform/architectury/creator/asset-steps.kt =================================================================== --- src/main/kotlin/platform/architectury/creator/asset-steps.kt (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/kotlin/platform/architectury/creator/asset-steps.kt (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -29,6 +29,7 @@ import com.demonwav.mcdev.creator.buildsystem.BuildSystemSupport import com.demonwav.mcdev.creator.findStep import com.demonwav.mcdev.creator.step.AbstractLongRunningAssetsStep +import com.demonwav.mcdev.creator.step.AbstractModIdStep import com.demonwav.mcdev.creator.step.AbstractModNameStep import com.demonwav.mcdev.creator.step.AbstractReformatFilesStep import com.demonwav.mcdev.creator.step.AuthorsStep @@ -74,7 +75,8 @@ val buildSystemProps = findStep>() val useMixins = data.getUserData(UseMixinsStep.KEY) ?: false val javaVersion = findStep().preferredJdk.ordinal - val packageName = "${buildSystemProps.groupId.toPackageName()}.${buildSystemProps.artifactId.toPackageName()}" + val modId = data.getUserData(AbstractModIdStep.KEY) ?: return + val packageName = "${buildSystemProps.groupId.toPackageName()}.${modId.toPackageName()}" val mcVersion = data.getUserData(ArchitecturyVersionChainStep.MC_VERSION_KEY) ?: return val modName = data.getUserData(AbstractModNameStep.KEY) ?: return val forgeVersion = data.getUserData(ArchitecturyVersionChainStep.FORGE_VERSION_KEY) ?: return @@ -114,6 +116,7 @@ "PACK_COMMENT" to packDescriptor.comment, "PACKAGE_NAME" to packageName, "JAVA_VERSION" to javaVersion, + "MOD_ID" to modId, "MOD_NAME" to modName, "DISPLAY_TEST" to hasDisplayTestInManifest, "FORGE_SPEC_VERSION" to forgeVersion.parts[0].versionString, @@ -160,9 +163,9 @@ assets.addTemplateProperties( "MIXINS" to "true", ) - val commonMixinsFile = "common/src/main/resources/${buildSystemProps.artifactId}-common.mixins.json" - val forgeMixinsFile = "forge/src/main/resources/${buildSystemProps.artifactId}.mixins.json" - val fabricMixinsFile = "fabric/src/main/resources/${buildSystemProps.artifactId}.mixins.json" + val commonMixinsFile = "common/src/main/resources/$modId-common.mixins.json" + val forgeMixinsFile = "forge/src/main/resources/$modId.mixins.json" + val fabricMixinsFile = "fabric/src/main/resources/$modId.mixins.json" assets.addTemplates( project, commonMixinsFile to MinecraftTemplates.ARCHITECTURY_COMMON_MIXINS_JSON_TEMPLATE, @@ -194,6 +197,7 @@ override fun setupAssets(project: Project) { val buildSystemProps = findStep>() + val modId = data.getUserData(AbstractModIdStep.KEY) ?: return val modName = data.getUserData(AbstractModNameStep.KEY) ?: return val useArchApi = data.getUserData(ArchitecturyVersionChainStep.ARCHITECTURY_API_VERSION_KEY) != null @@ -203,6 +207,7 @@ "PACKAGE_NAME" to packageName, "CLASS_NAME" to className, "ARTIFACT_ID" to buildSystemProps.artifactId, + "MOD_ID" to modId, "MOD_NAME" to modName, "MOD_VERSION" to buildSystemProps.version, "ARCHITECTURY_PACKAGE" to architecturyPackage, Index: src/main/kotlin/platform/architectury/creator/gradle-steps.kt =================================================================== --- src/main/kotlin/platform/architectury/creator/gradle-steps.kt (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/kotlin/platform/architectury/creator/gradle-steps.kt (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -33,6 +33,7 @@ import com.demonwav.mcdev.creator.findStep import com.demonwav.mcdev.creator.gitEnabled import com.demonwav.mcdev.creator.step.AbstractLongRunningAssetsStep +import com.demonwav.mcdev.creator.step.AbstractModIdStep import com.demonwav.mcdev.creator.step.AbstractModNameStep import com.demonwav.mcdev.creator.step.NewProjectWizardChainStep.Companion.nextStep import com.demonwav.mcdev.util.MinecraftTemplates @@ -67,6 +68,7 @@ data.putUserData(GRADLE_VERSION_KEY, SemanticVersion.release(7, 6, 1)) val buildSystemProps = findStep>() + val modId = data.getUserData(AbstractModIdStep.KEY) ?: return val modName = data.getUserData(AbstractModNameStep.KEY) ?: return val mcVersion = data.getUserData(ArchitecturyVersionChainStep.MC_VERSION_KEY) ?: return val forgeVersion = data.getUserData(ArchitecturyVersionChainStep.FORGE_VERSION_KEY) ?: return @@ -78,6 +80,7 @@ assets.addTemplateProperties( "GROUP_ID" to buildSystemProps.groupId, "ARTIFACT_ID" to buildSystemProps.artifactId, + "MOD_ID" to modId, "MOD_NAME" to modName, "VERSION" to buildSystemProps.version, "MC_VERSION" to mcVersion, Index: src/main/kotlin/platform/architectury/creator/ui-steps.kt =================================================================== --- src/main/kotlin/platform/architectury/creator/ui-steps.kt (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/kotlin/platform/architectury/creator/ui-steps.kt (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -26,6 +26,7 @@ import com.demonwav.mcdev.creator.step.AbstractMcVersionChainStep import com.demonwav.mcdev.creator.step.AuthorsStep import com.demonwav.mcdev.creator.step.DescriptionStep +import com.demonwav.mcdev.creator.step.ForgeStyleModIdStep import com.demonwav.mcdev.creator.step.IssueTrackerStep import com.demonwav.mcdev.creator.step.LicenseStep import com.demonwav.mcdev.creator.step.ModNameStep @@ -75,6 +76,7 @@ override fun createStep(data: ArchitecturyVersionData): NewProjectWizardStep { return ArchitecturyVersionChainStep(this, data) .nextStep(::UseMixinsStep) + .nextStep(::ForgeStyleModIdStep) .nextStep(::ModNameStep) .nextStep(::LicenseStep) .nextStep(::ArchitecturyOptionalSettingsStep) Index: src/main/kotlin/platform/fabric/creator/asset-steps.kt =================================================================== --- src/main/kotlin/platform/fabric/creator/asset-steps.kt (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/kotlin/platform/fabric/creator/asset-steps.kt (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -30,6 +30,7 @@ import com.demonwav.mcdev.creator.buildsystem.BuildSystemSupport import com.demonwav.mcdev.creator.findStep import com.demonwav.mcdev.creator.step.AbstractLongRunningAssetsStep +import com.demonwav.mcdev.creator.step.AbstractModIdStep import com.demonwav.mcdev.creator.step.AbstractModNameStep import com.demonwav.mcdev.creator.step.AuthorsStep import com.demonwav.mcdev.creator.step.DescriptionStep @@ -77,17 +78,18 @@ override fun setupAssets(project: Project) { val buildSystemProps = findStep>() + val modId = data.getUserData(AbstractModIdStep.KEY) ?: return val useMixins = data.getUserData(UseMixinsStep.KEY) ?: false val javaVersion = findStep().preferredJdk.ordinal if (useMixins) { val packageName = - "${buildSystemProps.groupId.toPackageName()}.${buildSystemProps.artifactId.toPackageName()}.mixin" + "${buildSystemProps.groupId.toPackageName()}.${modId.toPackageName()}.mixin" assets.addTemplateProperties( "PACKAGE_NAME" to packageName, "JAVA_VERSION" to javaVersion, ) - val mixinsJsonFile = "src/main/resources/${buildSystemProps.artifactId}.mixins.json" + val mixinsJsonFile = "src/main/resources/$modId.mixins.json" assets.addTemplates(project, mixinsJsonFile to FABRIC_MIXINS_JSON_TEMPLATE) } @@ -107,6 +109,7 @@ override fun setupAssets(project: Project) { val buildSystemProps = findStep>() + val modId = data.getUserData(AbstractModIdStep.KEY) ?: return val modName = data.getUserData(AbstractModNameStep.KEY) ?: return val description = data.getUserData(DescriptionStep.KEY) ?: "" val envName = when (data.getUserData(FabricEnvironmentStep.KEY) ?: Side.NONE) { @@ -121,7 +124,7 @@ val apiVersion = data.getUserData(FabricVersionChainStep.API_VERSION_KEY) val useMixins = data.getUserData(UseMixinsStep.KEY) ?: false - val packageName = "${buildSystemProps.groupId.toPackageName()}.${buildSystemProps.artifactId.toPackageName()}" + val packageName = "${buildSystemProps.groupId.toPackageName()}.${modId.toPackageName()}" val mainClassName = "$packageName.${modName.toJavaClassName()}" val clientClassName = "$packageName.client.${modName.toJavaClassName()}Client" entryPoints = listOf( @@ -131,6 +134,7 @@ assets.addTemplateProperties( "ARTIFACT_ID" to buildSystemProps.artifactId, + "MOD_ID" to modId, "MOD_NAME" to StringUtil.escapeStringCharacters(modName), "MOD_DESCRIPTION" to StringUtil.escapeStringCharacters(description), "MOD_ENVIRONMENT" to envName, Index: src/main/kotlin/platform/fabric/creator/ui-steps.kt =================================================================== --- src/main/kotlin/platform/fabric/creator/ui-steps.kt (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/kotlin/platform/fabric/creator/ui-steps.kt (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -27,6 +27,7 @@ import com.demonwav.mcdev.creator.step.AuthorsStep import com.demonwav.mcdev.creator.step.DescriptionStep import com.demonwav.mcdev.creator.step.LicenseStep +import com.demonwav.mcdev.creator.step.ModIdStep import com.demonwav.mcdev.creator.step.ModNameStep import com.demonwav.mcdev.creator.step.NewProjectWizardChainStep.Companion.nextStep import com.demonwav.mcdev.creator.step.RepositoryStep @@ -75,6 +76,7 @@ return FabricVersionChainStep(this, fabricVersions, apiVersions) .nextStep(::FabricEnvironmentStep) .nextStep(::UseMixinsStep) + .nextStep(::ModIdStep) .nextStep(::ModNameStep) .nextStep(::LicenseStep) .nextStep(::FabricOptionalSettingsStep) Index: src/main/kotlin/platform/forge/creator/asset-steps.kt =================================================================== --- src/main/kotlin/platform/forge/creator/asset-steps.kt (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/kotlin/platform/forge/creator/asset-steps.kt (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -29,6 +29,7 @@ import com.demonwav.mcdev.creator.findStep import com.demonwav.mcdev.creator.splitPackage import com.demonwav.mcdev.creator.step.AbstractLongRunningAssetsStep +import com.demonwav.mcdev.creator.step.AbstractModIdStep import com.demonwav.mcdev.creator.step.AbstractModNameStep import com.demonwav.mcdev.creator.step.AbstractReformatFilesStep import com.demonwav.mcdev.creator.step.AuthorsStep @@ -56,6 +57,7 @@ val mainClass = data.getUserData(MainClassStep.KEY) ?: return val (mainPackageName, mainClassName) = splitPackage(mainClass) val buildSystemProps = findStep>() + val modId = data.getUserData(AbstractModIdStep.KEY) ?: return val modName = data.getUserData(AbstractModNameStep.KEY) ?: return val license = data.getUserData(LicenseStep.KEY) ?: return val description = data.getUserData(DescriptionStep.KEY) ?: "" @@ -78,6 +80,7 @@ "PACKAGE_NAME" to mainPackageName, "CLASS_NAME" to mainClassName, "ARTIFACT_ID" to buildSystemProps.artifactId, + "MOD_ID" to modId, "MOD_NAME" to modName, "MOD_VERSION" to buildSystemProps.version, "DISPLAY_TEST" to (forgeVersion >= ForgeConstants.DISPLAY_TEST_MANIFEST_VERSION), @@ -144,12 +147,13 @@ override fun setupAssets(project: Project) { val useMixins = data.getUserData(UseMixinsStep.KEY) ?: false if (useMixins) { + val modId = data.getUserData(AbstractModIdStep.KEY) ?: return val buildSystemProps = findStep>() assets.addTemplateProperties( - "PACKAGE_NAME" to "${buildSystemProps.groupId}.${buildSystemProps.artifactId}.mixin", - "ARTIFACT_ID" to buildSystemProps.artifactId, + "PACKAGE_NAME" to "${buildSystemProps.groupId}.$modId.mixin", + "MOD_ID" to buildSystemProps.artifactId, ) - val mixinsJsonFile = "src/main/resources/${buildSystemProps.artifactId}.mixins.json" + val mixinsJsonFile = "src/main/resources/$modId.mixins.json" assets.addTemplates(project, mixinsJsonFile to MinecraftTemplates.FORGE_MIXINS_JSON_TEMPLATE) } } Index: src/main/kotlin/platform/forge/creator/gradle-steps.kt =================================================================== --- src/main/kotlin/platform/forge/creator/gradle-steps.kt (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/kotlin/platform/forge/creator/gradle-steps.kt (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -33,6 +33,7 @@ import com.demonwav.mcdev.creator.findStep import com.demonwav.mcdev.creator.gitEnabled import com.demonwav.mcdev.creator.step.AbstractLongRunningAssetsStep +import com.demonwav.mcdev.creator.step.AbstractModIdStep import com.demonwav.mcdev.creator.step.AbstractModNameStep import com.demonwav.mcdev.creator.step.AuthorsStep import com.demonwav.mcdev.creator.step.DescriptionStep @@ -47,7 +48,6 @@ import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.openapi.vfs.VfsUtil import com.intellij.util.lang.JavaVersion -import java.util.Locale private val fg6WrapperVersion = SemanticVersion.release(8, 1, 1) @@ -68,14 +68,11 @@ class ForgeGradleFilesStep(parent: NewProjectWizardStep) : AbstractLongRunningAssetsStep(parent) { override val description = "Creating Gradle files" - private fun transformModName(modName: String): String { - return modName.lowercase(Locale.ENGLISH).replace(" ", "") - } - override fun setupAssets(project: Project) { val mcVersion = data.getUserData(ForgeVersionChainStep.MC_VERSION_KEY) ?: return val forgeVersion = data.getUserData(ForgeVersionChainStep.FORGE_VERSION_KEY) ?: return - val modName = transformModName(data.getUserData(AbstractModNameStep.KEY) ?: return) + val modId = data.getUserData(AbstractModIdStep.KEY) ?: return + val modName = data.getUserData(AbstractModNameStep.KEY) ?: return val buildSystemProps = findStep>() val javaVersion = context.projectJdk.versionString?.let(JavaVersion::parse) val authors = data.getUserData(AuthorsStep.KEY) ?: emptyList() @@ -92,6 +89,7 @@ data.putUserData(GRADLE_VERSION_KEY, fg6WrapperVersion) assets.addTemplateProperties( + "MOD_ID" to modId, "MOD_NAME" to modName, "MC_VERSION" to mcVersion, "MC_NEXT_VERSION" to mcNextVersion, Index: src/main/kotlin/platform/forge/creator/ui-steps.kt =================================================================== --- src/main/kotlin/platform/forge/creator/ui-steps.kt (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/kotlin/platform/forge/creator/ui-steps.kt (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -26,6 +26,7 @@ import com.demonwav.mcdev.creator.step.AbstractMcVersionChainStep import com.demonwav.mcdev.creator.step.AuthorsStep import com.demonwav.mcdev.creator.step.DescriptionStep +import com.demonwav.mcdev.creator.step.ForgeStyleModIdStep import com.demonwav.mcdev.creator.step.LicenseStep import com.demonwav.mcdev.creator.step.MainClassStep import com.demonwav.mcdev.creator.step.ModNameStep @@ -53,6 +54,7 @@ } override fun createStep(data: ForgeVersion) = ForgeVersionChainStep(this, data) + .nextStep(::ForgeStyleModIdStep) .nextStep(::ModNameStep) .nextStep(::MainClassStep) .nextStep(::UseMixinsStep) Index: src/main/kotlin/platform/sponge/creator/gradle-steps.kt =================================================================== --- src/main/kotlin/platform/sponge/creator/gradle-steps.kt (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/kotlin/platform/sponge/creator/gradle-steps.kt (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -33,6 +33,7 @@ import com.demonwav.mcdev.creator.findStep import com.demonwav.mcdev.creator.gitEnabled import com.demonwav.mcdev.creator.step.AbstractLongRunningAssetsStep +import com.demonwav.mcdev.creator.step.AbstractModIdStep import com.demonwav.mcdev.creator.step.AbstractModNameStep import com.demonwav.mcdev.creator.step.AuthorsStep import com.demonwav.mcdev.creator.step.DependStep @@ -67,6 +68,7 @@ val javaVersion = findStep().preferredJdk.ordinal val spongeVersion = data.getUserData(SpongeApiVersionStep.KEY) ?: return val license = data.getUserData(LicenseStep.KEY) ?: return + val pluginId = data.getUserData(AbstractModIdStep.KEY) ?: return val pluginName = data.getUserData(AbstractModNameStep.KEY) ?: return val mainClass = data.getUserData(MainClassStep.KEY) ?: return val description = data.getUserData(DescriptionStep.KEY) ?: "" @@ -78,7 +80,7 @@ assets.addTemplateProperties( "GROUP_ID" to buildSystemProps.groupId, "ARTIFACT_ID" to buildSystemProps.artifactId, - "PLUGIN_ID" to buildSystemProps.artifactId, + "PLUGIN_ID" to pluginId, "PLUGIN_VERSION" to buildSystemProps.version, "JAVA_VERSION" to javaVersion, "SPONGEAPI_VERSION" to spongeVersion, Index: src/main/kotlin/platform/sponge/creator/maven-steps.kt =================================================================== --- src/main/kotlin/platform/sponge/creator/maven-steps.kt (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/kotlin/platform/sponge/creator/maven-steps.kt (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -28,7 +28,6 @@ import com.demonwav.mcdev.creator.buildsystem.AbstractPatchPomStep import com.demonwav.mcdev.creator.buildsystem.BuildDependency import com.demonwav.mcdev.creator.buildsystem.BuildRepository -import com.demonwav.mcdev.creator.buildsystem.BuildSystemPropertiesStep import com.demonwav.mcdev.creator.buildsystem.BuildSystemSupport import com.demonwav.mcdev.creator.buildsystem.BuildSystemType import com.demonwav.mcdev.creator.buildsystem.MavenImportStep @@ -37,6 +36,7 @@ import com.demonwav.mcdev.creator.findStep import com.demonwav.mcdev.creator.gitEnabled import com.demonwav.mcdev.creator.step.AbstractLongRunningAssetsStep +import com.demonwav.mcdev.creator.step.AbstractModIdStep import com.demonwav.mcdev.creator.step.AbstractModNameStep import com.demonwav.mcdev.creator.step.AuthorsStep import com.demonwav.mcdev.creator.step.DependStep @@ -82,10 +82,10 @@ override val description = "Creating Maven project files" override fun setupAssets(project: Project) { - val buildSystemProps = findStep>() val mainClass = data.getUserData(MainClassStep.KEY) ?: return val spongeApiVersion = data.getUserData(SpongeApiVersionStep.KEY) ?: return val license = data.getUserData(LicenseStep.KEY) ?: return + val pluginId = data.getUserData(AbstractModIdStep.KEY) ?: return val pluginName = data.getUserData(AbstractModNameStep.KEY) ?: return val description = data.getUserData(DescriptionStep.KEY) ?: "" val website = data.getUserData(WebsiteStep.KEY) ?: "" @@ -93,7 +93,7 @@ val dependencies = data.getUserData(DependStep.KEY) ?: emptyList() assets.addTemplateProperties( - "PLUGIN_ID" to buildSystemProps.artifactId, + "PLUGIN_ID" to pluginId, "VERSION_PLACEHOLDER" to "\${version}", "SPONGEAPI_VERSION" to spongeApiVersion, "LICENSE" to license.id, Index: src/main/kotlin/platform/sponge/creator/ui-steps.kt =================================================================== --- src/main/kotlin/platform/sponge/creator/ui-steps.kt (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/kotlin/platform/sponge/creator/ui-steps.kt (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -32,6 +32,7 @@ import com.demonwav.mcdev.creator.step.LicenseStep import com.demonwav.mcdev.creator.step.MainClassStep import com.demonwav.mcdev.creator.step.NewProjectWizardChainStep.Companion.nextStep +import com.demonwav.mcdev.creator.step.PluginIdStep import com.demonwav.mcdev.creator.step.PluginNameStep import com.demonwav.mcdev.creator.step.WebsiteStep import com.demonwav.mcdev.platform.sponge.SpongeVersion @@ -52,6 +53,7 @@ override suspend fun computeData() = SpongeVersion.downloadData() override fun createStep(data: SpongeVersion) = SpongeApiVersionStep(this, data) + .nextStep(::PluginIdStep) .nextStep(::PluginNameStep) .nextStep(::MainClassStep) .nextStep(::LicenseStep) Index: src/main/kotlin/platform/velocity/creator/asset-steps.kt =================================================================== --- src/main/kotlin/platform/velocity/creator/asset-steps.kt (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/kotlin/platform/velocity/creator/asset-steps.kt (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -29,6 +29,7 @@ import com.demonwav.mcdev.creator.splitPackage import com.demonwav.mcdev.creator.step.AbstractLongRunningAssetsStep import com.demonwav.mcdev.creator.step.AbstractLongRunningStep +import com.demonwav.mcdev.creator.step.AbstractModIdStep import com.demonwav.mcdev.creator.step.AbstractModNameStep import com.demonwav.mcdev.creator.step.AuthorsStep import com.demonwav.mcdev.creator.step.DependStep @@ -93,6 +94,7 @@ override fun perform(project: Project) { val buildSystemProps = findStep>() + val pluginId = data.getUserData(AbstractModIdStep.KEY) ?: return val pluginName = data.getUserData(AbstractModNameStep.KEY) ?: return val mainClassName = data.getUserData(MainClassStep.KEY) ?: return val mainClassFile = "${context.projectFileDirectory}/src/main/java/${mainClassName.replace('.', '/')}.java" @@ -111,7 +113,7 @@ val psiClass = mainClassPsi.classes[0] val annotation = buildString { append("@Plugin(") - append("\nid = ${literal(buildSystemProps.artifactId)}") + append("\nid = ${literal(pluginId)}") append(",\nname = ${literal(pluginName)}") if (isGradle) { Index: src/main/kotlin/platform/velocity/creator/ui-steps.kt =================================================================== --- src/main/kotlin/platform/velocity/creator/ui-steps.kt (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/kotlin/platform/velocity/creator/ui-steps.kt (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -33,6 +33,7 @@ import com.demonwav.mcdev.creator.step.DescriptionStep import com.demonwav.mcdev.creator.step.MainClassStep import com.demonwav.mcdev.creator.step.NewProjectWizardChainStep.Companion.nextStep +import com.demonwav.mcdev.creator.step.PluginIdStep import com.demonwav.mcdev.creator.step.PluginNameStep import com.demonwav.mcdev.creator.step.WebsiteStep import com.demonwav.mcdev.platform.PlatformType @@ -59,6 +60,7 @@ override fun createStep(data: PlatformVersion) = VelocityVersionStep(this, data.versions.mapNotNull(SemanticVersion::tryParse)) + .nextStep(::PluginIdStep) .nextStep(::PluginNameStep) .nextStep(::MainClassStep) .nextStep(::VelocityOptionalSettingsStep) Index: src/main/resources/fileTemplates/j2ee/architectury/architectury_common_main_class.java.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/architectury/architectury_common_main_class.java.ft (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/resources/fileTemplates/j2ee/architectury/architectury_common_main_class.java.ft (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -2,9 +2,9 @@ public class ${CLASS_NAME} { - public static final String MOD_ID = "${ARTIFACT_ID}"; + public static final String MOD_ID = "${MOD_ID}"; public static void init() { } -} \ No newline at end of file +} Index: src/main/resources/fileTemplates/j2ee/architectury/architectury_fabric_mod.json.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/architectury/architectury_fabric_mod.json.ft (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/resources/fileTemplates/j2ee/architectury/architectury_fabric_mod.json.ft (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -1,7 +1,7 @@ #set ( $d = "$" ) { "schemaVersion": 1, - "id": "${ARTIFACT_ID}", + "id": "${MOD_ID}", "version": "${d}{version}", "name": "${MOD_NAME}", @@ -16,8 +16,8 @@ "entrypoints": {}, #if (${MIXINS}) "mixins": [ - "${ARTIFACT_ID}.mixins.json", - "${ARTIFACT_ID}-common.mixins.json" + "${MOD_ID}.mixins.json", + "${MOD_ID}-common.mixins.json" ], #end "depends": { Index: src/main/resources/fileTemplates/j2ee/architectury/architectury_forge_build.gradle.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/architectury/architectury_forge_build.gradle.ft (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/resources/fileTemplates/j2ee/architectury/architectury_forge_build.gradle.ft (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -4,8 +4,8 @@ #if (${MIXINS}) loom { forge { - mixinConfig "${ARTIFACT_ID}-common.mixins.json" - mixinConfig "${ARTIFACT_ID}.mixins.json" + mixinConfig "${MOD_ID}-common.mixins.json" + mixinConfig "${MOD_ID}.mixins.json" } } #end @@ -82,4 +82,4 @@ repositories { // Add repositories to publish to here. } -} \ No newline at end of file +} Index: src/main/resources/fileTemplates/j2ee/architectury/architectury_forge_mods.toml.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/architectury/architectury_forge_mods.toml.ft (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/resources/fileTemplates/j2ee/architectury/architectury_forge_mods.toml.ft (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -19,7 +19,7 @@ # A list of mods - how many allowed here is determined by the individual mod loader [[mods]] #mandatory # The modid of the mod -modId="${ARTIFACT_ID}" #mandatory +modId="${MOD_ID}" #mandatory # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it # ${version} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata # see the associated build.gradle script for how to populate this completely automatically during a build @@ -63,7 +63,7 @@ ${DESCRIPTION} ''' # A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. -[[dependencies.${ARTIFACT_ID}]] #optional +[[dependencies.${MOD_ID}]] #optional # the modid of the dependency modId="forge" #mandatory # Does this dependency have to exist - if not, ordering below must be specified @@ -75,7 +75,7 @@ # Side this dependency is applied on - BOTH, CLIENT or SERVER side="BOTH" # Here's another dependency -[[dependencies.${ARTIFACT_ID}]] +[[dependencies.${MOD_ID}]] modId="minecraft" mandatory=true # This version range declares a minimum of the current minecraft version up to but not including the next major version @@ -83,7 +83,7 @@ ordering="NONE" side="BOTH" #if (${ARCHITECTURY_API}) -[[dependencies.${ARTIFACT_ID}]] +[[dependencies.${MOD_ID}]] modId = "architectury" mandatory = true versionRange = "[${ARCHITECTURY_API_VERSION},)" Index: src/main/resources/fileTemplates/j2ee/fabric/fabric_mod.json.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/fabric/fabric_mod.json.ft (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/resources/fileTemplates/j2ee/fabric/fabric_mod.json.ft (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -1,7 +1,7 @@ #set ( $d = "$" ) { "schemaVersion": 1, - "id": "${ARTIFACT_ID}", + "id": "${MOD_ID}", "version": "${d}{version}", "name": "${MOD_NAME}", @@ -10,14 +10,14 @@ "contact": {}, "license": "${LICENSE}", - "icon": "assets/${ARTIFACT_ID}/icon.png", + "icon": "assets/${MOD_ID}/icon.png", "environment": "${MOD_ENVIRONMENT}", "entrypoints": {}, #if (${MIXINS}) "mixins": [ - "${ARTIFACT_ID}.mixins.json" + "${MOD_ID}.mixins.json" ], #end Index: src/main/resources/fileTemplates/j2ee/forge/Forge (1.13+) gradle.properties.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/forge/Forge (1.13+) gradle.properties.ft (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/resources/fileTemplates/j2ee/forge/Forge (1.13+) gradle.properties.ft (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -38,7 +38,7 @@ # The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63} # Must match the String constant located in the main mod class annotated with @Mod. -mod_id=${ARTIFACT_ID} +mod_id=${MOD_ID} # The human-readable display name for the mod. mod_name=${MOD_NAME} # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. Index: src/main/resources/fileTemplates/j2ee/forge/Forge (1.16+) Main Class.java.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/forge/Forge (1.16+) Main Class.java.ft (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/resources/fileTemplates/j2ee/forge/Forge (1.16+) Main Class.java.ft (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -19,7 +19,7 @@ import java.util.stream.Collectors; // The value here should match an entry in the META-INF/mods.toml file -@Mod("${ARTIFACT_ID}") +@Mod("${MOD_ID}") public class ${CLASS_NAME} { // Directly reference a log4j logger. @@ -52,7 +52,7 @@ private void enqueueIMC(final InterModEnqueueEvent event) { // some example code to dispatch IMC to another mod - InterModComms.sendTo("${ARTIFACT_ID}", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";}); + InterModComms.sendTo("${MOD_ID}", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";}); } private void processIMC(final InterModProcessEvent event) { Index: src/main/resources/fileTemplates/j2ee/forge/Forge (1.17+) Main Class.java.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/forge/Forge (1.17+) Main Class.java.ft (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/resources/fileTemplates/j2ee/forge/Forge (1.17+) Main Class.java.ft (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -18,7 +18,7 @@ import java.util.stream.Collectors; // The value here should match an entry in the META-INF/mods.toml file -@Mod("${ARTIFACT_ID}") +@Mod("${MOD_ID}") public class ${CLASS_NAME} { // Directly reference a log4j logger. @@ -44,7 +44,7 @@ private void enqueueIMC(final InterModEnqueueEvent event) { // some example code to dispatch IMC to another mod - InterModComms.sendTo("${ARTIFACT_ID}", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";}); + InterModComms.sendTo("${MOD_ID}", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";}); } private void processIMC(final InterModProcessEvent event) { Index: src/main/resources/fileTemplates/j2ee/forge/Forge (1.18+) Main Class.java.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/forge/Forge (1.18+) Main Class.java.ft (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/resources/fileTemplates/j2ee/forge/Forge (1.18+) Main Class.java.ft (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -18,7 +18,7 @@ import java.util.stream.Collectors; // The value here should match an entry in the META-INF/mods.toml file -@Mod("${ARTIFACT_ID}") +@Mod("${MOD_ID}") public class ${CLASS_NAME} { // Directly reference a slf4j logger @@ -44,7 +44,7 @@ private void enqueueIMC(final InterModEnqueueEvent event) { // Some example code to dispatch IMC to another mod - InterModComms.sendTo("${ARTIFACT_ID}", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";}); + InterModComms.sendTo("${MOD_ID}", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";}); } private void processIMC(final InterModProcessEvent event) { Index: src/main/resources/fileTemplates/j2ee/forge/Forge (1.19+) Main Class.java.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/forge/Forge (1.19+) Main Class.java.ft (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/resources/fileTemplates/j2ee/forge/Forge (1.19+) Main Class.java.ft (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -31,17 +31,17 @@ public class ${CLASS_NAME} { // Define mod id in a common place for everything to reference - public static final String MODID = "${ARTIFACT_ID}"; + public static final String MODID = "${MOD_ID}"; // Directly reference a slf4j logger private static final Logger LOGGER = LogUtils.getLogger(); - // Create a Deferred Register to hold Blocks which will all be registered under the "${ARTIFACT_ID}" namespace + // Create a Deferred Register to hold Blocks which will all be registered under the "${MOD_ID}" namespace public static final DeferredRegister BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID); - // Create a Deferred Register to hold Items which will all be registered under the "${ARTIFACT_ID}" namespace + // Create a Deferred Register to hold Items which will all be registered under the "${MOD_ID}" namespace public static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID); - // Creates a new Block with the id "${ARTIFACT_ID}:example_block", combining the namespace and path + // Creates a new Block with the id "${MOD_ID}:example_block", combining the namespace and path public static final RegistryObject EXAMPLE_BLOCK = BLOCKS.register("example_block", () -> new Block(BlockBehaviour.Properties.of(Material.STONE))); - // Creates a new BlockItem with the id "${ARTIFACT_ID}:example_block", combining the namespace and path + // Creates a new BlockItem with the id "${MOD_ID}:example_block", combining the namespace and path public static final RegistryObject EXAMPLE_BLOCK_ITEM = ITEMS.register("example_block", () -> new BlockItem(EXAMPLE_BLOCK.get(), new Item.Properties().tab(CreativeModeTab.TAB_BUILDING_BLOCKS))); public ${CLASS_NAME}() { Index: src/main/resources/fileTemplates/j2ee/forge/Forge (1.19.3+) Main Class.java.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/forge/Forge (1.19.3+) Main Class.java.ft (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/resources/fileTemplates/j2ee/forge/Forge (1.19.3+) Main Class.java.ft (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -29,17 +29,17 @@ public class ${CLASS_NAME} { // Define mod id in a common place for everything to reference - public static final String MODID = "${ARTIFACT_ID}"; + public static final String MODID = "${MOD_ID}"; // Directly reference a slf4j logger private static final Logger LOGGER = LogUtils.getLogger(); - // Create a Deferred Register to hold Blocks which will all be registered under the "${ARTIFACT_ID}" namespace + // Create a Deferred Register to hold Blocks which will all be registered under the "${MOD_ID}" namespace public static final DeferredRegister BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID); - // Create a Deferred Register to hold Items which will all be registered under the "${ARTIFACT_ID}" namespace + // Create a Deferred Register to hold Items which will all be registered under the "${MOD_ID}" namespace public static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID); - // Creates a new Block with the id "${ARTIFACT_ID}:example_block", combining the namespace and path + // Creates a new Block with the id "${MOD_ID}:example_block", combining the namespace and path public static final RegistryObject EXAMPLE_BLOCK = BLOCKS.register("example_block", () -> new Block(BlockBehaviour.Properties.of(Material.STONE))); - // Creates a new BlockItem with the id "${ARTIFACT_ID}:example_block", combining the namespace and path + // Creates a new BlockItem with the id "${MOD_ID}:example_block", combining the namespace and path public static final RegistryObject EXAMPLE_BLOCK_ITEM = ITEMS.register("example_block", () -> new BlockItem(EXAMPLE_BLOCK.get(), new Item.Properties())); public ${CLASS_NAME}() { Index: src/main/resources/fileTemplates/j2ee/forge/Forge (1.20+) Main Class.java.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/forge/Forge (1.20+) Main Class.java.ft (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/resources/fileTemplates/j2ee/forge/Forge (1.20+) Main Class.java.ft (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -34,19 +34,19 @@ public class ${CLASS_NAME} { // Define mod id in a common place for everything to reference - public static final String MODID = "${ARTIFACT_ID}"; + public static final String MODID = "${MOD_ID}"; // Directly reference a slf4j logger private static final Logger LOGGER = LogUtils.getLogger(); - // Create a Deferred Register to hold Blocks which will all be registered under the "${ARTIFACT_ID}" namespace + // Create a Deferred Register to hold Blocks which will all be registered under the "${MOD_ID}" namespace public static final DeferredRegister BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID); - // Create a Deferred Register to hold Items which will all be registered under the "${ARTIFACT_ID}" namespace + // Create a Deferred Register to hold Items which will all be registered under the "${MOD_ID}" namespace public static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID); // Create a Deferred Register to hold CreativeModeTabs which will all be registered under the "examplemod" namespace public static final DeferredRegister CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID); - // Creates a new Block with the id "${ARTIFACT_ID}:example_block", combining the namespace and path + // Creates a new Block with the id "${MOD_ID}:example_block", combining the namespace and path public static final RegistryObject EXAMPLE_BLOCK = BLOCKS.register("example_block", () -> new Block(BlockBehaviour.Properties.of().mapColor(MapColor.STONE))); - // Creates a new BlockItem with the id "${ARTIFACT_ID}:example_block", combining the namespace and path + // Creates a new BlockItem with the id "${MOD_ID}:example_block", combining the namespace and path public static final RegistryObject EXAMPLE_BLOCK_ITEM = ITEMS.register("example_block", () -> new BlockItem(EXAMPLE_BLOCK.get(), new Item.Properties())); // Creates a new food item with the id "examplemod:example_id", nutrition 1 and saturation 2 Index: src/main/resources/fileTemplates/j2ee/forge/Forge Mixins Config.json.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/forge/Forge Mixins Config.json.ft (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/resources/fileTemplates/j2ee/forge/Forge Mixins Config.json.ft (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -3,7 +3,7 @@ "minVersion": "0.8", "package": "${PACKAGE_NAME}", "compatibilityLevel": "JAVA_8", - "refmap": "${ARTIFACT_ID}.refmap.json", + "refmap": "${MOD_ID}.refmap.json", "mixins": [ ], "client": [ Index: src/main/resources/fileTemplates/j2ee/forge/mods.toml.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/forge/mods.toml.ft (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/resources/fileTemplates/j2ee/forge/mods.toml.ft (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -33,7 +33,7 @@ #displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional #end # A file name (in the root of the mod JAR) containing a logo for display -#logoFile="${ARTIFACT_ID}.png" #optional +#logoFile="${MOD_ID}.png" #optional # A text field displayed in the mod UI #credits="Thanks for this example mod goes to Java" #optional # A text field displayed in the mod UI Index: src/main/resources/fileTemplates/j2ee/forge/pack.mcmeta.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/forge/pack.mcmeta.ft (revision e685e8e9c661598ef78e3f17a3ab5805d823c866) +++ src/main/resources/fileTemplates/j2ee/forge/pack.mcmeta.ft (revision f2f3b1c9dace3985c194b061b2e9761c6ca875d9) @@ -1,6 +1,6 @@ { "pack": { - "description": "${ARTIFACT_ID} resources", + "description": "${MOD_ID} resources", #if (${PACK_COMMENT} != "") "pack_format": ${PACK_FORMAT}, "_comment": "${PACK_COMMENT}"