Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ license {

ktlint {
disabledRules.add("filename")
disabledRules.add("no-wildcard-imports")
}
tasks.withType<BaseKtLintCheckTask>().configureEach {
workerMaxHeapSize.set("512m")
Expand Down
78 changes: 40 additions & 38 deletions src/main/kotlin/platform/fabric/creator/asset-steps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,11 @@ import com.demonwav.mcdev.creator.buildsystem.AbstractRunBuildSystemStep
import com.demonwav.mcdev.creator.buildsystem.BuildSystemPropertiesStep
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
import com.demonwav.mcdev.creator.step.LicenseStep
import com.demonwav.mcdev.creator.step.RepositoryStep
import com.demonwav.mcdev.creator.step.UseMixinsStep
import com.demonwav.mcdev.creator.step.WebsiteStep
import com.demonwav.mcdev.platform.fabric.EntryPoint
import com.demonwav.mcdev.platform.fabric.util.FabricConstants
import com.demonwav.mcdev.creator.step.*
import com.demonwav.mcdev.platform.forge.inspections.sideonly.Side
import com.demonwav.mcdev.util.MinecraftTemplates.Companion.FABRIC_MIXINS_JSON_TEMPLATE
import com.demonwav.mcdev.util.MinecraftTemplates.Companion.FABRIC_MOD_CLASS_TEMPLATE
import com.demonwav.mcdev.util.MinecraftTemplates.Companion.FABRIC_MOD_CLIENT_CLASS_TEMPLATE
import com.demonwav.mcdev.util.MinecraftTemplates.Companion.FABRIC_MOD_JSON_TEMPLATE
import com.demonwav.mcdev.util.toJavaClassName
import com.demonwav.mcdev.util.toPackageName
Expand All @@ -61,6 +53,11 @@ class FabricBaseFilesStep(parent: NewProjectWizardStep) : AbstractLongRunningAss
val buildSystemProps = findStep<BuildSystemPropertiesStep<*>>()
val modId = data.getUserData(AbstractModIdStep.KEY) ?: return
val modName = data.getUserData(AbstractModNameStep.KEY) ?: return
val packageName = "${buildSystemProps.groupId.toPackageName()}.${modId.toPackageName()}"
val mainClassName = modName.toJavaClassName()
val clientClassName = "${modName.toJavaClassName()}Client"
val mainClass = "$packageName.${modName.toJavaClassName()}"
val clientClass = "$packageName.client.${modName.toJavaClassName()}Client"
val description = data.getUserData(DescriptionStep.KEY) ?: ""
val envName = when (data.getUserData(FabricEnvironmentStep.KEY) ?: Side.NONE) {
Side.CLIENT -> "client"
Expand All @@ -73,8 +70,17 @@ class FabricBaseFilesStep(parent: NewProjectWizardStep) : AbstractLongRunningAss
val license = data.getUserData(LicenseStep.KEY) ?: return
val apiVersion = data.getUserData(FabricVersionChainStep.API_VERSION_KEY)
val useMixins = data.getUserData(UseMixinsStep.KEY) ?: false
val authors = data.getUserData(AuthorsStep.KEY) ?: emptyList()
val website = data.getUserData(WebsiteStep.KEY) ?: ""
val repo = data.getUserData(RepositoryStep.KEY) ?: ""

assets.addTemplateProperties(
"MAIN_PACKAGE" to packageName,
"CLIENT_PACKAGE" to "$packageName.client",
"MAIN_CLASS_NAME" to mainClassName,
"CLIENT_CLASS_NAME" to clientClassName,
"MAIN_CLASS" to mainClass,
"CLIENT_CLASS" to clientClass,
"ARTIFACT_ID" to buildSystemProps.artifactId,
"MOD_ID" to modId,
"MOD_NAME" to StringUtil.escapeStringCharacters(modName),
Expand All @@ -90,13 +96,25 @@ class FabricBaseFilesStep(parent: NewProjectWizardStep) : AbstractLongRunningAss
assets.addTemplateProperties("API_VERSION" to apiVersion)
}

if (authors.isNotEmpty()) {
assets.addTemplateProperties("AUTHOR_LIST" to authors.joinToString(",") { s -> "\u0022${s}\u0022" })
}

if (website.isNotBlank()) {
assets.addTemplateProperties("WEBSITE" to website)
}

if (repo.isNotBlank()) {
assets.addTemplateProperties("REPOSITORY" to repo)
}

if (useMixins) {
val packageName =
"${buildSystemProps.groupId.toPackageName()}.${modId.toPackageName()}.mixin"
val mixinPackageName = "${buildSystemProps.groupId.toPackageName()}.${modId.toPackageName()}.mixin"
assets.addTemplateProperties(
"MIXINS" to "true",
"MIXIN_PACKAGE_NAME" to packageName,
"MIXIN_PACKAGE_NAME" to mixinPackageName,
)

val mixinsJsonFile = "src/main/resources/$modId.mixins.json"
assets.addTemplates(project, mixinsJsonFile to FABRIC_MIXINS_JSON_TEMPLATE)
}
Expand All @@ -108,36 +126,20 @@ class FabricBaseFilesStep(parent: NewProjectWizardStep) : AbstractLongRunningAss
GeneratorEmptyDirectory("src/main/resources"),
)

assets.addTemplates(project, "src/main/resources/fabric.mod.json" to FABRIC_MOD_JSON_TEMPLATE)
assets.addTemplates(
project,
"src/main/java/${mainClass.replace(".", "/")}.java" to FABRIC_MOD_CLASS_TEMPLATE,
"src/main/java/${clientClass.replace(".", "/")}.java" to FABRIC_MOD_CLIENT_CLASS_TEMPLATE,
"src/main/resources/fabric.mod.json" to FABRIC_MOD_JSON_TEMPLATE
)

WriteAction.runAndWait<Throwable> {
val dir = VfsUtil.createDirectoryIfMissing(
LocalFileSystem.getInstance(),
"${assets.outputDirectory}/.gradle",
)
?: throw IllegalStateException("Unable to create .gradle directory")
val file = dir.findOrCreateChildData(this, MAGIC_DEFERRED_INIT_FILE)
) ?: throw IllegalStateException("Unable to create .gradle directory")

val authors = data.getUserData(AuthorsStep.KEY) ?: emptyList()
val website = data.getUserData(WebsiteStep.KEY)
val repo = data.getUserData(RepositoryStep.KEY)

val packageName = "${buildSystemProps.groupId.toPackageName()}.${modId.toPackageName()}"
val mainClassName = "$packageName.${modName.toJavaClassName()}"
val clientClassName = "$packageName.client.${modName.toJavaClassName()}Client"

val entrypoints = listOf(
"main,${EntryPoint.Type.CLASS.name},$mainClassName,${FabricConstants.MOD_INITIALIZER}",
"client,${EntryPoint.Type.CLASS.name},$clientClassName,${FabricConstants.CLIENT_MOD_INITIALIZER}",
)
val fileContents = """
${authors.joinToString(",")}
$website
$repo
${entrypoints.joinToString(";")}
""".trimIndent() // TODO: un-hardcode?

VfsUtil.saveText(file, fileContents)
dir.findOrCreateChildData(this, MAGIC_DEFERRED_INIT_FILE)
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/kotlin/util/MinecraftTemplates.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ class MinecraftTemplates : FileTemplateGroupDescriptorFactory {

FileTemplateGroupDescriptor("Fabric", PlatformAssets.FABRIC_ICON).let { fabricGroup ->
group.addTemplate(fabricGroup)
fabricGroup.addTemplate(FileTemplateDescriptor(FABRIC_MOD_CLASS_TEMPLATE))
fabricGroup.addTemplate(FileTemplateDescriptor(FABRIC_MOD_CLIENT_CLASS_TEMPLATE))
fabricGroup.addTemplate(FileTemplateDescriptor(FABRIC_GRADLE_PROPERTIES_TEMPLATE))
fabricGroup.addTemplate(FileTemplateDescriptor(FABRIC_BUILD_GRADLE_TEMPLATE, PlatformAssets.FABRIC_ICON))
fabricGroup.addTemplate(
FileTemplateDescriptor(FABRIC_GRADLE_PROPERTIES_TEMPLATE, PlatformAssets.FABRIC_ICON),
)
fabricGroup.addTemplate(FileTemplateDescriptor(FABRIC_MIXINS_JSON_TEMPLATE, PlatformAssets.FABRIC_ICON))
fabricGroup.addTemplate(FileTemplateDescriptor(FABRIC_MOD_JSON_TEMPLATE, PlatformAssets.FABRIC_ICON))
fabricGroup.addTemplate(FileTemplateDescriptor(FABRIC_SETTINGS_GRADLE_TEMPLATE, PlatformAssets.FABRIC_ICON))
Expand Down Expand Up @@ -221,6 +221,8 @@ class MinecraftTemplates : FileTemplateGroupDescriptorFactory {
const val MODS_TOML_TEMPLATE = "mods.toml"
const val PACK_MCMETA_TEMPLATE = "pack.mcmeta"

const val FABRIC_MOD_CLASS_TEMPLATE = "Fabric Mod Class.java"
const val FABRIC_MOD_CLIENT_CLASS_TEMPLATE = "Fabric Mod Client Class.java"
const val FABRIC_BUILD_GRADLE_TEMPLATE = "fabric_build.gradle"
const val FABRIC_GRADLE_PROPERTIES_TEMPLATE = "fabric_gradle.properties"
const val FABRIC_MIXINS_JSON_TEMPLATE = "fabric_mixins.json"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ${MAIN_PACKAGE};

import net.fabricmc.api.ModInitializer;

public class ${MAIN_CLASS_NAME} implements ModInitializer {

@Override
public void onInitialize() {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
Minecraft Development for IntelliJ

https://mcdev.io/

Copyright (C) 2024 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 <https://www.gnu.org/licenses/>.
-->

<html>
<body>
<p>This is a built-in file template used to create a new mod class.</p>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ${CLIENT_PACKAGE};

import net.fabricmc.api.ClientModInitializer;

public class ${CLIENT_CLASS_NAME} implements ClientModInitializer {

@Override
public void onInitializeClient() {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
Minecraft Development for IntelliJ

https://mcdev.io/

Copyright (C) 2024 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 <https://www.gnu.org/licenses/>.
-->

<html>
<body>
<p>This is a built-in file template used to create a new mod class.</p>
</body>
</html>
40 changes: 30 additions & 10 deletions src/main/resources/fileTemplates/j2ee/fabric/fabric_mod.json.ft
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,46 @@

"name": "${MOD_NAME}",
"description": "${MOD_DESCRIPTION}",
#if (${AUTHOR_LIST})
"authors": [${AUTHOR_LIST}],
#else
"authors": [],
"contact": {},
#end

"contact": {
#if (${WEBSITE})
"website": "${WEBSITE}"#if (${REPOSITORY}),
#end
#end
#if (${REPOSITORY})
"repo": "${REPOSITORY}"
#end
},

"license": "${LICENSE}",
"icon": "assets/${MOD_ID}/icon.png",

"environment": "${MOD_ENVIRONMENT}",
"entrypoints": {},
"entrypoints": {
"main": [
"${MAIN_CLASS}"
],
"client": [
"${CLIENT_CLASS}"
]
},

#if (${MIXINS})
"mixins": [
"${MOD_ID}.mixins.json"
],
#end
#if (${MIXINS})
"mixins": [
"${MOD_ID}.mixins.json"
],
#end

"depends": {
"fabricloader": ">=${d}{loader_version}",
#if (${API_VERSION})
"fabric": "*",
#end
#if (${API_VERSION})
"fabric": "*",
#end
"minecraft": "${d}{minecraft_version}"
}
}