aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/features/chat/QuickCommands.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/features/chat/QuickCommands.kt')
-rw-r--r--src/main/kotlin/features/chat/QuickCommands.kt55
1 files changed, 36 insertions, 19 deletions
diff --git a/src/main/kotlin/features/chat/QuickCommands.kt b/src/main/kotlin/features/chat/QuickCommands.kt
index 7963171..b857f8a 100644
--- a/src/main/kotlin/features/chat/QuickCommands.kt
+++ b/src/main/kotlin/features/chat/QuickCommands.kt
@@ -5,9 +5,9 @@ import com.mojang.brigadier.context.CommandContext
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
import net.fabricmc.fabric.impl.command.client.ClientCommandInternals
-import net.minecraft.command.CommandRegistryAccess
-import net.minecraft.network.packet.s2c.play.CommandTreeS2CPacket
-import net.minecraft.text.Text
+import net.minecraft.commands.CommandBuildContext
+import net.minecraft.network.protocol.game.ClientboundCommandsPacket
+import net.minecraft.network.chat.Component
import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.commands.DefaultSource
import moe.nea.firmament.commands.RestArgumentType
@@ -15,18 +15,19 @@ import moe.nea.firmament.commands.get
import moe.nea.firmament.commands.thenArgument
import moe.nea.firmament.commands.thenExecute
import moe.nea.firmament.events.CommandEvent
-import moe.nea.firmament.features.FirmamentFeature
-import moe.nea.firmament.gui.config.ManagedConfig
import moe.nea.firmament.gui.config.ManagedOption
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.SBData
+import moe.nea.firmament.util.data.Config
+import moe.nea.firmament.util.data.ManagedConfig
import moe.nea.firmament.util.grey
import moe.nea.firmament.util.tr
-object QuickCommands : FirmamentFeature {
- override val identifier: String
+object QuickCommands {
+ val identifier: String
get() = "quick-commands"
+ @Config
object TConfig : ManagedConfig("quick-commands", Category.CHAT) {
val enableJoin by toggle("join") { true }
val enableDh by toggle("dh") { true }
@@ -43,10 +44,14 @@ object QuickCommands : FirmamentFeature {
val dispatcher = CommandDispatcher<FabricClientCommandSource>()
ClientCommandInternals.setActiveDispatcher(dispatcher)
ClientCommandRegistrationCallback.EVENT.invoker()
- .register(dispatcher, CommandRegistryAccess.of(network.combinedDynamicRegistries,
- network.enabledFeatures))
+ .register(
+ dispatcher, CommandBuildContext.simple(
+ network.registryAccess,
+ network.enabledFeatures()
+ )
+ )
ClientCommandInternals.finalizeInit()
- network.onCommandTree(lastPacket)
+ network.handleCommands(lastPacket)
} catch (ex: Exception) {
ClientCommandInternals.setActiveDispatcher(fallback)
throw ex
@@ -64,7 +69,7 @@ object QuickCommands : FirmamentFeature {
return lf
}
- var lastReceivedTreePacket: CommandTreeS2CPacket? = null
+ var lastReceivedTreePacket: ClientboundCommandsPacket? = null
val kuudraLevelNames = listOf("NORMAL", "HOT", "BURNING", "FIERY", "INFERNAL")
val dungeonLevelNames = listOf("ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN")
@@ -98,16 +103,20 @@ object QuickCommands : FirmamentFeature {
}
val joinName = getNameForFloor(what.replace(" ", "").lowercase())
if (joinName == null) {
- source.sendFeedback(Text.stringifiedTranslatable("firmament.quick-commands.join.unknown", what))
+ source.sendFeedback(Component.translatableEscape("firmament.quick-commands.join.unknown", what))
} else {
- source.sendFeedback(Text.stringifiedTranslatable("firmament.quick-commands.join.success",
- joinName))
+ source.sendFeedback(
+ Component.translatableEscape(
+ "firmament.quick-commands.join.success",
+ joinName
+ )
+ )
MC.sendCommand("joininstance $joinName")
}
}
}
thenExecute {
- source.sendFeedback(Text.translatable("firmament.quick-commands.join.explain"))
+ source.sendFeedback(Component.translatable("firmament.quick-commands.join.explain"))
}
}
}
@@ -122,8 +131,12 @@ object QuickCommands : FirmamentFeature {
)
}
if (l !in kuudraLevelNames.indices) {
- source.sendFeedback(Text.stringifiedTranslatable("firmament.quick-commands.join.unknown-kuudra",
- kuudraLevel))
+ source.sendFeedback(
+ Component.translatableEscape(
+ "firmament.quick-commands.join.unknown-kuudra",
+ kuudraLevel
+ )
+ )
return null
}
return "KUUDRA_${kuudraLevelNames[l]}"
@@ -143,8 +156,12 @@ object QuickCommands : FirmamentFeature {
return "CATACOMBS_ENTRANCE"
}
if (l !in dungeonLevelNames.indices) {
- source.sendFeedback(Text.stringifiedTranslatable("firmament.quick-commands.join.unknown-catacombs",
- kuudraLevel))
+ source.sendFeedback(
+ Component.translatableEscape(
+ "firmament.quick-commands.join.unknown-catacombs",
+ kuudraLevel
+ )
+ )
return null
}
return "${if (masterLevel != null) "MASTER_" else ""}CATACOMBS_FLOOR_${dungeonLevelNames[l]}"