aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/dulkirfabric
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/com/dulkirfabric')
-rw-r--r--src/main/kotlin/com/dulkirfabric/Registrations.kt2
-rw-r--r--src/main/kotlin/com/dulkirfabric/commands/DynamicKeyCommand.kt48
-rw-r--r--src/main/kotlin/com/dulkirfabric/commands/RestArgumentType.kt12
-rw-r--r--src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt6
-rw-r--r--src/main/kotlin/com/dulkirfabric/features/KeyShortCutImpl.kt10
-rw-r--r--src/main/kotlin/com/dulkirfabric/features/NoReverseCam.kt4
6 files changed, 77 insertions, 5 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/Registrations.kt b/src/main/kotlin/com/dulkirfabric/Registrations.kt
index 31b1eb1..3122924 100644
--- a/src/main/kotlin/com/dulkirfabric/Registrations.kt
+++ b/src/main/kotlin/com/dulkirfabric/Registrations.kt
@@ -2,6 +2,7 @@ package com.dulkirfabric
import com.dulkirfabric.DulkirModFabric.EVENT_BUS
import com.dulkirfabric.commands.ConfigCommand
+import com.dulkirfabric.commands.DynamicKeyCommand
import com.dulkirfabric.commands.JoinDungeonCommands
import com.dulkirfabric.events.ChatReceivedEvent
import com.dulkirfabric.events.ClientTickEvent
@@ -35,6 +36,7 @@ object Registrations {
cre.register(JoinDungeonCommands.M5Command::register)
cre.register(JoinDungeonCommands.M6Command::register)
cre.register(JoinDungeonCommands.M7Command::register)
+ cre.register(DynamicKeyCommand::register)
}
fun registerEventListeners() {
diff --git a/src/main/kotlin/com/dulkirfabric/commands/DynamicKeyCommand.kt b/src/main/kotlin/com/dulkirfabric/commands/DynamicKeyCommand.kt
new file mode 100644
index 0000000..f253957
--- /dev/null
+++ b/src/main/kotlin/com/dulkirfabric/commands/DynamicKeyCommand.kt
@@ -0,0 +1,48 @@
+package com.dulkirfabric.commands
+
+import com.dulkirfabric.util.TextUtils
+import com.mojang.brigadier.CommandDispatcher
+import com.mojang.brigadier.arguments.StringArgumentType
+import com.mojang.brigadier.builder.LiteralArgumentBuilder
+import com.mojang.brigadier.builder.RequiredArgumentBuilder
+import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
+import net.minecraft.command.CommandRegistryAccess
+
+object DynamicKeyCommand {
+ var command = ""
+ fun register(dispatcher: CommandDispatcher<FabricClientCommandSource>, registryAccess: CommandRegistryAccess) {
+ dispatcher.register(
+ LiteralArgumentBuilder.literal<FabricClientCommandSource>("dk")
+ .executes { context ->
+ TextUtils.info("§6Usage: /dk set <command>")
+ TextUtils.info("§6For more information about this command, run /dk help")
+ return@executes 0
+ }
+ .then(
+ LiteralArgumentBuilder.literal<FabricClientCommandSource>("set")
+ .then(
+ RequiredArgumentBuilder.argument<FabricClientCommandSource, String>("command", RestArgumentType)
+ .executes { context ->
+ command = StringArgumentType.getString(context, "command")
+ command = command.removePrefix("/")
+ TextUtils.info("§6§lCommand Registered: §7$command")
+ return@executes 1
+ }
+ )
+ )
+ .then(
+ LiteralArgumentBuilder.literal<FabricClientCommandSource>("help")
+ .executes {
+ TextUtils.info("§6§lDynamic Keybind Info")
+ TextUtils.info("§7 - There's a keybind setting inside your Dulkir Config you can use in order" +
+ " to make a chat macro for a particular in game command. This only works for commands.", prefix = false)
+ TextUtils.info("§7 - Usage: /dk set <command args>", prefix = false)
+ TextUtils.info("§7 (i made this cuz I have a mouse button that i use for a bunch of different useful " +
+ "actions depending upon what I'm doing, so don't worry if this feature doesn't apply to you lol)", prefix = false)
+ return@executes 2
+ }
+ )
+ )
+ }
+
+} \ No newline at end of file
diff --git a/src/main/kotlin/com/dulkirfabric/commands/RestArgumentType.kt b/src/main/kotlin/com/dulkirfabric/commands/RestArgumentType.kt
new file mode 100644
index 0000000..a6f13ac
--- /dev/null
+++ b/src/main/kotlin/com/dulkirfabric/commands/RestArgumentType.kt
@@ -0,0 +1,12 @@
+package com.dulkirfabric.commands
+
+import com.mojang.brigadier.StringReader
+import com.mojang.brigadier.arguments.ArgumentType
+
+object RestArgumentType: ArgumentType<String> {
+ override fun parse(reader: StringReader): String {
+ val remaining = reader.remaining
+ reader.cursor += remaining.length
+ return remaining
+ }
+} \ No newline at end of file
diff --git a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt
index 9e3fbaf..16fa366 100644
--- a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt
+++ b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt
@@ -65,6 +65,9 @@ class DulkirConfig {
val shortcuts = builder.getOrCreateCategory(Text.literal("Shortcuts"))
shortcuts.addEntry(
+ entryBuilder.mkKeyField(Text.literal("Dynamic Key"), configOptions::dynamicKey)
+ )
+ shortcuts.addEntry(
ConfigHelper.mkConfigList(
Text.literal("Macros"),
configOptions::macrosList,
@@ -88,7 +91,8 @@ class DulkirConfig {
var invScaleBool: Boolean = false,
var inventoryScale: Int = 3,
var macrosList: List<Macro> = listOf(Macro(UNKNOWN_KEY, "")),
- var ignoreReverseThirdPerson: Boolean = false
+ var ignoreReverseThirdPerson: Boolean = false,
+ var dynamicKey: InputUtil.Key = UNKNOWN_KEY
)
@Serializable
diff --git a/src/main/kotlin/com/dulkirfabric/features/KeyShortCutImpl.kt b/src/main/kotlin/com/dulkirfabric/features/KeyShortCutImpl.kt
index c94c258..9d2d39f 100644
--- a/src/main/kotlin/com/dulkirfabric/features/KeyShortCutImpl.kt
+++ b/src/main/kotlin/com/dulkirfabric/features/KeyShortCutImpl.kt
@@ -6,10 +6,20 @@ import com.dulkirfabric.util.TextUtils
import meteordevelopment.orbit.EventHandler
object KeyShortCutImpl {
+ private var lastCommandHandle: Long = 0
+ private var prevCode: Int = 0;
+
@EventHandler
fun onKeyPress(event: WorldKeyPressEvent) {
DulkirConfig.configOptions.macrosList.forEach {
if (it.keyBinding.code == event.key) {
+ // Spam Prevention
+ if (event.key == prevCode && System.currentTimeMillis() - lastCommandHandle < 1000)
+ return
+
+ lastCommandHandle = System.currentTimeMillis()
+ prevCode = event.key
+
// This conditional allows for these shortcuts to work for commands or normal messages
if (it.command.startsWith("/"))
TextUtils.sendCommand(it.command.substring(1))
diff --git a/src/main/kotlin/com/dulkirfabric/features/NoReverseCam.kt b/src/main/kotlin/com/dulkirfabric/features/NoReverseCam.kt
deleted file mode 100644
index b8cb36d..0000000
--- a/src/main/kotlin/com/dulkirfabric/features/NoReverseCam.kt
+++ /dev/null
@@ -1,4 +0,0 @@
-package com.dulkirfabric.features
-
-class NoReverseCam {
-} \ No newline at end of file