feat: Add /dh command

This commit is contained in:
Linnea Gräf
2024-12-23 23:02:08 +01:00
parent 22bc3adbae
commit 656958937f
7 changed files with 167 additions and 84 deletions

View File

@@ -51,7 +51,7 @@ public class FirmKeybindsInVanillaControlsPatch {
var config = FirmamentKeyBindings.INSTANCE.getKeyBindings().get(binding);
if (config == null) return;
resetButton.active = false;
editButton.setMessage(Text.translatable("firmament.keybinding.external", config.value.format()));
editButton.setMessage(Text.translatable("firmament.keybinding.external", config.getValue().format()));
ci.cancel();
}

View File

@@ -0,0 +1,17 @@
package moe.nea.firmament.mixins;
import moe.nea.firmament.features.chat.QuickCommands;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.packet.s2c.play.CommandTreeS2CPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ClientPlayNetworkHandler.class)
public class SaveOriginalCommandTreePacket {
@Inject(method = "onCommandTree", at = @At(value = "RETURN"))
private void saveUnmodifiedCommandTree(CommandTreeS2CPacket packet, CallbackInfo ci) {
QuickCommands.INSTANCE.setLastReceivedTreePacket(packet);
}
}

View File

@@ -1,8 +1,12 @@
package moe.nea.firmament.features.chat
import com.mojang.brigadier.CommandDispatcher
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 moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.commands.DefaultSource
@@ -12,13 +16,44 @@ 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.grey
import moe.nea.firmament.util.tr
object QuickCommands : FirmamentFeature {
override val identifier: String
get() = "quick-commands"
object TConfig : ManagedConfig("quick-commands", Category.CHAT) {
val enableJoin by toggle("join") { true }
val enableDh by toggle("dh") { true }
override fun onChange(option: ManagedOption<*>) {
reloadCommands()
}
}
fun reloadCommands() {
val lastPacket = lastReceivedTreePacket ?: return
val network = MC.networkHandler ?: return
val fallback = ClientCommandInternals.getActiveDispatcher()
try {
val dispatcher = CommandDispatcher<FabricClientCommandSource>()
ClientCommandInternals.setActiveDispatcher(dispatcher)
ClientCommandRegistrationCallback.EVENT.invoker()
.register(dispatcher, CommandRegistryAccess.of(network.combinedDynamicRegistries,
network.enabledFeatures))
ClientCommandInternals.finalizeInit()
network.onCommandTree(lastPacket)
} catch (ex: Exception) {
ClientCommandInternals.setActiveDispatcher(fallback)
throw ex
}
}
fun removePartialPrefix(text: String, prefix: String): String? {
var lf: String? = null
for (i in 1..prefix.length) {
@@ -29,11 +64,30 @@ object QuickCommands : FirmamentFeature {
return lf
}
var lastReceivedTreePacket: CommandTreeS2CPacket? = null
val kuudraLevelNames = listOf("NORMAL", "HOT", "BURNING", "FIERY", "INFERNAL")
val dungeonLevelNames = listOf("ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN")
@Subscribe
fun onCommands(it: CommandEvent) {
fun registerDh(event: CommandEvent) {
if (!TConfig.enableDh) return
event.register("dh") {
thenExecute {
MC.sendCommand("warp dhub")
}
}
event.register("dn") {
thenExecute {
MC.sendChat(tr("firmament.quickwarp.deez-nutz", "Warping to... Deez Nuts!").grey())
MC.sendCommand("warp dhub")
}
}
}
@Subscribe
fun registerJoin(it: CommandEvent) {
if (!TConfig.enableJoin) return
it.register("join") {
thenArgument("what", RestArgumentType) { what ->
thenExecute {

View File

@@ -15,7 +15,6 @@ import org.lwjgl.glfw.GLFW
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonObject
import kotlin.enums.enumEntries
import kotlin.io.path.createDirectories
import kotlin.io.path.readText
import kotlin.io.path.writeText
@@ -135,7 +134,7 @@ abstract class ManagedConfig(
return StringIdentifiable.createCodec { x() }
}
// TODO: wait on https://youtrack.jetbrains.com/issue/KT-73434
// TODO: wait on https://youtrack.jetbrains.com/issue/KT-73434
// protected inline fun <reified E> choice(
// propertyName: String,
// noinline default: () -> E
@@ -148,6 +147,8 @@ abstract class ManagedConfig(
// default
// )
// }
open fun onChange(option: ManagedOption<*>) {
}
protected fun duration(
propertyName: String,

View File

@@ -6,7 +6,6 @@ import kotlinx.serialization.json.JsonObject
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
import net.minecraft.text.Text
import moe.nea.firmament.Firmament
import moe.nea.firmament.util.ErrorUtil
class ManagedOption<T : Any>(
@@ -28,7 +27,13 @@ class ManagedOption<T : Any>(
val descriptionTranslationKey = "firmament.config.${element.name}.${propertyName}.description"
val labelDescription: Text = Text.translatable(descriptionTranslationKey)
lateinit var value: T
private var actualValue: T? = null
var value: T
get() = actualValue ?: error("Lateinit variable not initialized")
set(value) {
actualValue = value
element.onChange(this)
}
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
this.value = value

View File

@@ -3,6 +3,7 @@ accessible class net/minecraft/client/render/RenderLayer$MultiPhase
accessible class net/minecraft/client/render/RenderLayer$MultiPhaseParameters
accessible class net/minecraft/client/font/TextRenderer$Drawer
accessible field net/minecraft/client/gui/hud/InGameHud SCOREBOARD_ENTRY_COMPARATOR Ljava/util/Comparator;
accessible field net/minecraft/client/network/ClientPlayNetworkHandler combinedDynamicRegistries Lnet/minecraft/registry/DynamicRegistryManager$Immutable;
accessible field net/minecraft/client/render/item/HeldItemRenderer itemRenderer Lnet/minecraft/client/render/item/ItemRenderer;
accessible field net/minecraft/client/render/item/ItemModels missingModelSupplier Ljava/util/function/Supplier;

View File

@@ -180,6 +180,11 @@
"firmament.config.pristine-profit.position.description": "Edit the pristine profit hud location.",
"firmament.config.pristine-profit.timeout": "Timeout (0 = disabled)",
"firmament.config.pristine-profit.timeout.description": "Track the profit you make from pristine gemstones while mining. Set to 0 seconds to disable the HUD.",
"firmament.config.quick-commands": "Quick Commands",
"firmament.config.quick-commands.dh": "Enable /dh",
"firmament.config.quick-commands.dh.description": "Warps you to the dungeon hub.",
"firmament.config.quick-commands.join": "Enable /join",
"firmament.config.quick-commands.join.description": "Join various types of instances like dungeons using short hands like /join f1, /join k1, /join m7",
"firmament.config.repo": "Firmament Repo Settings",
"firmament.config.repo.autoUpdate": "Auto Update",
"firmament.config.repo.autoUpdate.description": "Automatically download new items for the item list on every startup.",