diff --git a/fabric-keybindings-v0/build.gradle b/fabric-keybindings-v0/build.gradle index a3bc26b45..7c240a7b7 100644 --- a/fabric-keybindings-v0/build.gradle +++ b/fabric-keybindings-v0/build.gradle @@ -1,5 +1,5 @@ archivesBaseName = "fabric-keybindings-v0" -version = getSubprojectVersion(project, "0.1.0") +version = getSubprojectVersion(project, "0.1.1") dependencies { compile project(path: ':fabric-api-base', configuration: 'dev') diff --git a/fabric-keybindings-v0/src/main/java/net/fabricmc/fabric/api/client/keybinding/FabricKeyBinding.java b/fabric-keybindings-v0/src/main/java/net/fabricmc/fabric/api/client/keybinding/FabricKeyBinding.java index eba789ee0..9c6d11940 100644 --- a/fabric-keybindings-v0/src/main/java/net/fabricmc/fabric/api/client/keybinding/FabricKeyBinding.java +++ b/fabric-keybindings-v0/src/main/java/net/fabricmc/fabric/api/client/keybinding/FabricKeyBinding.java @@ -16,6 +16,7 @@ package net.fabricmc.fabric.api.client.keybinding; +import net.fabricmc.fabric.mixin.client.keybinding.KeyCodeAccessor; import net.minecraft.client.options.KeyBinding; import net.minecraft.client.util.InputUtil; import net.minecraft.util.Identifier; @@ -31,6 +32,14 @@ public class FabricKeyBinding extends KeyBinding { super("key." + id.toString().replace(':', '.'), type, code, category); } + /** + * Returns the configured KeyCode assigned to the KeyBinding from the player's settings. + * @return configured KeyCode + */ + public InputUtil.KeyCode getBoundKey() { + return ((KeyCodeAccessor) this).getKeyCode(); + } + public static class Builder { protected final FabricKeyBinding binding; diff --git a/fabric-keybindings-v0/src/main/java/net/fabricmc/fabric/mixin/client/keybinding/KeyCodeAccessor.java b/fabric-keybindings-v0/src/main/java/net/fabricmc/fabric/mixin/client/keybinding/KeyCodeAccessor.java new file mode 100644 index 000000000..dd15460c2 --- /dev/null +++ b/fabric-keybindings-v0/src/main/java/net/fabricmc/fabric/mixin/client/keybinding/KeyCodeAccessor.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.fabricmc.fabric.mixin.client.keybinding; + +import net.minecraft.client.options.KeyBinding; +import net.minecraft.client.util.InputUtil; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(KeyBinding.class) +public interface KeyCodeAccessor { + @Accessor + InputUtil.KeyCode getKeyCode(); +} diff --git a/fabric-keybindings-v0/src/main/resources/fabric-keybindings-v0.mixins.json b/fabric-keybindings-v0/src/main/resources/fabric-keybindings-v0.mixins.json index 68f8fac8f..4c5632e3e 100644 --- a/fabric-keybindings-v0/src/main/resources/fabric-keybindings-v0.mixins.json +++ b/fabric-keybindings-v0/src/main/resources/fabric-keybindings-v0.mixins.json @@ -4,7 +4,8 @@ "compatibilityLevel": "JAVA_8", "client": [ "MixinGameOptions", - "MixinKeyBinding" + "MixinKeyBinding", + "KeyCodeAccessor" ], "injectors": { "defaultRequire": 1