KotlinLangForge
为 Forge 和 Neoforge 提供 Kotlin 语言适配器
本模组添加了 Kotlin 的语言适配器,并提供了多个库。
开发者用法
要将你的语言适配器添加到模组中,请在你的
(neoforge.)mods.toml 中添加以下行。
neoforge.mods.toml
modLoader = "klf"
loaderVersion = "[1,)"
现在你可以像其他模组一样初始化你的模组。
只需确保你的 @Mod 类是一个对象(object)或具有公共构造函数(public constructor)的类。
构造函数可以接受以下四个参数(它们不应重复):
- IEventBus
- ModContainer
- KotlinModContainer
- Dist
如果你想在模组中实现这些库,请导入以下依赖项,
使其与语言提供程序版本、加载器以及 Kotlin 的版本(最新版)相匹配。
版本说明
“语言提供程序版本”是仅由 KotlinLangForge 提供的版本。
此格式不被 Forge 或 NeoForge 使用,仅作为在 Minecraft 不同版本迭代过程中区分不同语言提供程序实现的简单变量。
| Minecraft 版本 |
语言提供程序版本 |
支持的加载器 |
| 1.16.5 |
1.0 |
Forge |
| 1.17.1 - 1.20.4 |
2.0 |
Forge, NeoForge |
| 1.20.5 - 1.21.8 |
3.0 |
NeoForge |
| 1.21.9 - 26.x |
3.1 |
NeoForge |
build.gradle.kts
repositories {
maven("https://repo.nyon.dev/releases")
}
dependencies {
implementation("dev.nyon:KotlinLangForge:2.20.1-k2.4.21-$lpVersion+$loader")
}
对于 lp: <=3.0,你必须使用 modImplementation。
事件
若要使用自动事件监听器注册,必须在类/文件上添加 @EventBusSubscriber 注解。
Klf 将自动查找其参数中包含事件的所有方法,并确定使用哪个事件总线。
此外,你可以使用 @SubscribeEvent 注解方法来调整监听器的参数。
给 Forge 开发者的注意: 私有事件监听器在 Forge 上无法处理,并将导致崩溃!
Mod Bus: Mod Bus 可通过顶层声明 dev.nyon.klf.MOD_BUS 获取。
包含的库
- org.jetbrains.kotlin:kotlin-stdlib:2.4.21
- org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.4.21
- org.jetbrains.kotlin:kotlin-stdlib-jdk7:2.4.21
- org.jetbrains.kotlin:kotlin-reflect:2.4.21
- org.jetbrains.kotlinx:kotlinx-serialization-core:1.13.0
- org.jetbrains.kotlinx:kotlinx-serialization-json:1.13.0
- org.jetbrains.kotlinx:kotlinx-serialization-cbor:1.13.0
- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.11.0
- org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.11.0
- org.jetbrains.kotlinx:kotlinx-datetime:0.8.0-0.6.x-compat
- org.jetbrains.kotlinx:kotlinx-io-core:0.9.3
- org.jetbrains.kotlinx:kotlinx-io-bytestring:0.9.3
- org.jetbrains.kotlinx:atomicfu:0.33.0
其他
如果你需要关于我的任何模组的帮助,欢迎加入我的 Discord 服务器。
KotlinLangForge
Provides a Kotlin language adapter for Forge and Neoforge
This mod adds a language adapter for Kotlin and provides multiple libraries.
Developer usage
To add your language adapter to your mod, add the following lines to your
(neoforge.)mods.toml.
neoforge.mods.toml
modLoader = "klf"
loaderVersion = "[1,)"
Now you can init your mod like any other.
Just make sure your @Mod class is either an object or a class with a public constructor.
The constructor can take the following four arguments (they should never duplicate):
- IEventBus
- ModContainer
- KotlinModContainer
- Dist
If you want to implement the libraries in your mod, import the following dependency,
matching the language provider version, your loader and the (latest) version of Kotlin.
Versioning
The "language provider version" is a version only provided by KotlinLangForge.
This format is not used by Forge or NeoForge and only serves as a simple differentiation variable between the different
language provider implementations over the course of the versions of Minecraft.
| version of Minecraft |
language provider version |
supported loaders |
| 1.16.5 |
1.0 |
Forge |
| 1.17.1 - 1.20.4 |
2.0 |
Forge, NeoForge |
| 1.20.5 - 1.21.8 |
3.0 |
NeoForge |
| 1.21.9 - 26.x |
3.1 |
NeoForge |
build.gradle.kts
repositories {
maven("https://repo.nyon.dev/releases")
}
dependencies {
implementation("dev.nyon:KotlinLangForge:2.20.1-k2.4.21-$lpVersion+$loader")
}
For lp: <=3.0, you will have to use modImplementation.
Events
To use automatic event listener registration, the @EventBusSubscriber annotation has to be added on the class/file.
Klf then will automatically find all methods that have events in their parameters and will determine which event bus to
use.
Additionally, you can annotate a method with @SubscribeEvent to adjust the listener's parameters.
Note for Forge developers: Private event listeners cannot be processed on Forge and will result in a crash!
Mod Bus: The mod bus is available via the top-level declaration dev.nyon.klf.MOD_BUS.
Included Libraries
- org.jetbrains.kotlin:kotlin-stdlib:2.4.21
- org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.4.21
- org.jetbrains.kotlin:kotlin-stdlib-jdk7:2.4.21
- org.jetbrains.kotlin:kotlin-reflect:2.4.21
- org.jetbrains.kotlinx:kotlinx-serialization-core:1.13.0
- org.jetbrains.kotlinx:kotlinx-serialization-json:1.13.0
- org.jetbrains.kotlinx:kotlinx-serialization-cbor:1.13.0
- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.11.0
- org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.11.0
- org.jetbrains.kotlinx:kotlinx-datetime:0.8.0-0.6.x-compat
- org.jetbrains.kotlinx:kotlinx-io-core:0.9.3
- org.jetbrains.kotlinx:kotlinx-io-bytestring:0.9.3
- org.jetbrains.kotlinx:atomicfu:0.33.0
Other
If you need help with any of my mods, just join my discord server.
评论 0
登录后参与评分
还没有评论,来抢沙发吧