minecraft-mod/src/main/java/dev/c0de/minecraft/client/Module.java

48 lines
1.1 KiB
Java

package dev.c0de.minecraft.client;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
public abstract class Module {
protected KeyBinding key;
protected boolean state;
public void onTick(MinecraftClient client) {
}
public void onToggle(MinecraftClient client) {
}
public void registerKey(String translationKey, int glfw_key, String category) {
this.key = KeyBindingHelper.registerKeyBinding(new KeyBinding(
translationKey,
InputUtil.Type.KEYSYM,
glfw_key,
category
));
}
public void setState(boolean state) {
this.state = state;
}
public KeyBinding getKey() {
return this.key;
}
public void toggleKey() {
if (this.key != null) {
if (this.key.wasPressed()) {
this.setState(!this.isState());
}
}
}
public boolean isState() {
return this.state;
}
}