Compare commits
2 Commits
ea798c9cd7
...
86bc75991a
Author | SHA1 | Date | |
---|---|---|---|
86bc75991a | |||
d651d41d8f |
@ -1,53 +0,0 @@
|
|||||||
package dev.c0de.minecraft.client;
|
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
public class KeybindManager {
|
|
||||||
private final HashMap<String, Boolean> states = new HashMap<>();
|
|
||||||
private final List<Module> modules;
|
|
||||||
|
|
||||||
public KeybindManager(List<Module> modules) {
|
|
||||||
this.modules = modules;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void tick(MinecraftClient client) {
|
|
||||||
// Execute the onTick function of each module
|
|
||||||
modules.forEach(module -> module.onTick(this, client));
|
|
||||||
|
|
||||||
// Toggle the module state with keybind
|
|
||||||
modules.stream().filter(module -> module.getKey() != null).forEach(module -> {
|
|
||||||
if (module.getKey().wasPressed()) {
|
|
||||||
final String name = module.getClass().getName();
|
|
||||||
final boolean newState = states.get(name);
|
|
||||||
|
|
||||||
c0deFoxModClient.LOGGER.info(name);
|
|
||||||
|
|
||||||
states.put(name, !states.getOrDefault(name, false));
|
|
||||||
|
|
||||||
module.setState(newState);
|
|
||||||
module.onToggle(this, client);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getState(Class<?> cls) {
|
|
||||||
return states.getOrDefault(cls.getName(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TreeMap<String, Boolean> getSortedStates() {
|
|
||||||
final TreeMap<String, Boolean> keyStates = new TreeMap<>();
|
|
||||||
|
|
||||||
states.forEach((key, value) -> {
|
|
||||||
final Optional<Module> foundModule = modules.stream().filter(module -> module.getClass().getName().equals(key)).findFirst();
|
|
||||||
|
|
||||||
foundModule.ifPresent(module -> keyStates.put(module.getKey().getTranslationKey(), value));
|
|
||||||
});
|
|
||||||
|
|
||||||
return keyStates;
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,18 +2,28 @@ package dev.c0de.minecraft.client;
|
|||||||
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.option.KeyBinding;
|
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 {
|
public abstract class Module {
|
||||||
|
|
||||||
protected KeyBinding key;
|
protected KeyBinding key;
|
||||||
protected boolean state;
|
protected boolean state;
|
||||||
|
|
||||||
public void onTick(KeybindManager manager, MinecraftClient client) {
|
public void onTick(MinecraftClient client) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onToggle(KeybindManager manager, 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) {
|
public void setState(boolean state) {
|
||||||
|
@ -12,17 +12,13 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import dev.c0de.minecraft.client.modules.Fullbright;
|
import dev.c0de.minecraft.client.modules.Fullbright;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
@Environment(EnvType.CLIENT)
|
||||||
public class c0deFoxModClient implements ClientModInitializer {
|
public class c0deFoxModClient implements ClientModInitializer {
|
||||||
public static final Logger LOGGER = LoggerFactory.getLogger("c0defox");
|
public static final Logger LOGGER = LoggerFactory.getLogger("c0defox");
|
||||||
|
|
||||||
private static c0deFoxModClient self;
|
private static c0deFoxModClient self;
|
||||||
private static KeybindManager keybindManager;
|
|
||||||
|
|
||||||
// Load in modules as independent parts of the mod
|
Module fullbright;
|
||||||
private static List<Module> modules;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitializeClient() {
|
public void onInitializeClient() {
|
||||||
@ -30,12 +26,7 @@ public class c0deFoxModClient implements ClientModInitializer {
|
|||||||
|
|
||||||
self = this;
|
self = this;
|
||||||
|
|
||||||
// Add new modules here
|
fullbright = new Fullbright();
|
||||||
modules = List.of(
|
|
||||||
new Fullbright()
|
|
||||||
);
|
|
||||||
|
|
||||||
keybindManager = new KeybindManager(modules);
|
|
||||||
|
|
||||||
LOGGER.info("Ready");
|
LOGGER.info("Ready");
|
||||||
}
|
}
|
||||||
@ -44,13 +35,9 @@ public class c0deFoxModClient implements ClientModInitializer {
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static KeybindManager getKeybindManager() {
|
|
||||||
return keybindManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called on every game tick
|
// Called on every game tick
|
||||||
public void tick(MinecraftClient client) {
|
public void tick(MinecraftClient client) {
|
||||||
keybindManager.tick(client);
|
this.fullbright.onTick(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,7 @@ package dev.c0de.minecraft.client.modules;
|
|||||||
import dev.c0de.minecraft.c0deFoxMod;
|
import dev.c0de.minecraft.c0deFoxMod;
|
||||||
import dev.c0de.minecraft.client.Module;
|
import dev.c0de.minecraft.client.Module;
|
||||||
import dev.c0de.minecraft.client.c0deFoxModClient;
|
import dev.c0de.minecraft.client.c0deFoxModClient;
|
||||||
import dev.c0de.minecraft.client.KeybindManager;
|
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.option.KeyBinding;
|
|
||||||
import net.minecraft.client.util.InputUtil;
|
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
@ -17,24 +12,27 @@ public class Fullbright extends Module {
|
|||||||
double DEFAULT = 1.0;
|
double DEFAULT = 1.0;
|
||||||
|
|
||||||
public void FullBright() {
|
public void FullBright() {
|
||||||
this.key = KeyBindingHelper.registerKeyBinding(new KeyBinding(
|
this.registerKey("key.c0defox.fullbright", GLFW.GLFW_KEY_B, "key.categories.c0defox");
|
||||||
"key.c0defox.fullbright",
|
|
||||||
InputUtil.Type.KEYSYM,
|
|
||||||
GLFW.GLFW_KEY_B,
|
|
||||||
"category.c0defox.default"
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTick(KeybindManager manager, MinecraftClient client) {
|
public void onTick(MinecraftClient client) {
|
||||||
update(client, DEFAULT);
|
if (key.wasPressed()) {
|
||||||
|
this.setState(!this.isState());
|
||||||
|
}
|
||||||
|
|
||||||
if (this.isState()) {
|
if (this.isState()) {
|
||||||
c0deFoxModClient.LOGGER.warn("Active State");
|
c0deFoxModClient.LOGGER.warn("Active State");
|
||||||
update(client, c0deFoxMod.config.getConfig().FULLBRIGHT_GAMMA);
|
update(client, c0deFoxMod.config.getConfig().FULLBRIGHT_GAMMA);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update(client, DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void update(MinecraftClient client, double value) {
|
private void update(MinecraftClient client, double value) {
|
||||||
|
c0deFoxModClient.LOGGER.warn(String.valueOf(value));
|
||||||
|
|
||||||
if (client == null) return;
|
if (client == null) return;
|
||||||
if (client.options.getGamma().getValue() == value) return;
|
if (client.options.getGamma().getValue() == value) return;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"category.c0defox.default": "c0de's mods",
|
"key.categories.c0defox": "c0de's mods",
|
||||||
"key.c0defox.fullbright": "Fullbright"
|
"key.c0defox.fullbright": "Fullbright"
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user