Skip to content

Commit 1c60020

Browse files
committed
Update to Minecraft 1.21.9
1 parent f16debc commit 1c60020

10 files changed

Lines changed: 45 additions & 48 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
![Code license (MIT)](https://img.shields.io/github/license/devs-immortal/bind-cmd)
44
![GitHub release (latest by date)](https://img.shields.io/github/v/release/devs-immortal/bind-cmd)
5-
![Minecraft 1.21.7](https://img.shields.io/badge/Minecraft-1.21.7-yellowgreen)
5+
![Minecraft 1.21.9](https://img.shields.io/badge/Minecraft-1.21.9-yellowgreen)
66

7-
The BindCommands mod allows players to bind Minecraft commands to specific keys on their keyboard, making it easier and faster to execute commands in the game. The mod is built using the [Fabric](https://fabricmc.net/) mod loader and is compatible with Minecraft versions from 1.16.5 up to 1.21.7.
7+
The BindCommands mod allows players to bind Minecraft commands to specific keys on their keyboard, making it easier and faster to execute commands in the game. The mod is built using the [Fabric](https://fabricmc.net/) mod loader and is compatible with Minecraft versions from 1.16.5 up to 1.21.9.
88

99
## Features
1010

@@ -14,7 +14,7 @@ The BindCommands mod allows players to bind Minecraft commands to specific keys
1414

1515
## Installation
1616

17-
1. Download and install [Fabric](https://fabricmc.net/use/installer/) for Minecraft 1.21.7.
17+
1. Download and install [Fabric](https://fabricmc.net/use/installer/) for Minecraft 1.21.9.
1818
2. Download BindCommands, [Mod Menu](https://github.com/TerraformersMC/ModMenu), and [Fabric Language Kotlin](https://github.com/FabricMC/fabric-language-kotlin) mods.
1919
3. Place the downloaded mod files in the "mods" folder located in your Minecraft game directory.
2020
4. Launch Minecraft with the Fabric mod loader and enjoy the mod!

gradle.properties

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ org.gradle.jvmargs=-Xmx4G
33

44
# Fabric Properties
55
# Check these on https://fabricmc.net/develop/
6-
minecraft_version=1.21.8
7-
yarn_mappings=1.21.8+build.1
6+
minecraft_version=1.21.9
7+
yarn_mappings=1.21.9+build.1
88
loader_version=0.17.2
99

1010
# Fabric API
11-
fabric_version=0.133.4+1.21.8
11+
fabric_version=0.134.0+1.21.9
1212
loom_version=1.11-SNAPSHOT
1313

1414
# Mod Properties
15-
mod_version=1.7.3
15+
mod_version=1.8.0
1616
maven_group=net.immortaldevs
1717
archives_base_name=fabric-bind-cmd
1818

1919
# Kotlin
2020
kotlin_version=2.2.20
2121
fabric_kotlin_version=1.13.6+kotlin.2.2.20
22-
modmenu_version=15.0.0
22+
modmenu_version=16.0.0-rc.1
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Wed Jul 02 13:34:00 UTC 2025
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

src/main/kotlin/net/immortaldevs/bindcmd/BindCmdClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private fun handleBinding(client: MinecraftClient, binding: CommandBinding) {
4747
if (binding.isUnknown) return
4848

4949
if (binding.isPressed && !binding.wasPressed) {
50-
val commands = Config.bindings.filter { it.key.translationKey == binding.key.translationKey }.map { it.command }
50+
val commands = Config.bindings.filter { it.translationKey == binding.translationKey }.map { it.command }
5151
for (command in commands) {
5252
val cmd = Command(command)
5353
when (cmd.type) {
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
11
package net.immortaldevs.bindcmd
22

3+
import net.minecraft.client.input.KeyInput
34
import net.minecraft.client.option.KeyBinding
45
import net.minecraft.client.util.InputUtil
6+
import net.minecraft.util.Identifier
57

6-
class CommandBinding(var command: String, var key: KeyBinding) {
8+
private val CATEGORY = KeyBinding.Category(Identifier.of("bindcmd", "category"))
79

8-
constructor(command: String) : this(command, KeyBinding("key.keyboard.unknown", -1, "key.categories.bindcmd"))
10+
class CommandBinding(var command: String, var key: KeyBinding) {
11+
constructor(command: String) : this(command, KeyBinding("key.keyboard.unknown", -1, CATEGORY))
912

1013
constructor(command: String, translationKey: String, source: BindSource = BindSource.CLIENT) : this(command) {
1114
this.command = command
1215
this.source = source
1316
val keyCode = InputUtil.fromTranslationKey(translationKey).code
1417
val type = if (translationKey.startsWith("key.mouse")) InputUtil.Type.MOUSE else InputUtil.Type.KEYSYM
15-
this.key = KeyBinding(translationKey, type, keyCode, "key.categories.bindcmd")
16-
}
17-
18-
constructor(command: String, key: Int) : this(command) {
19-
this.command = command
20-
setBoundKey(key, 0)
18+
this.key = KeyBinding(translationKey, type, keyCode, CATEGORY)
2119
}
2220

2321
var source: BindSource = BindSource.CLIENT
24-
val isUnknown: Boolean get() = key.translationKey.endsWith("unknown")
22+
val translationKey: String get() = key.boundKeyTranslationKey
23+
val isUnknown: Boolean get() = translationKey.endsWith("unknown")
2524
val isPressed: Boolean get() = key.isPressed
2625
var wasPressed: Boolean = false
2726

28-
fun setBoundKey(keyCode: Int, scanCode: Int) {
27+
fun setBoundKey(keyInput: KeyInput) {
2928
unbind()
30-
val key = InputUtil.fromKeyCode(if (keyCode == 256) -1 else keyCode, scanCode)
31-
this.key = KeyBinding(key.translationKey, key.code, "key.categories.bindcmd")
29+
val key = if (keyInput.isEscape) InputUtil.UNKNOWN_KEY else InputUtil.fromKeyCode(keyInput)
30+
this.key = KeyBinding(key.translationKey, key.code, CATEGORY)
3231
}
3332

3433
fun setBoundMouse(button: Int) {
3534
unbind()
3635
val key = InputUtil.Type.MOUSE.createFromCode(button)
37-
this.key = KeyBinding(key.translationKey, InputUtil.Type.MOUSE, key.code, "key.categories.bindcmd")
36+
this.key = KeyBinding(key.translationKey, InputUtil.Type.MOUSE, key.code, CATEGORY)
3837
}
3938

4039
fun unbind() {
41-
KeyBinding.KEYS_BY_ID.remove(this.key.translationKey)
40+
KeyBinding.KEYS_BY_ID.remove(translationKey)
4241
KeyBinding.updateKeysByCode()
4342
}
4443
}

src/main/kotlin/net/immortaldevs/bindcmd/config/BindingsListWidget.kt

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class BindingsListWidget(val parent: ModConfigScreen, client: MinecraftClient?)
7171
0,
7272
124,
7373
16,
74-
Text.of(binding.key.translationKey)
74+
binding.key.boundKeyLocalizedText
7575
)
7676

7777
init {
@@ -87,18 +87,13 @@ class BindingsListWidget(val parent: ModConfigScreen, client: MinecraftClient?)
8787

8888
override fun render(
8989
context: DrawContext?,
90-
index: Int,
91-
y: Int,
92-
x: Int,
93-
entryWidth: Int,
94-
entryHeight: Int,
9590
mouseX: Int,
9691
mouseY: Int,
9792
hovered: Boolean,
9893
tickDelta: Float
9994
) {
10095
val textRenderer: TextRenderer = this@BindingsListWidget.client.textRenderer
101-
val textWidth: Int = entryWidth - editButton.width - deleteButton.width - 3
96+
val textWidth: Int = width - editButton.width - deleteButton.width - 3
10297
val isClient: Boolean = binding.source == BindSource.CLIENT
10398
val tooltip = when (binding.source) {
10499
BindSource.SERVER -> serverBindingTooltip
@@ -119,36 +114,36 @@ class BindingsListWidget(val parent: ModConfigScreen, client: MinecraftClient?)
119114
}
120115
this.hovered = true
121116
} else {
122-
val yPosition = y + entryHeight / 2 - 2
117+
val yPosition = y + height / 2 - 2
123118
val text = cutString(binding.command, textRenderer, textWidth - 12)
124119
context?.drawTextWithShadow(textRenderer, text, x, yPosition, Colors.WHITE)
125120
this.hovered = false
126121
}
127122

128123
editButton.setTooltip(tooltip)
129124
editButton.active = isClient
130-
editButton.x = x + entryWidth - editButton.width - deleteButton.width - 2
125+
editButton.x = x + width - editButton.width - deleteButton.width - 2
131126
editButton.y = y
132127

133128
deleteButton.setTooltip(tooltip)
134129
deleteButton.active = isClient
135-
deleteButton.x = x + entryWidth - deleteButton.width
130+
deleteButton.x = x + width - deleteButton.width
136131
deleteButton.y = y
137132
deleteButton.render(context, mouseX, mouseY, tickDelta)
138133

139134
if (duplicate) {
140135
val j = editButton.x - 6
141-
context?.fill(j, y + 2, j + 3, y + entryHeight + 2, -65536)
136+
context?.fill(j, y + 2, j + 3, y + height + 2, -65536)
142137
}
143138

144139
editButton.render(context, mouseX, mouseY, tickDelta)
145140
}
146141

147-
override fun children(): List<Element?>? {
142+
override fun children(): List<Element?> {
148143
return listOf(editButton, deleteButton, inputField)
149144
}
150145

151-
override fun selectableChildren(): List<Selectable?>? {
146+
override fun selectableChildren(): List<Selectable?> {
152147
return listOf(editButton, deleteButton, inputField)
153148
}
154149

@@ -164,7 +159,7 @@ class BindingsListWidget(val parent: ModConfigScreen, client: MinecraftClient?)
164159
if (duplicate)
165160
mutableText.append(", ")
166161
duplicate = true
167-
mutableText.append(Text.translatable(keyBinding.translationKey))
162+
mutableText.append(keyBinding.boundKeyLocalizedText)
168163
}
169164
}
170165

src/main/kotlin/net/immortaldevs/bindcmd/config/Config.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Config {
6161
@JvmStatic
6262
private fun toTuples(data: List<CommandBinding>): List<Pair<String, String>> {
6363
return data.map { binding ->
64-
binding.key.translationKey to binding.command
64+
binding.translationKey to binding.command
6565
}
6666
}
6767

src/main/kotlin/net/immortaldevs/bindcmd/config/ConfigLoader.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ConfigLoader(private val runDirectory: File) {
2020
val stream = file.inputStream()
2121
val content = stream.readBytes().decodeToString()
2222
return decode(content)
23-
} catch (e: Exception) {
23+
} catch (_: Exception) {
2424
return null
2525
}
2626
}

src/main/kotlin/net/immortaldevs/bindcmd/config/ModConfigScreen.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package net.immortaldevs.bindcmd.config
33
import net.fabricmc.api.EnvType
44
import net.fabricmc.api.Environment
55
import net.immortaldevs.bindcmd.CommandBinding
6+
import net.minecraft.client.gui.Click
67
import net.minecraft.client.gui.screen.Screen
78
import net.minecraft.client.gui.screen.option.GameOptionsScreen
89
import net.minecraft.client.gui.widget.ButtonWidget
910
import net.minecraft.client.gui.widget.DirectionalLayoutWidget
1011
import net.minecraft.client.gui.widget.TextWidget
12+
import net.minecraft.client.input.KeyInput
1113
import net.minecraft.client.option.KeyBinding
1214
import net.minecraft.screen.ScreenTexts
1315
import net.minecraft.text.Text
@@ -57,31 +59,32 @@ class ModConfigScreen(parent: Screen?) : GameOptionsScreen(
5759
bindingsList?.position(this.width, this.layout)
5860
}
5961

60-
override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
62+
override fun mouseClicked(click: Click, doubled: Boolean): Boolean {
6163
return if (selectedKeyBinding != null) {
6264
Config.bindings.forEach { binding ->
6365
if (binding.key == selectedKeyBinding)
64-
binding.setBoundMouse(button)
66+
binding.setBoundMouse(click.button())
6567
}
6668
selectedKeyBinding = null
6769
bindingsList?.update()
6870
true
6971
} else {
70-
super.mouseClicked(mouseX, mouseY, button)
72+
super.mouseClicked(click, doubled)
7173
}
7274
}
7375

74-
override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
76+
override fun keyPressed(input: KeyInput): Boolean {
7577
return if (selectedKeyBinding != null) {
7678
Config.bindings.forEach { binding ->
77-
if (binding.key == selectedKeyBinding)
78-
binding.setBoundKey(keyCode, scanCode)
79+
if (binding.key == selectedKeyBinding) {
80+
binding.setBoundKey(input)
81+
}
7982
}
8083
selectedKeyBinding = null
8184
bindingsList?.update()
8285
true
8386
} else {
84-
super.keyPressed(keyCode, scanCode, modifiers)
87+
super.keyPressed(input)
8588
}
8689
}
8790

src/main/resources/fabric.mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"fabric-api": "*",
4242
"fabric-language-kotlin": "*",
4343
"fabricloader": ">=0.17.0",
44-
"minecraft": "1.21.8",
44+
"minecraft": "1.21.9",
4545
"modmenu": "*"
4646
}
4747
}

0 commit comments

Comments
 (0)