Last active
December 11, 2022 22:21
-
-
Save kotx/26fcd98d0d2deae927b1f6ec7501380e to your computer and use it in GitHub Desktop.
Dumb Fabric keybind thing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you star this I'll make you unstar it.