Skip to content

Commit 18abc18

Browse files
Backported the mod to 1.20.1. Mixin fix pending.
1 parent 40f31ce commit 18abc18

File tree

11 files changed

+159
-147
lines changed

11 files changed

+159
-147
lines changed

build.gradle.kts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
id("java-library")
33
id("maven-publish")
44
id("idea")
5-
id("net.neoforged.moddev") version "2.0.78"
5+
id("net.neoforged.moddev.legacyforge") version "2.0.91"
66
kotlin("jvm") version "2.1.0"
77
kotlin("plugin.serialization") version "2.1.0"
88
//id("io.ktor.plugin") version "3.1.1"
@@ -32,16 +32,17 @@ base {
3232
archivesName = mod_id
3333
}
3434

35-
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
36-
kotlin.jvmToolchain(21)
35+
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
36+
kotlin.jvmToolchain(17)
3737

38+
val minecraft_version: String by project
3839
val neo_version: String by project
3940
val parchment_mappings_version: String by project
4041
val parchment_minecraft_version: String by project
4142

42-
neoForge {
43+
legacyForge {
4344
// Specify the version of NeoForge to use.
44-
version = neo_version
45+
version = "$minecraft_version-$neo_version"
4546

4647
parchment {
4748
mappingsVersion = parchment_mappings_version
@@ -125,9 +126,20 @@ neoForge {
125126
// Include resources generated by data generators.
126127
sourceSets["main"].resources { srcDir("src/generated/resources") }
127128

129+
mixin {
130+
add(sourceSets.main.get(), "${mod_id}.refmap.json")
131+
config("${mod_id}.mixins.json")
132+
}
133+
134+
tasks.named<Jar>("jar") {
135+
manifest.attributes(
136+
mapOf("MixinConfigs" to "${mod_id}.refmap.json")
137+
)
138+
}
139+
128140
dependencies {
129141
fun externalImplementation(dependency: String, strictly: String, prefer: String) {
130-
jarJar(implementation(dependency) {
142+
jarJar(modImplementation(dependency) {
131143
version {
132144
// The version range your mod is actually compatible with.
133145
// Note that you may receive a *lower* version than your preferred if another
@@ -139,13 +151,11 @@ dependencies {
139151
"additionalRuntimeClasspath"("$dependency:$prefer")
140152
}
141153

154+
// mixin
155+
annotationProcessor("org.spongepowered:mixin:0.8.5:processor")
156+
142157
// kff
143-
implementation("thedarkcolour:kotlinforforge-neoforge:5.7.0:slim")
144-
"additionalRuntimeClasspath"("org.jetbrains.kotlin:kotlin-stdlib")
145-
"additionalRuntimeClasspath"("org.jetbrains.kotlin:kotlin-reflect")
146-
"additionalRuntimeClasspath"("org.jetbrains.kotlinx:kotlinx-coroutines-core")
147-
"additionalRuntimeClasspath"("org.jetbrains.kotlinx:kotlinx-serialization-core")
148-
"additionalRuntimeClasspath"("org.jetbrains.kotlinx:kotlinx-serialization-json")
158+
implementation("thedarkcolour:kotlinforforge:4.10.0")
149159

150160
// ktor
151161
externalImplementation("io.ktor:ktor-io", "[2.0, 4.0)", "2.3.13")
@@ -154,7 +164,7 @@ dependencies {
154164

155165
// chatimage
156166
compileOnly("io.github.kituin:ChatImageCode:0.12.1")
157-
compileOnly("io.github.kituin:ChatImage:1.4.6+1.21.0+neoforge")
167+
//compileOnly("io.github.kituin:ChatImage:1.4.7+1.20.1+neoforge") // no 1.20.1 version yet
158168

159169
// Example mod dependency with JEI
160170
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
@@ -178,7 +188,6 @@ dependencies {
178188
// http://www.gradle.org/docs/current/userguide/dependency_management.html
179189
}
180190

181-
val minecraft_version: String by project
182191
val minecraft_version_range: String by project
183192
val neo_version_range: String by project
184193
val loader_version_range: String by project
@@ -213,7 +222,7 @@ val generateModMetadata = tasks.register<ProcessResources>("generateModMetadata"
213222
// this works with both building through Gradle and the IDE.
214223
sourceSets["main"].resources.srcDir(generateModMetadata)
215224
// To avoid having to run "generateModMetadata" manually, make it run on every project reload
216-
neoForge.ideSyncTask(generateModMetadata)
225+
legacyForge.ideSyncTask(generateModMetadata)
217226

218227
// Example configuration to allow publishing using the maven-publish plugin
219228
publishing {

gradle.properties

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ org.gradle.configuration-cache=true
77
## Environment Properties
88
# You can find the latest versions here: https://projects.neoforged.net/neoforged/neoforge
99
# The Minecraft version must agree with the Neo version to get a valid artifact
10-
minecraft_version=1.21.1
10+
minecraft_version=1.20.1
1111
# The Minecraft version range can use any release version of Minecraft as bounds.
1212
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
1313
# as they do not follow standard versioning conventions.
14-
minecraft_version_range=[1.21.1,1.22)
14+
minecraft_version_range=[1.20.1,1.21)
1515
# The Neo version must agree with the Minecraft version to get a valid artifact
16-
neo_version=21.1.133
16+
neo_version=47.1.3
1717
# The Neo version range can use any version of Neo as bounds
18-
neo_version_range=[21,)
18+
neo_version_range=[47,)
1919
# The loader version range can only use the major version of FML as bounds
20-
loader_version_range=[5.3,)
21-
parchment_minecraft_version=1.21.1
22-
parchment_mappings_version=2024.11.17
20+
loader_version_range=[4.10,)
21+
parchment_minecraft_version=1.20.1
22+
parchment_mappings_version=2023.09.03
2323
## Mod Properties
2424
# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63}
2525
# Must match the String constant located in the main mod class annotated with @Mod.

src/main/kotlin/NoMathExpectation/chatExchange/neoForged/ChatExchange.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package NoMathExpectation.chatExchange.neoForged
22

3-
import net.neoforged.bus.api.SubscribeEvent
4-
import net.neoforged.fml.common.EventBusSubscriber
5-
import net.neoforged.fml.common.Mod
6-
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent
3+
import net.minecraftforge.eventbus.api.SubscribeEvent
4+
import net.minecraftforge.fml.common.Mod
5+
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent
76
import org.apache.logging.log4j.Level
87
import org.apache.logging.log4j.LogManager
98
import org.apache.logging.log4j.Logger
@@ -14,7 +13,7 @@ import org.apache.logging.log4j.Logger
1413
* An example for blocks is in the `blocks` package of this mod.
1514
*/
1615
@Mod(ChatExchange.ID)
17-
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
16+
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
1817
object ChatExchange {
1918
const val ID = "chatexchange"
2019

src/main/kotlin/NoMathExpectation/chatExchange/neoForged/ChatExchangeConfig.kt

Lines changed: 71 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,115 @@
11
package NoMathExpectation.chatExchange.neoForged
22

3-
import net.neoforged.api.distmarker.Dist
4-
import net.neoforged.bus.api.SubscribeEvent
5-
import net.neoforged.fml.common.EventBusSubscriber
6-
import net.neoforged.fml.config.ModConfig
7-
import net.neoforged.fml.event.config.ModConfigEvent
8-
import net.neoforged.neoforge.common.ModConfigSpec
9-
import thedarkcolour.kotlinforforge.neoforge.forge.LOADING_CONTEXT
10-
import thedarkcolour.kotlinforforge.neoforge.forge.runWhenOn
11-
12-
@EventBusSubscriber(
3+
import net.minecraftforge.api.distmarker.Dist
4+
import net.minecraftforge.common.ForgeConfigSpec
5+
import net.minecraftforge.eventbus.api.SubscribeEvent
6+
import net.minecraftforge.fml.common.Mod
7+
import net.minecraftforge.fml.config.ModConfig
8+
import net.minecraftforge.fml.event.config.ModConfigEvent
9+
import thedarkcolour.kotlinforforge.forge.LOADING_CONTEXT
10+
import thedarkcolour.kotlinforforge.forge.runWhenOn
11+
12+
@Mod.EventBusSubscriber(
1313
modid = ChatExchange.ID,
14-
bus = EventBusSubscriber.Bus.MOD
14+
bus = Mod.EventBusSubscriber.Bus.MOD
1515
)
1616
object ChatExchangeConfig {
17-
private val builder = ModConfigSpec.Builder()
17+
private val builder = ForgeConfigSpec.Builder()
1818

19-
val host: ModConfigSpec.ConfigValue<String> = builder.comment("The host to bind the exchange server to.")
19+
val host: ForgeConfigSpec.ConfigValue<String> = builder.comment("The host to bind the exchange server to.")
2020
.translation("modid.config.host")
2121
.worldRestart()
2222
.define("host", "0.0.0.0")
23-
val port: ModConfigSpec.IntValue = builder.comment("The port to bind the exchange server to.")
23+
val port: ForgeConfigSpec.IntValue = builder.comment("The port to bind the exchange server to.")
2424
.translation("modid.config.port")
2525
.worldRestart()
2626
.defineInRange("port", 9002, 0, 65535)
27-
val token: ModConfigSpec.ConfigValue<String> =
27+
val token: ForgeConfigSpec.ConfigValue<String> =
2828
builder.comment("The token to authenticate with the exchange server.", "Leave blank to disable authentication.")
2929
.translation("modid.config.token")
3030
.worldRestart()
3131
.define("token", "")
32-
val language: ModConfigSpec.ConfigValue<String> = builder.comment("The language the exchange server messages will be.", "Leave blank to use the language the game is using.")
32+
val language: ForgeConfigSpec.ConfigValue<String> = builder.comment(
33+
"The language the exchange server messages will be.",
34+
"Leave blank to use the language the game is using."
35+
)
3336
.translation("modid.config.language")
3437
.worldRestart()
3538
.define("language", "")
3639

37-
val mixinMode: ModConfigSpec.BooleanValue = builder.comment("Whether to use mixin instead of event to listen to server chats.", "If the exchange server isn't sending server chat, try turn this on.")
40+
val mixinMode: ForgeConfigSpec.BooleanValue = builder.comment(
41+
"Whether to use mixin instead of event to listen to server chats.",
42+
"If the exchange server isn't sending server chat, try turn this on."
43+
)
3844
.translation("modid.config.mixinMode")
3945
.define("mixinMode", false)
4046

41-
val ignoreBotRegex: ModConfigSpec.ConfigValue<String> = builder.comment("The regex to match and ignore the bot players.", "Leave blank to disable.")
42-
.translation("modid.config.ignoreBotRegex")
43-
.define("ignoreBotRegex", "") {
44-
kotlin.runCatching {
45-
val str = it as String
46-
if (str.isBlank()) {
47-
return@runCatching true
48-
}
49-
50-
it.toRegex()
51-
true
52-
}.getOrDefault(false)
53-
}
54-
val chat: ModConfigSpec.BooleanValue = builder.comment("Whether to broadcast player chatting.", "Players can also broadcast their message by prefixing @broadcast.")
47+
val ignoreBotRegex: ForgeConfigSpec.ConfigValue<String> =
48+
builder.comment("The regex to match and ignore the bot players.", "Leave blank to disable.")
49+
.translation("modid.config.ignoreBotRegex")
50+
.define("ignoreBotRegex", "") {
51+
kotlin.runCatching {
52+
val str = it as String
53+
if (str.isBlank()) {
54+
return@runCatching true
55+
}
56+
57+
it.toRegex()
58+
true
59+
}.getOrDefault(false)
60+
}
61+
val chat: ForgeConfigSpec.BooleanValue = builder.comment(
62+
"Whether to broadcast player chatting.",
63+
"Players can also broadcast their message by prefixing @broadcast."
64+
)
5565
.translation("modid.config.chat")
5666
.define("chat", true)
57-
val joinLeave: ModConfigSpec.BooleanValue = builder.comment("Whether to broadcast player joining and leaving.")
67+
val joinLeave: ForgeConfigSpec.BooleanValue = builder.comment("Whether to broadcast player joining and leaving.")
5868
.translation("modid.config.joinLeave")
5969
.define("joinLeave", true)
60-
val death: ModConfigSpec.BooleanValue = builder.comment("Whether to broadcast player deaths.")
70+
val death: ForgeConfigSpec.BooleanValue = builder.comment("Whether to broadcast player deaths.")
6171
.translation("modid.config.death")
6272
.define("death", true)
63-
val advancement: ModConfigSpec.BooleanValue = builder.comment("Whether to broadcast player advancements.")
73+
val advancement: ForgeConfigSpec.BooleanValue = builder.comment("Whether to broadcast player advancements.")
6474
.translation("modid.config.advancement")
6575
.define("advancement", true)
6676

67-
val broadcastTriggerPrefix: ModConfigSpec.ConfigValue<MutableList<out String>> = builder.comment("The prefix to recognize to trigger broadcast in chat message.")
68-
.translation("modid.config.broadcastTriggerPrefix")
69-
.defineListAllowEmpty(
70-
"broadcastTriggerPrefix",
71-
{ mutableListOf("@广播", "@bc", "@broadcast") },
72-
{ "@broadcast" },
73-
{ true }
74-
)
75-
val broadcastPrefix: ModConfigSpec.ConfigValue<String> = builder.comment("The prefix to prepend when displaying manually broadcast chat message.")
76-
.translation("modid.config.broadcastPrefix")
77-
.define("broadcastPrefix", "")
78-
val commandBroadcastFormat: ModConfigSpec.ConfigValue<String> = builder.comment("The message format when player broadcast message using the command.", "Will not prepend broadcast prefix.")
77+
val broadcastTriggerPrefix: ForgeConfigSpec.ConfigValue<MutableList<out String>> =
78+
builder.comment("The prefix to recognize to trigger broadcast in chat message.")
79+
.translation("modid.config.broadcastTriggerPrefix")
80+
.defineListAllowEmpty(
81+
"broadcastTriggerPrefix",
82+
{ mutableListOf("@广播", "@bc", "@broadcast") },
83+
{ true }
84+
)
85+
val broadcastPrefix: ForgeConfigSpec.ConfigValue<String> =
86+
builder.comment("The prefix to prepend when displaying manually broadcast chat message.")
87+
.translation("modid.config.broadcastPrefix")
88+
.define("broadcastPrefix", "")
89+
val commandBroadcastFormat: ForgeConfigSpec.ConfigValue<String> = builder.comment(
90+
"The message format when player broadcast message using the command.",
91+
"Will not prepend broadcast prefix."
92+
)
7993
.translation("modid.config.commandBroadcastFormat")
80-
.define("commandBroadcastFormat", "\"<%s> %s\"")
81-
val receiveMessageFormat: ModConfigSpec.ConfigValue<String> = builder.comment("The message format when receiving message from outside.")
82-
.translation("modid.config.receiveMessageFormat")
83-
.define("receiveMessageFormat", "\"<%s> %s\"")
94+
.define("commandBroadcastFormat", "\"<%s> %s\"") {
95+
(it as? String)?.parseJsonToComponent() != null
96+
}
97+
val receiveMessageFormat: ForgeConfigSpec.ConfigValue<String> =
98+
builder.comment("The message format when receiving message from outside.")
99+
.translation("modid.config.receiveMessageFormat")
100+
.define("receiveMessageFormat", "\"<%s> %s\"") {
101+
(it as? String)?.parseJsonToComponent() != null
102+
}
84103

85-
val spec: ModConfigSpec = builder.build()
104+
val spec: ForgeConfigSpec = builder.build()
86105

87106
private var registered = false
88107
internal fun register() {
89108
if (registered) {
90109
error("Config is already registered!")
91110
}
92111

93-
val modContainer = LOADING_CONTEXT.activeContainer
94-
modContainer.registerConfig(ModConfig.Type.COMMON, spec)
112+
LOADING_CONTEXT.registerConfig(ModConfig.Type.COMMON, spec)
95113
runWhenOn(Dist.CLIENT) {
96114
registerOnClient()
97115
}
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package NoMathExpectation.chatExchange.neoForged
22

3-
import net.neoforged.neoforge.client.gui.ConfigurationScreen
4-
import net.neoforged.neoforge.client.gui.IConfigScreenFactory
5-
import thedarkcolour.kotlinforforge.neoforge.forge.LOADING_CONTEXT
6-
73
internal fun ChatExchangeConfig.registerOnClient() {
8-
val modContainer = LOADING_CONTEXT.activeContainer
9-
val supplier = {
10-
IConfigScreenFactory { container, screen ->
11-
ConfigurationScreen(container, screen)
12-
}
13-
}
14-
modContainer.registerExtensionPoint(IConfigScreenFactory::class.java, supplier)
4+
// do nothing because no default config screen in this version
5+
// val modContainer = LOADING_CONTEXT.activeContainer
6+
// val supplier = {
7+
// ConfigScreenHandler.ConfigScreenFactory { container, screen ->
8+
// ConfigurationScreen(container, screen)
9+
// }
10+
// }
11+
// modContainer.registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory::class.java, supplier)
1512
}

src/main/kotlin/NoMathExpectation/chatExchange/neoForged/ChatExchangeData.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package NoMathExpectation.chatExchange.neoForged
22

3-
import net.minecraft.core.HolderLookup
43
import net.minecraft.nbt.CompoundTag
54
import net.minecraft.nbt.ListTag
65
import net.minecraft.nbt.StringTag
@@ -26,7 +25,7 @@ class ChatExchangeData : SavedData() {
2625
return player in ignoredPlayers
2726
}
2827

29-
override fun save(tag: CompoundTag, registries: HolderLookup.Provider): CompoundTag {
28+
override fun save(tag: CompoundTag): CompoundTag {
3029
val listTag = ListTag()
3130
ignoredPlayers.forEach {
3231
listTag += StringTag.valueOf(it.toString())
@@ -40,20 +39,19 @@ class ChatExchangeData : SavedData() {
4039

4140
const val IGNORED_PLAYERS_KEY = "IgnoredPlayers"
4241

43-
private fun load(tag: CompoundTag, lookupProvider: HolderLookup.Provider): ChatExchangeData {
42+
fun load(tag: CompoundTag): ChatExchangeData {
4443
val data = ChatExchangeData()
4544
tag.getList(IGNORED_PLAYERS_KEY, Tag.TAG_STRING.toInt()).forEach {
4645
data.ignoredPlayers += UUID.fromString(it.asString)
4746
}
4847
return data
4948
}
50-
51-
val factory = Factory(::ChatExchangeData, ::load)
5249
}
5350
}
5451

5552
val MinecraftServer.chatExchangeData: ChatExchangeData
5653
get() = overworld().dataStorage.computeIfAbsent(
57-
ChatExchangeData.factory,
54+
ChatExchangeData.Companion::load,
55+
::ChatExchangeData,
5856
ChatExchangeData.DATA_STORAGE_KEY,
5957
)

0 commit comments

Comments
 (0)