Skip to content
Merged
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
15 changes: 6 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ val yarnMappings = property("yarn_mappings").toString()
val libs = file("libs")

plugins {
kotlin("jvm") version "1.9.22"
kotlin("jvm") version "1.9.23"
id("org.jetbrains.dokka") version "1.9.20"
id("architectury-plugin") version "3.4-SNAPSHOT"
id("dev.architectury.loom") version "1.5-SNAPSHOT" apply false
Expand All @@ -26,14 +26,8 @@ subprojects {
apply(plugin = "org.jetbrains.dokka")

dependencies {
if (path == ":quilt") {
"minecraft"("com.mojang:minecraft:1.20.2")
"mappings"("net.fabricmc:yarn:1.20.2+build.3:v2")
}
else {
"minecraft"("com.mojang:minecraft:$minecraftVersion")
"mappings"("net.fabricmc:yarn:$yarnMappings:v2")
}
"minecraft"("com.mojang:minecraft:$minecraftVersion")
"mappings"("net.fabricmc:yarn:$yarnMappings:v2")
}

if (path == ":common") return@subprojects
Expand All @@ -46,17 +40,20 @@ subprojects {
isCanBeConsumed = false
isCanBeResolved = true
}

val shadow = named<ShadowJar>("shadowJar") {
archiveVersion = versionWithMCVersion
archiveClassifier.set("shadow")
configurations = listOf(shadowCommon)
}

named<RemapJarTask>("remapJar") {
dependsOn(shadow)
inputFile = shadow.flatMap { it.archiveFile }
archiveVersion = versionWithMCVersion
archiveClassifier = ""
}

jar {
enabled = false
}
Expand Down
17 changes: 6 additions & 11 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
val fabricLoaderVersion = property("fabric_loader_version").toString()
val fabricKotlinVersion = property("fabric_kotlin_version").toString()
val mixinExtrasVersion = property("mixinextras_version").toString()
val kotlinVersion = property("kotlin_version").toString()
val kotlinxCoroutinesVersion = property("kotlinx_coroutines_version").toString()
val architecturyVersion = property("architectury_version").toString()

architectury { common("fabric", "forge", "neoforge", "quilt") }
architectury { common("fabric", "forge", "neoforge") }

loom {
silentMojangMappingsLicense()
Expand All @@ -12,24 +13,18 @@ loom {

repositories {
maven("https://maven.fabricmc.net/")
maven("https://jitpack.io")

mavenCentral()
mavenLocal()
}

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")

// Remove the following line if you don't want to depend on the API
modApi("dev.architectury:architectury:$architecturyVersion")

// 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")!!)

// Add Kotlin
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion")
}

// Avoid nested jars
Expand Down
17 changes: 6 additions & 11 deletions common/src/main/kotlin/com/lambda/Lambda.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ package com.lambda

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.lambda.config.serializer.*
import com.lambda.module.tag.ModuleTag
import com.lambda.util.KeyCode
import dev.architectury.platform.Platform
import com.lambda.config.serializer.BlockPosSerializer
import com.lambda.config.serializer.BlockSerializer
import com.lambda.config.serializer.ColorSerializer
import net.minecraft.block.Block
import net.minecraft.client.MinecraftClient
import net.minecraft.util.math.BlockPos
import org.apache.logging.log4j.Level
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.core.Logger
import org.apache.logging.log4j.Logger
import java.awt.Color


Expand All @@ -20,14 +18,11 @@ object Lambda {
const val MOD_ID = "lambda"
const val SYMBOL = "λ"
val VERSION: String = LoaderInfo.getVersion()
val LOG = (LogManager.getLogger(SYMBOL) as Logger)
.apply { level = if (Platform.isDevelopmentEnvironment()) Level.DEBUG else Level.INFO }
@JvmStatic val mc: MinecraftClient by lazy { MinecraftClient.getInstance() }
val LOG: Logger = LogManager.getLogger(SYMBOL)
val mc: MinecraftClient by lazy { MinecraftClient.getInstance() }

val gson: Gson = GsonBuilder()
.setPrettyPrinting()
.registerTypeAdapter(ModuleTag::class.java, ModuleTagSerializer)
.registerTypeAdapter(KeyCode::class.java, KeyCodeSerializer)
.registerTypeAdapter(Color::class.java, ColorSerializer)
.registerTypeAdapter(BlockPos::class.java, BlockPosSerializer)
.registerTypeAdapter(Block::class.java, BlockSerializer)
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/kotlin/com/lambda/Loader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ object Loader {

LOG.info("${Lambda.MOD_NAME} ${Lambda.VERSION} was successfully initialized (${initTime}ms)")
}
}
}
14 changes: 12 additions & 2 deletions common/src/main/kotlin/com/lambda/command/CommandManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,17 @@ object CommandManager : Configurable(LambdaConfig), Loadable {
override fun load(): String {
Reflections(
ConfigurationBuilder()
.setUrls(ClasspathHelper.forPackage("com.lambda.command.commands"))
// Let's hope the maintainer of the library releases a new version soon
// because this is horrible, it takes multiple SECONDS to scan the classpath,
// and it's not even that big
//
// The culprit may be due to [ClasspathHelper.forClassLoader()] loading
// the classes from the main thread while we are in a different thread.
// If this is the case I wish the maintainer a very bad day.
.addUrls(ClasspathHelper.forJavaClassPath())
.addUrls(ClasspathHelper.forClassLoader())
.filterInputsBy { it.contains("lambda") }
.forPackage("com.lambda.command.commands")
.setScanners(Scanners.SubTypes)
).getSubTypesOf(LambdaCommand::class.java).forEach { commandClass ->
commandClass.declaredFields.find {
Expand All @@ -131,4 +141,4 @@ object CommandManager : Configurable(LambdaConfig), Loadable {

return "Registered ${commands.size} commands"
}
}
}
18 changes: 15 additions & 3 deletions common/src/main/kotlin/com/lambda/module/ModuleRegistry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import org.reflections.scanners.Scanners
import org.reflections.util.ClasspathHelper
import org.reflections.util.ConfigurationBuilder



/**
* The [ModuleRegistry] object is responsible for managing all [Module] instances in the system.
*
Expand All @@ -21,8 +23,18 @@ object ModuleRegistry : Loadable {
override fun load(): String {
Reflections(
ConfigurationBuilder()
.setUrls(ClasspathHelper.forPackage("com.lambda.module.modules"))
.setScanners(Scanners.SubTypes)
// Let's hope the maintainer of the library releases a new version soon
// because this is horrible, it takes multiple SECONDS to scan the classpath,
// and it's not even that big
//
// The culprit may be due to [ClasspathHelper.forClassLoader()] loading
// the classes from the main thread while we are in a different thread.
// If this is the case I wish the maintainer a very bad day.
.addUrls(ClasspathHelper.forJavaClassPath())
.addUrls(ClasspathHelper.forClassLoader())
.filterInputsBy { it.contains("lambda") }
.forPackage("com.lambda.module.modules")
.addScanners(Scanners.SubTypes)
).getSubTypesOf(Module::class.java).forEach { moduleClass ->
moduleClass.declaredFields.find {
it.name == "INSTANCE"
Expand All @@ -36,4 +48,4 @@ object ModuleRegistry : Loadable {

return "Registered ${modules.size} modules with ${modules.sumOf { it.settings.size }} settings"
}
}
}
4 changes: 2 additions & 2 deletions common/src/main/kotlin/com/lambda/util/FolderRegister.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.lambda.util

import com.lambda.Lambda.mc
import com.lambda.util.FolderRegister.config
import com.lambda.util.FolderRegister.lambda
import com.lambda.util.FolderRegister.minecraft
import dev.architectury.platform.Platform
import java.io.File

/**
Expand All @@ -14,7 +14,7 @@ import java.io.File
* @property config The directory for storing configuration files, located within the Lambda directory.
*/
object FolderRegister {
val minecraft: File = Platform.getGameFolder().toFile()
val minecraft: File = mc.runDirectory
val lambda: File = File(minecraft, "lambda")
val config: File = File(lambda, "config")
}
17 changes: 6 additions & 11 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
val fabricLoaderVersion = property("fabric_loader_version").toString()
val fabricApiVersion = property("fabric_api_version").toString()
val fabricKotlinVersion = property("fabric_kotlin_version").toString()
val architecturyVersion = property("architectury_version").toString()
val kotlinFabricVersion = property("kotlin_fabric_version").toString()

architectury {
platformSetupLoomIde()
Expand Down Expand Up @@ -32,26 +32,21 @@ fun DependencyHandlerScope.setupConfigurations() {

includeMod.dependencies.forEach {
modImplementation(it)
include(it)
}
}

dependencies {
// Fabric API (Do not touch)
modImplementation("net.fabricmc:fabric-loader:$fabricLoaderVersion")
modApi("net.fabricmc.fabric-api:fabric-api:$fabricApiVersion")

// Remove the following line if you don't want to depend on the API
modApi("dev.architectury:architectury-fabric:$architecturyVersion")

// Kotlin for Fabric
modImplementation("net.fabricmc:fabric-language-kotlin:$fabricKotlinVersion")

// Add dependencies on the required Kotlin modules.
includeLib("org.reflections:reflections:0.10.2")
includeLib("org.javassist:javassist:3.27.0-GA")
includeLib("org.javassist:javassist:3.28.0-GA")

// Add mods to the mod jar
// includeMod(...)
includeMod("net.fabricmc.fabric-api:fabric-api:$fabricApiVersion")
includeMod("net.fabricmc:fabric-language-kotlin:$kotlinFabricVersion")

// Common (Do not touch)
common(project(":common", configuration = "namedElements")) { isTransitive = false }
Expand All @@ -70,7 +65,7 @@ tasks {
expand(getProperties())
expand(mutableMapOf(
"group" to project.group,
"version" to project.version
"version" to project.version,
))
}
}
Expand Down
11 changes: 5 additions & 6 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@
"lambda.mixins.common.json"
],
"depends": {
"fabricloader": ">=0.14.24",
"fabric-api": ">=0.83.0+1.20",
"architectury": ">=9.0.6",
"minecraft": ">=1.20.0",
"java": ">=17",
"fabric-language-kotlin": ">=${fabric_kotlin_version}"
"fabricloader": ">=0.15.1",
"fabric-api": ">=0.91.3+1.20.4",
"minecraft": "1.20.4",
"fabric-language-kotlin": ">=${kotlin_fabric_version}",
"java": ">=17"
}
}
53 changes: 24 additions & 29 deletions forge/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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()
val kotlinForgeVersion = property("kotlin_forge_version").toString()

architectury {
platformSetupLoomIde()
Expand All @@ -18,23 +18,11 @@ loom {
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/")
maven("https://cursemaven.com")
maven("https://thedarkcolour.github.io/KotlinForForge/")
}

val common: Configuration by configurations.creating {
Expand All @@ -45,43 +33,40 @@ val common: Configuration by configurations.creating {

val includeLib: Configuration by configurations.creating
val includeMod: Configuration by configurations.creating
val shadowInclude: Configuration by configurations.creating

fun DependencyHandlerScope.setupConfigurations() {
includeLib.dependencies.forEach {
implementation(it)
forgeRuntimeLibrary(it)
include(it)
}

// Please look at this before yelling at me
// https://docs.architectury.dev/loom/using_libraries/
includeMod.dependencies.forEach {
implementation(it)
forgeRuntimeLibrary(it)
include(it)
}
}

dependencies {
// Forge API
forge("net.minecraftforge:forge:$forgeVersion")

// Remove the following line if you don't want to depend on the 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")!!)
includeLib("org.javassist:javassist:3.28.0-GA")

// Add mods to the mod jar
includeMod("thedarkcolour:kotlinforforge:$kotlinForgeVersion")

// Bugfixes
compileOnly(kotlin("stdlib")) // Hack https://github.com/thedarkcolour/KotlinForForge/issues/93
// MixinExtras
implementation("io.github.llamalad7:mixinextras-forge:$mixinExtrasVersion")
compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:$mixinExtrasVersion")!!)

// Fix KFF
compileOnly(kotlin("stdlib"))

// 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
common(project(":common", configuration = "namedElements")) { isTransitive = false }
shadowCommon(project(path = ":common", configuration = "transformProductionForge")) { isTransitive = false }

// Finish the configuration
Expand All @@ -90,11 +75,21 @@ dependencies {

tasks {
processResources {
inputs.property("group", project.group)
inputs.property("version", project.version)

filesMatching("META-INF/mods.toml") {
expand(getProperties())
expand(mutableMapOf("version" to project.version))
expand(mutableMapOf(
"group" to project.group,
"version" to project.version,
))
}
}

sourceSets.forEach {
val dir = layout.buildDirectory.dir("sourcesSets/${it.name}")
it.output.setResourcesDir(dir)
it.java.destinationDirectory.set(dir)
}
}
Loading