FabricKeyBinding configured KeyCode getter (#245)

This commit is contained in:
Draylar 2019-06-13 10:19:10 +02:00 committed by Adrian Siekierka
parent c189dc5c11
commit 7dfef87c3a
4 changed files with 40 additions and 2 deletions

View file

@ -1,5 +1,5 @@
archivesBaseName = "fabric-keybindings-v0" archivesBaseName = "fabric-keybindings-v0"
version = getSubprojectVersion(project, "0.1.0") version = getSubprojectVersion(project, "0.1.1")
dependencies { dependencies {
compile project(path: ':fabric-api-base', configuration: 'dev') compile project(path: ':fabric-api-base', configuration: 'dev')

View file

@ -16,6 +16,7 @@
package net.fabricmc.fabric.api.client.keybinding; 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.options.KeyBinding;
import net.minecraft.client.util.InputUtil; import net.minecraft.client.util.InputUtil;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
@ -31,6 +32,14 @@ public class FabricKeyBinding extends KeyBinding {
super("key." + id.toString().replace(':', '.'), type, code, category); 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 { public static class Builder {
protected final FabricKeyBinding binding; protected final FabricKeyBinding binding;

View file

@ -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();
}

View file

@ -4,7 +4,8 @@
"compatibilityLevel": "JAVA_8", "compatibilityLevel": "JAVA_8",
"client": [ "client": [
"MixinGameOptions", "MixinGameOptions",
"MixinKeyBinding" "MixinKeyBinding",
"KeyCodeAccessor"
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1