feat: added QuickModule with a toggle keybind
awful name but eeehh
This commit is contained in:
parent
867a5f5f62
commit
5e0ec6d4aa
1 changed files with 61 additions and 0 deletions
61
src/main/java/co/fantabos/bscv/module/QuickModule.java
Normal file
61
src/main/java/co/fantabos/bscv/module/QuickModule.java
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
package co.fantabos.bscv.module;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
|
||||||
|
import net.minecraft.client.settings.KeyBinding;
|
||||||
|
import net.minecraft.command.CommandSource;
|
||||||
|
import net.minecraftforge.client.event.InputEvent;
|
||||||
|
import net.minecraftforge.common.ForgeConfigSpec;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||||
|
import co.fantabos.bscv.BoSCoVicino;
|
||||||
|
|
||||||
|
// TODO rename
|
||||||
|
public class QuickModule extends Module {
|
||||||
|
|
||||||
|
private class ToggleHook {
|
||||||
|
private final KeyBinding key;
|
||||||
|
private final Module mod;
|
||||||
|
protected ToggleHook(KeyBinding key, Module mod) {
|
||||||
|
this.key = key;
|
||||||
|
this.mod = mod;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onKeyPress(InputEvent.KeyInputEvent event) {
|
||||||
|
if (this.key.isDown()) {
|
||||||
|
this.mod.toggle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onKeyPress(InputEvent.MouseInputEvent event) {
|
||||||
|
if (this.key.isDown()) {
|
||||||
|
this.mod.toggle();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final KeyBinding keybind;
|
||||||
|
|
||||||
|
public QuickModule(String name, Group group, int default_key, ForgeConfigSpec.Builder builder, CommandDispatcher<CommandSource> dispatcher) {
|
||||||
|
super(name, group, builder, dispatcher);
|
||||||
|
|
||||||
|
this.keybind = new KeyBinding(key_name(name), default_key, key_category());
|
||||||
|
ClientRegistry.registerKeyBinding(this.keybind);
|
||||||
|
|
||||||
|
// register a separate subclass on the hook, so that it's always listening
|
||||||
|
MinecraftForge.EVENT_BUS.register(new ToggleHook(this.keybind, this));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String key_name(String name) {
|
||||||
|
return String.format("key.%s.%s", BoSCoVicino.MOD_ID, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String key_category() {
|
||||||
|
return String.format("key.category.%s", BoSCoVicino.MOD_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue