Skip to content

Update to support EventBus7 #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: 5.x
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,14 @@ repositories {
mavenCentral()
maven("https://maven.neoforged.net/releases")
maven("https://maven.minecraftforge.net/")
maven("https://libraries.minecraft.net")
}

dependencies {

// fakecraft (fake class/field/method signatures used in place of the full Minecraft/Forge dependencies)
"fakecraftCompileOnly"(libs.joml)
"fakecraftCompileOnly"(libs.forge.core)
"fakecraftCompileOnly"(libs.forge.bus)
"fakecraftCompileOnly"(libs.night.config)

// kfflib/common
Expand All @@ -131,6 +132,8 @@ dependencies {

// kffmod/forge
"modForgeCompileOnly"(libs.log4j.core)
"modForgeCompileOnly"(sourceSets["langForge"].output)


sourceSets.forEach { sourceSet ->
val name = sourceSet.name
Expand All @@ -153,6 +156,8 @@ dependencies {
if (name.contains("lang")) {
dependencies.add(compileOnly, libs.asm)
dependencies.add(compileOnly, libs.log4j.core)
dependencies.add(compileOnly, libs.secure.jar)
dependencies.add(compileOnly, libs.forge.bus)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why all of these random Gradle options? If these changes are just for your setup, please remove them from the PR

Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ min_mc_version = 1.20.6
unsupported_mc_version = 1.22

# KOTLIN FOR FORGE VERSION
kff_version=5.9.0
kff_max_version=6.0.0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be 7.0.0, not 6.1.0

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed that

kff_version=6.0.0
kff_max_version=7.0.0
16 changes: 10 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
# https://github.com/JetBrains/kotlin
# https://github.com/Kotlin/kotlinx.coroutines
# https://github.com/Kotlin/kotlinx.serialization
kotlin = "2.1.21"
kotlin = "2.2.0"
coroutines = "1.10.2"
serialization = "1.8.1"

# Misc
neoforge = "21.6.11-beta"
neoforge = "21.7.20-beta"
neoforge-fml = "[3,5)"
neoforge-bus = "8.0.5"
neoforge-mergetool = "2.0.7"
forge = "1.21-51.0.8"
forge = "1.21.7-57.0.2"
forge-mergetool = "1.0"
forge-spi = "7.1.4"
forge-bus = "6.2.6"
unsafe = "0.9.2"
forge-spi = "7.1.5"
secureJar = "3.0.9"
forge-bus = "7.0-beta.10"
joml = "1.10.5"
log4j = "2.22.1"
asm = "9.5"
Expand Down Expand Up @@ -44,9 +46,11 @@ neoforge-mergetool = { module = "net.neoforged:mergetool", version.ref = "neofor
forge-fml = { module = "net.minecraftforge:javafmllanguage", version.ref = "forge" }
forge-bus = { module = "net.minecraftforge:eventbus", version.ref = "forge-bus" }
forge-loader = { module = "net.minecraftforge:fmlloader", version.ref = "forge" }
forge-unsafe = { module = "net.minecraftforge:unsafe", version.ref = "unsafe" }
forge-core = { module = "net.minecraftforge:fmlcore", version.ref = "forge" }
forge-mergetool = { module = "net.minecraftforge:mergetool-api", version.ref = "forge-mergetool" }
forge-spi = { module = "net.minecraftforge:forgespi", version.ref = "forge-spi" }
secure-jar = { module = "cpw.mods:securejarhandler", version.ref = "secureJar"}
joml = { module = "org.joml:joml", version.ref = "joml" }
asm = { module = "org.ow2.asm:asm", version.ref = "asm" }
log4j-core = { module = "org.apache.logging.log4j:log4j-core", version.ref = "log4j" }
Expand All @@ -56,7 +60,7 @@ night-config = { module = "com.electronwill.night-config:core", version.ref = "n
# Kotlin Reflect, Stdlib, Coroutines, Serialization JSON
kotlin = ["kotlin-reflect", "kotlin-stdlib", "kotlin-stdlib-jdk7", "kotlin-stdlib-jdk8", "kotlinx-coroutines-core", "kotlinx-coroutines-core-jvm", "kotlinx-coroutines-jdk8", "kotlinx-serialization-core", "kotlinx-serialization-json"]
neoforge = ["neoforge", "neoforge-bus", "neoforge-fml", "neoforge-mergetool"]
forge = ["forge-core", "forge-fml", "forge-loader", "forge-mergetool", "forge-spi", "forge-bus"]
forge = ["forge-core", "forge-fml", "forge-loader", "forge-mergetool", "forge-spi", "forge-bus", "forge-unsafe"]

[plugins]
ideaext = { id = "org.jetbrains.gradle.plugin.idea-ext", version.ref = "ideaext" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.minecraftforge.common;

import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.bus.BusGroup;

public class MinecraftForge {
public static final IEventBus EVENT_BUS = null;
public static final BusGroup EVENT_BUS = null;
}
51 changes: 51 additions & 0 deletions src/kfflang/forge/kotlin/thedarkcolour/common/KotlinMod.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package thedarkcolour.common

import net.minecraftforge.api.distmarker.Dist
import net.minecraftforge.eventbus.api.bus.BusGroup
import net.minecraftforge.fml.Bindings
import net.minecraftforge.fml.common.Mod
import thedarkcolour.kotlinforforge.KotlinModLoadingContext
import java.util.function.Supplier

/**
* This defines a Kotlin Mod Class
* Any class found with this annotation applied will be loaded as a Mod. The instance that is loaded will
* represent the mod to other Mods in the system. It will be sent various subclasses of [ModLifecycleEvent]
* at pre-defined times during the loading of the game.
* @author Chidoziealways
* @since 6.0.0
*/

@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS)
public annotation class KotlinMod(val value: String) {

public annotation class KotlinEventBusSubscriber(
val value: Array<Dist> = [Dist.CLIENT, Dist.DEDICATED_SERVER],
val modId: String = "",
val bus: KotlinBus = KotlinBus.BOTH
) {
}
}

public enum class KotlinBus(public val eventBusSupplier: Supplier<BusGroup?>) {
/**
* The main BusGroup that most game events are fired on.
*/
FORGE(Bindings.getForgeBus()),

/**
* The Mod-Specific event BusGroup, usually for mod lifecycle events.
* @see KotlinModLoadingContext.getKBusGroup()
*/
MOD({ KotlinModLoadingContext.get().getKBusGroup() }),

/**
* Both the [FORGE] and [MOD] buses. This is slower to register events in your class but
* allows you to listen to events from different BusGroup types without needing separate classes annotated
* with [thedarkcolour.common.KotlinMod.KotlinEventBusSubscriber].
*/
BOTH({null});

public fun bus(): Supplier<BusGroup?> = eventBusSupplier
}
Loading