diff --git a/build.gradle.kts b/build.gradle.kts index bd9020ba8..0823ac86c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,11 +1,13 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import net.fabricmc.loom.task.RemapJarTask -val modId = project.properties["mod_id"].toString() -val modVersion = project.properties["mod_version"].toString() -val mavenGroup = project.properties["maven_group"].toString() -val minecraftVersion = project.properties["minecraft_version"].toString() -val yarnMappings = project.properties["yarn_mappings"].toString() +val modId = property("mod_id").toString() +val modVersion = property("mod_version").toString() +val mavenGroup = property("maven_group").toString() +val minecraftVersion = property("minecraft_version").toString() +val yarnMappings = property("yarn_mappings").toString() + +val libs = file("libs") plugins { kotlin("jvm") version "1.9.22" @@ -22,6 +24,7 @@ architectury { subprojects { apply(plugin = "dev.architectury.loom") apply(plugin = "org.jetbrains.dokka") + dependencies { "minecraft"("com.mojang:minecraft:$minecraftVersion") "mappings"("net.fabricmc:yarn:$yarnMappings:v2") @@ -66,19 +69,18 @@ allprojects { repositories { maven("https://api.modrinth.com/maven") maven("https://jitpack.io") - maven("https://maven.shedaniel.me/") { - name = "Architectury" - } + maven("https://maven.shedaniel.me/") { name = "Architectury" } maven("https://maven.terraformersmc.com/releases/") - } - tasks { - withType { - options.encoding = "UTF-8" - options.release = 17 - } - compileKotlin { - kotlinOptions.jvmTarget = "17" + flatDir { + dirs(libs) } } + + java { + // withSourcesJar() // Uncomment this line when the plugin system is ready + + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } } diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 4ca7e64dc..ba93c4e04 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -1,18 +1,19 @@ -val fabricLoaderVersion = project.properties["fabric_loader_version"].toString() -val fabricKotlinVersion = project.properties["fabric_kotlin_version"].toString() -val mixinExtrasVersion = project.properties["mixinextras_version"].toString() +val fabricLoaderVersion = property("fabric_loader_version").toString() +val fabricKotlinVersion = property("fabric_kotlin_version").toString() +val mixinExtrasVersion = property("mixinextras_version").toString() +val kotlinXCoroutineVersion = property("kotlinx_coroutines_version").toString() -architectury { common("fabric", "forge") } +architectury { common("fabric", "forge", "neoforge") } loom { + silentMojangMappingsLicense() accessWidenerPath.set(File("src/main/resources/lambda.accesswidener")) } repositories { - maven("https://maven.fabricmc.net/") { - name = "Fabric" - } + maven("https://maven.fabricmc.net/") maven("https://jitpack.io") + mavenCentral() mavenLocal() } @@ -21,12 +22,14 @@ dependencies { // We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies // Do NOT use other classes from fabric loader modImplementation("net.fabricmc:fabric-loader:$fabricLoaderVersion") + // Add dependencies on the required Kotlin modules. modImplementation("net.fabricmc:fabric-language-kotlin:$fabricKotlinVersion") implementation("org.reflections:reflections:0.10.2") implementation(annotationProcessor("io.github.llamalad7:mixinextras-common:$mixinExtrasVersion")!!) } +// Avoid nested jars tasks.named("remapJar") { enabled = false } diff --git a/common/src/main/kotlin/com/lambda/Lambda.kt b/common/src/main/kotlin/com/lambda/Lambda.kt index 818b5903a..0be931bf1 100644 --- a/common/src/main/kotlin/com/lambda/Lambda.kt +++ b/common/src/main/kotlin/com/lambda/Lambda.kt @@ -13,13 +13,14 @@ import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger object Lambda { - private const val MOD_NAME = "Lambda" + const val MOD_NAME = "Lambda" const val MOD_ID = "lambda" private const val SYMBOL = "λ" - private val VERSION: String = LoaderInfo.getVersion() + val VERSION: String = LoaderInfo.getVersion() val LOG: Logger = LogManager.getLogger(SYMBOL) - val mc: MinecraftClient = MinecraftClient.getInstance() + val mc: MinecraftClient by lazy { MinecraftClient.getInstance() } + val gson: Gson = GsonBuilder() .setPrettyPrinting() .registerTypeAdapter(BlockPos::class.java, BlockPosSerializer) diff --git a/common/src/main/kotlin/com/lambda/event/EventMutable.kt b/common/src/main/kotlin/com/lambda/event/Muteable.kt similarity index 100% rename from common/src/main/kotlin/com/lambda/event/EventMutable.kt rename to common/src/main/kotlin/com/lambda/event/Muteable.kt diff --git a/common/src/main/kotlin/com/lambda/module/modules/BoringModule.kt b/common/src/main/kotlin/com/lambda/module/modules/BoringModule.kt index af78781d3..3d0af3e79 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/BoringModule.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/BoringModule.kt @@ -24,7 +24,7 @@ object BoringModule : Module( mapOf("One" to 1, "Two" to 2, "Three" to 3, "Four" to 4, "Five" to 5) ) private val boringEnum by setting("Boring Enum", BoringEnum.ONE) - private val blockSetting by setting("Boring Block", Blocks.STONE) + //private val blockSetting by setting("Boring Block", Blocks.STONE) // Registries are not initialized yet private val blockPosSetting by setting("Boring BlockPos", BlockPos(420, 69, 1337)) // private val blockListSetting by setting("Boring Block List", listOf(Blocks.STONE, Blocks.DIRT, Blocks.GRASS_BLOCK)) @@ -49,4 +49,4 @@ object BoringModule : Module( LOG.info("I'm ${if (superBoring) "super boring ($boringValue)" else "boring"}! $isEnabled") } } -} \ No newline at end of file +} diff --git a/common/src/main/kotlin/com/lambda/util/FolderRegister.kt b/common/src/main/kotlin/com/lambda/util/FolderRegister.kt index fcda05702..553751c58 100644 --- a/common/src/main/kotlin/com/lambda/util/FolderRegister.kt +++ b/common/src/main/kotlin/com/lambda/util/FolderRegister.kt @@ -7,4 +7,4 @@ object FolderRegister { val minecraft: File = mc.runDirectory val lambda: File = File(minecraft, "lambda") val config: File = File(lambda, "config") -} \ No newline at end of file +} diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index 55851cf81..21418d2c4 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -1,6 +1,6 @@ -val fabricLoaderVersion = project.properties["fabric_loader_version"].toString() -val fabricApiVersion = project.properties["fabric_api_version"].toString() -val fabricKotlinVersion = project.properties["fabric_kotlin_version"].toString() +val fabricLoaderVersion = property("fabric_loader_version").toString() +val fabricApiVersion = property("fabric_api_version").toString() +val fabricKotlinVersion = property("fabric_kotlin_version").toString() architectury { platformSetupLoomIde() @@ -20,17 +20,39 @@ val common: Configuration by configurations.creating { configurations["developmentFabric"].extendsFrom(this) } -dependencies { - common(project(":common", configuration = "namedElements")) { - isTransitive = false +val includeLib: Configuration by configurations.creating +val includeMod: Configuration by configurations.creating + +fun DependencyHandlerScope.setupConfigurations() { + includeLib.dependencies.forEach { + implementation(it) + include(it) } - shadowCommon(project(path = ":common", configuration = "transformProductionFabric")) { - isTransitive = false + + includeMod.dependencies.forEach { + modImplementation(it) } +} + +dependencies { + // Fabric API (Do not touch) modImplementation("net.fabricmc:fabric-loader:$fabricLoaderVersion") modImplementation("net.fabricmc.fabric-api:fabric-api:$fabricApiVersion") modImplementation("net.fabricmc:fabric-language-kotlin:$fabricKotlinVersion") - implementation("org.reflections:reflections:0.10.2") + + // Add dependencies on the required Kotlin modules. + includeLib("org.reflections:reflections:0.10.2") + includeLib("org.javassist:javassist:3.27.0-GA") + + // Add mods to the mod jar + // includeMod(...) + + // Common (Do not touch) + common(project(":common", configuration = "namedElements")) { isTransitive = false } + shadowCommon(project(path = ":common", configuration = "transformProductionFabric")) { isTransitive = false } + + // Finish the configuration + setupConfigurations() } tasks { diff --git a/fabric/src/main/kotlin/com/lambda/fabric/LambdaFabric.kt b/fabric/src/main/kotlin/com/lambda/fabric/LambdaFabric.kt index 7f9b8a94e..1b6840aa8 100644 --- a/fabric/src/main/kotlin/com/lambda/fabric/LambdaFabric.kt +++ b/fabric/src/main/kotlin/com/lambda/fabric/LambdaFabric.kt @@ -3,11 +3,12 @@ package com.lambda.fabric import net.fabricmc.api.ClientModInitializer import com.lambda.Lambda import com.lambda.Lambda.LOG +import com.lambda.Lambda.MOD_NAME +import com.lambda.Lambda.VERSION object LambdaFabric : ClientModInitializer { override fun onInitializeClient() { Lambda.initialize() - - LOG.info("Lambda Fabric initialized") + LOG.info("$MOD_NAME Fabric $VERSION initialized.") } } diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 3482da947..f641d1196 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -26,9 +26,9 @@ "lambda.mixins.common.json" ], "depends": { - "fabricloader": ">=${fabric_loader_version}", - "fabric-api": "*", - "minecraft": "1.20.4", + "fabricloader": ">=0.14.24", + "fabric-api": ">=0.83.0+1.20", + "minecraft": ">=1.20.0", "java": ">=17", "fabric-language-kotlin": ">=${fabric_kotlin_version}" } diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts index 0ded81a09..259cec3c7 100644 --- a/forge/build.gradle.kts +++ b/forge/build.gradle.kts @@ -1,6 +1,7 @@ -val forgeVersion = project.properties["forge_version"].toString() -val kotlinForgeVersion = project.properties["kotlin_forge_version"].toString() -val mixinExtrasVersion = project.properties["mixinextras_version"].toString() +val forgeVersion = property("forge_version").toString() +val kotlinForgeVersion = property("kotlin_forge_version").toString() +val architecturyVersion = property("architectury_version").toString() +val mixinExtrasVersion = property("mixinextras_version").toString() architectury { platformSetupLoomIde() @@ -11,20 +12,29 @@ base.archivesName.set("${base.archivesName.get()}-forge") loom { accessWidenerPath.set(project(":common").loom.accessWidenerPath) + forge { convertAccessWideners = true extraAccessWideners.add(loom.accessWidenerPath.get().asFile.name) mixinConfig("lambda.mixins.common.json") } + + mods { + register("forge") { + sourceSet("main", project(":forge")) + + sourceSets.forEach { + val dir = layout.buildDirectory.dir("sourcesSets/${it.name}") + it.output.setResourcesDir(dir) + it.java.destinationDirectory.set(dir) + } + } + } } repositories { - maven("https://thedarkcolour.github.io/KotlinForForge/") { - name = "KotlinForForge" - } - maven("https://cursemaven.com") { - name = "Curse" - } + maven("https://thedarkcolour.github.io/KotlinForForge/") + maven("https://cursemaven.com") } val common: Configuration by configurations.creating { @@ -33,18 +43,49 @@ val common: Configuration by configurations.creating { configurations["developmentForge"].extendsFrom(this) } -dependencies { - forge("net.minecraftforge:forge:$forgeVersion") - implementation("thedarkcolour:kotlinforforge:$kotlinForgeVersion") - common(project(":common", configuration = "namedElements")) { - isTransitive = false +val includeLib: Configuration by configurations.creating +val includeMod: Configuration by configurations.creating + +fun DependencyHandlerScope.setupConfigurations() { + includeLib.dependencies.forEach { + implementation(it) + include(it) } - shadowCommon(project(path = ":common", configuration = "transformProductionForge")) { - isTransitive = false + + // Please look at this before yelling at me + // https://docs.architectury.dev/loom/using_libraries/ + includeMod.dependencies.forEach { + implementation(it) + forgeRuntimeLibrary(it) } - implementation(annotationProcessor("io.github.llamalad7:mixinextras-common:$mixinExtrasVersion")!!) - implementation(include("io.github.llamalad7:mixinextras-forge:$mixinExtrasVersion")!!) - implementation("org.reflections:reflections:0.10.2") +} + +dependencies { + // Forge API + forge("net.minecraftforge:forge:$forgeVersion") + + // Architectury API + modApi("dev.architectury:architectury-forge:$architecturyVersion") + + // Add dependencies on the required Kotlin modules. + includeLib("org.reflections:reflections:0.10.2") + includeLib("org.javassist:javassist:3.27.0-GA") + + implementation("io.github.llamalad7:mixinextras-forge:$mixinExtrasVersion") + compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:$mixinExtrasVersion")!!) + + // Add mods to the mod jar + includeMod("thedarkcolour:kotlinforforge:$kotlinForgeVersion") + + // Bugfixes + compileOnly(kotlin("stdlib")) // Hack https://github.com/thedarkcolour/KotlinForForge/issues/93 + + // Common (Do not touch) + common(project(":common", configuration = "namedElements")) { isTransitive = false } // We cannot common here because it is treated as a different mod and forge will panic + shadowCommon(project(path = ":common", configuration = "transformProductionForge")) { isTransitive = false } + + // Finish the configuration + setupConfigurations() } tasks { diff --git a/forge/src/main/kotlin/com/lambda/forge/LambdaForge.kt b/forge/src/main/kotlin/com/lambda/forge/LambdaForge.kt index 14edcd0fe..97f6daaa9 100644 --- a/forge/src/main/kotlin/com/lambda/forge/LambdaForge.kt +++ b/forge/src/main/kotlin/com/lambda/forge/LambdaForge.kt @@ -3,12 +3,13 @@ package com.lambda.forge import net.minecraftforge.fml.common.Mod import com.lambda.Lambda import com.lambda.Lambda.LOG +import com.lambda.Lambda.MOD_NAME +import com.lambda.Lambda.VERSION @Mod(Lambda.MOD_ID) object LambdaForge { init { Lambda.initialize() - - LOG.info("Lambda Forge initialized") + LOG.info("$MOD_NAME Forge $VERSION initialized.") } } diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index dc7ed6e59..598fb04c1 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -6,7 +6,7 @@ license = "GNU General Public License v3.0" modId = "lambda" version = "${version}" displayName = "Lambda" -authors = "Constructor" +authors = "${authors}" description = ''' ''' logoFile = "assets/lambda/lambda.png" @@ -15,14 +15,14 @@ displayTest = "IGNORE_ALL_VERSION" [[dependencies.lambda]] modId = "forge" mandatory = true -versionRange = "[47,)" +versionRange = "[44,)" ordering = "NONE" side = "CLIENT" [[dependencies.lambda]] modId = "minecraft" mandatory = true -versionRange = "[1.20.4,)" +versionRange = "[1.19.3,1.21)" ordering = "NONE" side = "CLIENT" diff --git a/gradle.properties b/gradle.properties index 31d8f08ca..0dfc06a09 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,14 @@ -# Lambda https://github.com/lambda-client/NeoLambda +# Lambda https://github.com/lambda-client/lambda mod_id=lambda mod_version=1.0.0 +mod_description=Minecraft utility mod coded in Kotlin maven_group=com.lambda +authors=Constructor # General minecraft_version=1.20.4 mixinextras_version=0.3.5 +kotlinx_coroutines_version=1.8.0 # Architectury https://docs.architectury.dev/start enabled_platforms=fabric,forge @@ -21,9 +24,12 @@ fabric_kotlin_version=1.10.18+kotlin.1.9.22 forge_version=1.20.4-49.0.31 kotlin_forge_version=4.10.0 +# NeoForge https://neoforged.net +neo_version=20.4.196 + # Kotlin https://kotlinlang.org/ kotlin.code.style=official # Gradle https://gradle.org/ org.gradle.jvmargs=-Xmx2048M -org.gradle.parallel=true4 \ No newline at end of file +org.gradle.parallel=true diff --git a/neoforge/build.gradle.kts b/neoforge/build.gradle.kts new file mode 100644 index 000000000..417790b88 --- /dev/null +++ b/neoforge/build.gradle.kts @@ -0,0 +1,68 @@ +val neoVersion = property("neo_version").toString() +val kotlinForgeVersion = property("kotlin_forge_version").toString() +val mixinExtrasVersion = property("mixinextras_version").toString() + +architectury { + platformSetupLoomIde() + neoForge() +} + +base.archivesName.set("${base.archivesName.get()}-neoforge") + +loom { + accessWidenerPath.set(project(":common").loom.accessWidenerPath) +} + +repositories { + maven("https://maven.neoforged.net/releases/") + maven("https://thedarkcolour.github.io/KotlinForForge/") +} + +val common: Configuration by configurations.creating { + configurations.compileClasspath.get().extendsFrom(this) + configurations.runtimeClasspath.get().extendsFrom(this) + configurations["developmentNeoForge"].extendsFrom(this) +} + +val includeLib: Configuration by configurations.creating +val includeMod: Configuration by configurations.creating + +fun DependencyHandlerScope.setupConfigurations() { + includeLib.dependencies.forEach { + implementation(it) + include(it) + } + + includeMod.dependencies.forEach { + implementation(it) + } +} + +dependencies { + // NeoForge API + neoForge("net.neoforged:neoforge:$neoVersion") + + // Add dependencies on the required Kotlin modules. + // includeLib(...) + + // Add mods to the mod jar + includeMod("thedarkcolour:kotlinforforge-neoforge:$kotlinForgeVersion") + + // Common (Do not touch) + common(project(":common", configuration = "namedElements")) { isTransitive = false } + shadowCommon(project(path = ":common", configuration = "transformProductionNeoForge")) { isTransitive = false } + + // Finish the configuration + setupConfigurations() +} + +tasks { + processResources { + inputs.property("version", project.version) + + filesMatching("META-INF/mods.toml") { + expand(getProperties()) + expand(mutableMapOf("version" to project.version)) + } + } +} diff --git a/neoforge/gradle.properties b/neoforge/gradle.properties new file mode 100644 index 000000000..7da18ea6f --- /dev/null +++ b/neoforge/gradle.properties @@ -0,0 +1 @@ +loom.platform=neoforge diff --git a/neoforge/src/main/kotlin/com/lambda/neoforge/LambdaNeoForge.kt b/neoforge/src/main/kotlin/com/lambda/neoforge/LambdaNeoForge.kt new file mode 100644 index 000000000..491132500 --- /dev/null +++ b/neoforge/src/main/kotlin/com/lambda/neoforge/LambdaNeoForge.kt @@ -0,0 +1,15 @@ +package com.lambda.neoforge + +import net.neoforged.fml.common.Mod +import com.lambda.Lambda +import com.lambda.Lambda.LOG +import com.lambda.Lambda.MOD_NAME +import com.lambda.Lambda.VERSION + +@Mod(Lambda.MOD_ID) +object LambdaNeoForge { + init { + Lambda.initialize() + LOG.info("$MOD_NAME Fabric $VERSION initialized.") + } +} diff --git a/neoforge/src/main/kotlin/com/lambda/neoforge/LoaderInfoImpl.kt b/neoforge/src/main/kotlin/com/lambda/neoforge/LoaderInfoImpl.kt new file mode 100644 index 000000000..cd81773e6 --- /dev/null +++ b/neoforge/src/main/kotlin/com/lambda/neoforge/LoaderInfoImpl.kt @@ -0,0 +1,10 @@ +package com.lambda.neoforge + +import net.neoforged.fml.loading.FMLLoader + + +object LoaderInfoImpl { + @JvmStatic + fun getVersion(): String = + FMLLoader.getLoadingModList().getModFileById("lambda").versionString() +} diff --git a/neoforge/src/main/resources/META-INF/mods.toml b/neoforge/src/main/resources/META-INF/mods.toml new file mode 100644 index 000000000..fe30883ac --- /dev/null +++ b/neoforge/src/main/resources/META-INF/mods.toml @@ -0,0 +1,36 @@ +modLoader = "kotlinforforge" +loaderVersion = "[4,)" +license = "GNU General Public License v3.0" + +[[mods]] +modId = "lambda" +version = "${version}" +displayName = "Lambda" +authors = "${authors}" +description = "${description}" +logoFile = "assets/lambda/lambda.png" +displayTest = "IGNORE_ALL_VERSION" + +[[dependencies.lambda]] +modId = "neoforge" +mandatory = true +type = "required" +versionRange = "[20.2,)" +ordering = "NONE" +side = "CLIENT" + +[[dependencies.lambda]] +modId = "minecraft" +mandatory = true +type = "required" +versionRange = "[1.20.2,1.21)" +ordering = "NONE" +side = "CLIENT" + +[[dependencies.lambda]] +modId = "kotlinforforge" +mandatory = true +type = "required" +versionRange = "[4,)" +ordering = "AFTER" +side = "CLIENT" diff --git a/neoforge/src/main/resources/pack.mcmeta b/neoforge/src/main/resources/pack.mcmeta new file mode 100644 index 000000000..bcf1d9ead --- /dev/null +++ b/neoforge/src/main/resources/pack.mcmeta @@ -0,0 +1,6 @@ +{ + "pack": { + "description": "lambda", + "pack_format": 9 + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 6b099e1b0..85b87a908 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,9 +1,7 @@ rootProject.name = "Lambda" pluginManagement { repositories { - maven("https://maven.fabricmc.net/") { - name = "Fabric" - } + maven("https://maven.fabricmc.net/") maven("https://maven.architectury.dev/") maven("https://maven.minecraftforge.net/") mavenCentral() @@ -14,3 +12,4 @@ pluginManagement { include("common") include("fabric") include("forge") +include("neoforge")