Skip to content

Commit 3c7ca37

Browse files
committed
Fix: Reflections (doesn't work everywhere)
please end my suffering that is of multiplatform minecraft mod
1 parent d97d8aa commit 3c7ca37

File tree

8 files changed

+48
-16
lines changed

8 files changed

+48
-16
lines changed

common/src/main/kotlin/com/lambda/Loader.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ object Loader {
2727

2828
LOG.info("${Lambda.MOD_NAME} ${Lambda.VERSION} was successfully initialized (${initTime}ms)")
2929
}
30-
}
30+
}

common/src/main/kotlin/com/lambda/command/CommandManager.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,17 @@ object CommandManager : Configurable(LambdaConfig), Loadable {
116116
override fun load(): String {
117117
Reflections(
118118
ConfigurationBuilder()
119-
.setUrls(ClasspathHelper.forPackage("com.lambda.command.commands"))
119+
// Let's hope the maintainer of the library releases a new version soon
120+
// because this is horrible, it takes multiple SECONDS to scan the classpath,
121+
// and it's not even that big
122+
//
123+
// The culprit may be due to [ClasspathHelper.forClassLoader()] loading
124+
// the classes from the main thread while we are in a different thread.
125+
// If this is the case I wish the maintainer a very bad day.
126+
.addUrls(ClasspathHelper.forJavaClassPath())
127+
.addUrls(ClasspathHelper.forClassLoader())
128+
.filterInputsBy { it.contains("lambda") }
129+
.forPackage("com.lambda.module.modules")
120130
.setScanners(Scanners.SubTypes)
121131
).getSubTypesOf(LambdaCommand::class.java).forEach { commandClass ->
122132
commandClass.declaredFields.find {
@@ -131,4 +141,4 @@ object CommandManager : Configurable(LambdaConfig), Loadable {
131141

132142
return "Registered ${commands.size} commands"
133143
}
134-
}
144+
}

common/src/main/kotlin/com/lambda/module/ModuleRegistry.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import org.reflections.scanners.Scanners
77
import org.reflections.util.ClasspathHelper
88
import org.reflections.util.ConfigurationBuilder
99

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

3749
return "Registered ${modules.size} modules with ${modules.sumOf { it.settings.size }} settings"
3850
}
39-
}
51+
}

fabric/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ dependencies {
5151

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

5656
// Add mods to the mod jar
5757
// includeMod(...)

forge/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
val forgeVersion = property("forge_version").toString()
2-
val kotlinVersion = property("kotlin_version").toString()
32
val kotlinxCoroutinesVersion = property("kotlinx_coroutines_version").toString()
43
val architecturyVersion = property("architectury_version").toString()
54
val mixinExtrasVersion = property("mixinextras_version").toString()
@@ -58,10 +57,12 @@ fun DependencyHandlerScope.setupConfigurations() {
5857
includeMod.dependencies.forEach {
5958
implementation(it)
6059
forgeRuntimeLibrary(it)
60+
include(it)
6161
}
6262

6363
shadowInclude.dependencies.forEach {
6464
implementation(it)
65+
forgeRuntimeLibrary(it)
6566
shadowCommon(it)
6667
}
6768
}
@@ -75,13 +76,12 @@ dependencies {
7576

7677
// Add dependencies on the required Kotlin modules.
7778
includeLib("org.reflections:reflections:0.10.2")
78-
includeLib("org.javassist:javassist:3.30.0-GA")
79+
includeLib("org.javassist:javassist:3.28.0-GA")
7980

8081
// Add mods to the mod jar
8182
// includeMod(...)
8283

8384
// Add Kotlin
84-
shadowInclude("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion")
8585
shadowInclude("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion")
8686

8787
// MixinExtras

forge/src/main/resources/META-INF/mods.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
modLoader = "javafml"
22
loaderVersion = "[48,)"
33
license = "GNU General Public License v3.0"
4-
issueTrackerURL = "https://github.com/lambda-client/lambda/issues
4+
issueTrackerURL = "https://github.com/lambda-client/lambda/issues"
55

66
[[mods]]
77
modId = "lambda"
@@ -30,5 +30,5 @@ issueTrackerURL = "https://github.com/lambda-client/lambda/issues
3030
modId = "architectury"
3131
mandatory = true
3232
versionRange = "[11.0.7,)"
33-
ordering = "NONE"
33+
ordering = "AFTER"
3434
side = "CLIENT"

neoforge/build.gradle.kts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,19 @@ val shadowInclude: Configuration by configurations.creating
3131
fun DependencyHandlerScope.setupConfigurations() {
3232
includeLib.dependencies.forEach {
3333
implementation(it)
34+
forgeRuntimeLibrary(it)
3435
include(it)
3536
}
3637

3738
includeMod.dependencies.forEach {
3839
modImplementation(it)
40+
forgeRuntimeLibrary(it)
3941
include(it)
4042
}
4143

4244
shadowInclude.dependencies.forEach {
4345
implementation(it)
46+
forgeRuntimeLibrary(it)
4447
shadowCommon(it)
4548
}
4649
}
@@ -54,13 +57,15 @@ dependencies {
5457

5558
// Add dependencies on the required Kotlin modules.
5659
includeLib("org.reflections:reflections:0.10.2")
57-
includeLib("org.javassist:javassist:3.30.0-GA")
60+
includeLib("org.javassist:javassist:3.28.0-GA")
5861

5962
// Add mods to the mod jar
6063
// includeMod(...)
6164

6265
// Add Kotlin
63-
shadowInclude("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion")
66+
shadowInclude("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion") {
67+
exclude("org.jetbrains", "annotations")
68+
}
6469

6570
// Common (Do not touch)
6671
common(project(":common", configuration = "namedElements")) { isTransitive = false }
@@ -84,6 +89,11 @@ tasks {
8489
}
8590
}
8691

92+
shadowJar {
93+
relocate("kotlin", "com.lambda.kotlin")
94+
relocate("kotlinx", "com.lambda.kotlinx")
95+
}
96+
8797
remapJar {
8898
atAccessWideners.add("lambda.accesswidener")
8999
}

neoforge/src/main/resources/META-INF/mods.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
modLoader = "javafml"
22
loaderVersion = "[2,)"
33
license = "GNU General Public License v3.0"
4-
issueTrackerURL = "https://github.com/lambda-client/lambda/issues
4+
issueTrackerURL = "https://github.com/lambda-client/lambda/issues"
55
#updateJSONURL = "https://raw.githubusercontent.com/lambda-client/lambda/main/update.json"
66

77
[[mods]]
@@ -34,7 +34,7 @@ issueTrackerURL = "https://github.com/lambda-client/lambda/issues
3434
mandatory = true
3535
type = "required"
3636
versionRange = "[11.0.7,)"
37-
ordering = "NONE"
37+
ordering = "AFTER"
3838
side = "CLIENT"
3939

4040
[[mixins]]

0 commit comments

Comments
 (0)