Make chat events use fabric events

[no changelog]
This commit is contained in:
nea
2023-09-04 20:22:51 +02:00
parent ee5591684d
commit d202ef5439
16 changed files with 185 additions and 157 deletions

View File

@@ -12,6 +12,7 @@ import moe.nea.firmament.Firmament
import moe.nea.firmament.features.chat.ChatLinks
import moe.nea.firmament.features.debug.DebugView
import moe.nea.firmament.features.debug.DeveloperFeatures
import moe.nea.firmament.features.debug.MinorTrolling
import moe.nea.firmament.features.fixes.Fixes
import moe.nea.firmament.features.inventory.CraftingOverlay
import moe.nea.firmament.features.inventory.PriceData
@@ -41,6 +42,7 @@ object FeatureManager : DataHolder<FeatureManager.Config>(serializer(), "feature
fun autoload() {
synchronized(this) {
if (hasAutoloaded) return
loadFeature(MinorTrolling)
loadFeature(FairySouls)
// TODO: loadFeature(FishingWarning)
loadFeature(SlotLocking)

View File

@@ -26,7 +26,7 @@ import net.minecraft.text.Text
import net.minecraft.util.Formatting
import net.minecraft.util.Identifier
import moe.nea.firmament.Firmament
import moe.nea.firmament.events.ClientChatLineReceivedEvent
import moe.nea.firmament.events.ModifyChatEvent
import moe.nea.firmament.events.ScreenRenderPostEvent
import moe.nea.firmament.features.FirmamentFeature
import moe.nea.firmament.gui.config.ManagedConfig
@@ -98,9 +98,9 @@ object ChatLinks : FirmamentFeature {
@OptIn(ExperimentalCoroutinesApi::class)
override fun onLoad() {
ClientChatLineReceivedEvent.subscribe {
ModifyChatEvent.subscribe {
if (TConfig.enableLinks)
it.replaceWith = it.text.transformEachRecursively { child ->
it.replaceWith = it.replaceWith.transformEachRecursively { child ->
val text = child.string
if ("://" !in text) return@transformEachRecursively child
val s = Text.empty().setStyle(child.style)

View File

@@ -0,0 +1,31 @@
/*
* SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package moe.nea.firmament.features.debug
import moe.nea.firmament.events.ModifyChatEvent
import moe.nea.firmament.features.FirmamentFeature
import net.minecraft.text.Text
// In memorian Dulkir
object MinorTrolling : FirmamentFeature {
override val identifier: String
get() = "minor-trolling"
val trollers = listOf("nea89o", "lrg89")
val t = "From(?: \\[[^\\]]+])? ([^:]+): (.*)".toRegex()
override fun onLoad() {
ModifyChatEvent.subscribe {
val m = t.matchEntire(it.unformattedString) ?: return@subscribe
val (_, name, text) = m.groupValues
if (name !in trollers) return@subscribe
if (!text.startsWith("c:")) return@subscribe
it.replaceWith = Text.literal(text.substring(2).replace("&", "§"))
}
}
}

View File

@@ -17,7 +17,7 @@ import net.minecraft.client.render.VertexFormat
import net.minecraft.client.render.VertexFormats
import net.minecraft.text.Text
import net.minecraft.util.math.Vec3d
import moe.nea.firmament.events.ServerChatLineReceivedEvent
import moe.nea.firmament.events.AllowChatEvent
import moe.nea.firmament.events.SkyblockServerUpdateEvent
import moe.nea.firmament.events.WorldRenderLastEvent
import moe.nea.firmament.features.FirmamentFeature
@@ -125,7 +125,7 @@ object FairySouls : FirmamentFeature {
updateWorldSouls()
updateMissingSouls()
}
ServerChatLineReceivedEvent.subscribe {
AllowChatEvent.subscribe {
when (it.text.unformattedString) {
"You have already found that Fairy Soul!" -> {
markNearestSoul()