Skip to content

Instantly share code, notes, and snippets.

@kotx
Last active December 11, 2022 22:21
Show Gist options
  • Save kotx/26fcd98d0d2deae927b1f6ec7501380e to your computer and use it in GitHub Desktop.
Save kotx/26fcd98d0d2deae927b1f6ec7501380e to your computer and use it in GitHub Desktop.
Dumb Fabric keybind thing.
package moe.whip.pilot.keys;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.options.KeyBinding;
@Environment(EnvType.CLIENT)
public class KeyBind extends KeyBindBase {
private KeyBinding keyBinding;
private boolean pressed;
public KeyBind(KeyBinding keyBinding) {
super(keyBinding);
}
public KeyBinding getKeyBinding() {
return keyBinding;
}
public void setKeyBinding(KeyBinding keyBinding) {
this.keyBinding = keyBinding;
}
public boolean isPressed() {
return getKeyBinding().isPressed();
}
public boolean wasPressed() { return pressed = !pressed && isPressed(); }
}
package moe.whip.pilot.keys;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.options.KeyBinding;
public abstract class KeyBindBase {
public abstract KeyBinding getKeyBinding();
public abstract void setKeyBinding(KeyBinding keyBinding);
public abstract boolean isPressed();
public abstract boolean wasPressed();
public KeyBindBase(KeyBinding keyBinding)
{
setKeyBinding(keyBinding);
KeyBindingHelper.registerKeyBinding(keyBinding);
}
}
package moe.whip.pilot.keys;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.options.KeyBinding;
@Environment(EnvType.CLIENT)
public class LazyKeyBind extends KeyBindBase {
private KeyBinding keyBinding;
private boolean pressed;
public LazyKeyBind(KeyBinding keyBinding) {
super(keyBinding);
}
public KeyBinding getKeyBinding() {
return keyBinding;
}
public void setKeyBinding(KeyBinding keyBinding) {
this.keyBinding = keyBinding;
}
public boolean isPressed() {
return getKeyBinding().isPressed();
}
public boolean wasPressed() {
if (isPressed()) {
pressed = true;
return false;
} else if (pressed) {
pressed = false;
return true;
} else {
return false;
}
}
}
@sschr15
Copy link

sschr15 commented Jul 26, 2020

@kotx and how will you do that?

@kotx
Copy link
Author

kotx commented Jul 26, 2020

@kotx and how will you do that?

>:(
I'll be mad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment