Initial commit

This commit is contained in:
2026-03-23 11:14:33 +01:00
commit 0cceecdd39
24 changed files with 872 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
plugins {
id("de.siphalor.smcmtk.plugin")
}
description = "This is the settings plugin that serves as the main entrypoint for development with SMCMTK. " +
"It configures the cross-version structure, properties and dependencies."
gradlePlugin {
val settingPlugin by plugins.creating {
id = "de.siphalor.minecraft-modding-toolkit.settings-plugin"
implementationClass = "de.siphalor.minecraft_modding_toolkit.gradle.settings_plugin.SmcmtkSettingsPlugin"
}
}

View File

@@ -0,0 +1,12 @@
package de.siphalor.minecraft_modding_toolkit.gradle.settings_plugin
import org.jetbrains.annotations.ApiStatus
@ApiStatus.Internal
class SmcmtkManifest private constructor(val version: String) {
companion object {
fun resolve(): SmcmtkManifest {
return SmcmtkManifest(javaClass.`package`.implementationVersion ?: "0.0.0")
}
}
}

View File

@@ -0,0 +1,8 @@
package de.siphalor.minecraft_modding_toolkit.gradle.settings_plugin
import org.gradle.api.provider.Property
abstract class SmcmtkSettingsExtension {
abstract val fabricLoomVersion: Property<String>
abstract val jcyoVersion: Property<String>
}

View File

@@ -0,0 +1,78 @@
package de.siphalor.minecraft_modding_toolkit.gradle.settings_plugin
import org.gradle.api.Plugin
import org.gradle.api.initialization.Settings
import org.gradle.api.logging.Logging
import org.gradle.api.model.ObjectFactory
import org.gradle.api.plugins.ExtraPropertiesExtension
import java.io.File
import java.util.*
import javax.inject.Inject
abstract class SmcmtkSettingsPlugin : Plugin<Settings> {
companion object {
private const val PROJECT_PLUGIN_ID = "de.siphalor.minecraft-modding-toolkit.project-plugin"
}
@get:Inject
protected abstract val objectFactory: ObjectFactory
private val logger = lazy { Logging.getLogger(javaClass) }
override fun apply(settings: Settings) {
val gradleProperties = loadProperties(settings.rootDir.resolve("gradle.properties"))
val minecraftVersionDescriptor = gradleProperties["minecraft.version.descriptor"]
?: error("Missing minecraft.version.descriptor in gradle.properties")
val minecraftVersionDir = settings.rootDir.resolve("gradle/mc-$minecraftVersionDescriptor")
val minecraftVersionProperties = loadProperties(minecraftVersionDir.resolve("gradle.properties"))
val fabricLoom = minecraftVersionProperties["fabric.loom"]
val extension = settings.extensions.create("smcmtk", SmcmtkSettingsExtension::class.java)
val smcmtkManifest = SmcmtkManifest.resolve()
val fabricLoomModule = when (fabricLoom) {
"plain" -> "net.fabricmc.fabric-loom"
"remap" -> "net.fabricmc.fabric-loom-remap"
else -> null
}
if (fabricLoomModule != null) {
logger.value.info("Choosing Fabric Loom $fabricLoomModule")
}
settings.pluginManagement.plugins {
it.id(PROJECT_PLUGIN_ID).version(smcmtkManifest.version)
}
settings.gradle.settingsEvaluated {
settings.dependencyResolutionManagement.versionCatalogs.create("mcLibs") {
it.from(objectFactory.fileCollection().from(minecraftVersionDir.resolve("mc.versions.toml")))
it.plugin("smcmtk", PROJECT_PLUGIN_ID)
.version(smcmtkManifest.version)
fabricLoomModule?.let { loomModule ->
it.plugin("fabric-loom", loomModule).version(extension.fabricLoomVersion.get())
}
}
}
if (fabricLoom == "plain") {
settings.gradle.allprojects { project ->
project.extensions.findByType(ExtraPropertiesExtension::class.java)?.apply {
// Loom uses the same jar for both plugin variants (plain and remap) and tries to determine
// which one is in use by checking the plugin manager.
// This doesn't seem to work when using convention plugins, so we're forcing the remapping off here.
project.extensions.extraProperties.set("fabric.loom.disableObfuscation", "true")
project.extensions.extraProperties.set("fabric.loom.dontRemap", "true")
}
}
}
}
private fun loadProperties(file: File): Properties {
return Properties().apply {
load(file.inputStream())
}
}
}