User: mysterious_dev Date: 01 Mar 23 20:29 Revision: fecd3145dfb0e83d71fc95f16373d13fb5997a33 Summary: Add option to select official mappings for FabricMC mods (#1948) * Begin Work * WIP * WIP * Remove unnecessary code * WIP TeamCity URL: https://ci.mcdev.io/viewModification.html?tab=vcsModificationFiles&modId=8356&personal=false Index: src/main/kotlin/platform/fabric/creator/gradle-steps.kt =================================================================== --- src/main/kotlin/platform/fabric/creator/gradle-steps.kt (revision af6d94a51becaa82b7f50ac2fae9453325218b2e) +++ src/main/kotlin/platform/fabric/creator/gradle-steps.kt (revision fecd3145dfb0e83d71fc95f16373d13fb5997a33) @@ -50,6 +50,7 @@ val loomVersion = "1.0-SNAPSHOT" // TODO val javaVersion = findStep().preferredJdk.ordinal val apiVersion = data.getUserData(FabricVersionChainStep.API_VERSION_KEY) + val officialMappings = data.getUserData(FabricVersionChainStep.OFFICIAL_MAPPINGS_KEY) ?: false assets.addTemplateProperties( "GROUP_ID" to buildSystemProps.groupId, @@ -66,6 +67,10 @@ assets.addTemplateProperties("API_VERSION" to apiVersion) } + if (officialMappings) { + assets.addTemplateProperties("OFFICIAL_MAPPINGS" to "true") + } + assets.addTemplates( project, "build.gradle" to MinecraftTemplates.FABRIC_BUILD_GRADLE_TEMPLATE, Index: src/main/kotlin/platform/fabric/creator/ui-steps.kt =================================================================== --- src/main/kotlin/platform/fabric/creator/ui-steps.kt (revision af6d94a51becaa82b7f50ac2fae9453325218b2e) +++ src/main/kotlin/platform/fabric/creator/ui-steps.kt (revision fecd3145dfb0e83d71fc95f16373d13fb5997a33) @@ -34,6 +34,7 @@ import com.intellij.ide.wizard.NewProjectWizardStep import com.intellij.openapi.observable.util.bindBooleanStorage import com.intellij.openapi.observable.util.bindStorage +import com.intellij.openapi.observable.util.not import com.intellij.openapi.observable.util.transform import com.intellij.openapi.project.Project import com.intellij.openapi.util.Key @@ -94,6 +95,7 @@ val LOADER_VERSION_KEY = Key.create("${FabricVersionChainStep::class.java.name}.loaderVersion") val YARN_VERSION_KEY = Key.create("${FabricVersionChainStep::class.java.name}.yarnVersion") val API_VERSION_KEY = Key.create("${FabricVersionChainStep::class.java.name}.apiVersion") + val OFFICIAL_MAPPINGS_KEY = Key.create("${FabricVersionChainStep::class.java.name}.officialMappings") } private val showSnapshotsProperty = propertyGraph.property(false) @@ -104,6 +106,10 @@ .bindBooleanStorage("${javaClass.name}.useApi") private var useApi by useApiProperty + private val useOfficialMappingsProperty = propertyGraph.property(false) + .bindBooleanStorage("${javaClass.name}.useOfficialMappings") + private var useOfficialMappings by useOfficialMappingsProperty + init { showSnapshotsProperty.afterChange { updateVersionBox() } } @@ -122,7 +128,8 @@ comboBox } YARN_VERSION -> { - val comboBox = super.createComboBox(row, index, items) + val comboBox = super.createComboBox(row, index, items).bindEnabled(useOfficialMappingsProperty.not()) + row.checkBox("Use Official Mappings").bindSelected(useOfficialMappingsProperty) row.label(EMPTY_LABEL).bindText( getVersionProperty(MINECRAFT_VERSION).transform { mcVersion -> mcVersion as FabricMcVersion @@ -133,7 +140,7 @@ "Unable to match Yarn versions to Minecraft version" } }, - ).component.foreground = JBColor.YELLOW + ).bindEnabled(useOfficialMappingsProperty.not()).component.foreground = JBColor.YELLOW comboBox } API_VERSION -> { @@ -200,6 +207,7 @@ if (useApi) { data.putUserData(API_VERSION_KEY, getVersion(API_VERSION) as SemanticVersion) } + data.putUserData(OFFICIAL_MAPPINGS_KEY, useOfficialMappings) } } Index: src/main/resources/fileTemplates/j2ee/fabric/fabric_build.gradle.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/fabric/fabric_build.gradle.ft (revision af6d94a51becaa82b7f50ac2fae9453325218b2e) +++ src/main/resources/fileTemplates/j2ee/fabric/fabric_build.gradle.ft (revision fecd3145dfb0e83d71fc95f16373d13fb5997a33) @@ -17,7 +17,11 @@ dependencies { // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" +#if (${OFFICIAL_MAPPINGS}) + mappings loom.officialMojangMappings() +#else mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" +#end modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" #if (${API_VERSION}) Index: src/main/resources/fileTemplates/j2ee/fabric/fabric_gradle.properties.ft =================================================================== --- src/main/resources/fileTemplates/j2ee/fabric/fabric_gradle.properties.ft (revision af6d94a51becaa82b7f50ac2fae9453325218b2e) +++ src/main/resources/fileTemplates/j2ee/fabric/fabric_gradle.properties.ft (revision fecd3145dfb0e83d71fc95f16373d13fb5997a33) @@ -4,7 +4,9 @@ # Fabric Properties # check these on https://modmuss50.me/fabric.html minecraft_version=${MC_VERSION} +#if (!${OFFICIAL_MAPPINGS}) yarn_mappings=${YARN_MAPPINGS} +#end loader_version=${LOADER_VERSION} # Mod Properties