Files
src
build.gradle
gradle.properties
IMPLEMENTACAO_STATUS.txt
LEIA-ME-IMPORTANTE.txt
README.txt
settings.gradle
Code
20 2,649
src/main/java/nerdox/hub/NerdoxHubClient.java
package nerdox.hub;
import nerdox.hub.gui.HubScreen;
import nerdox.hub.module.Module;
import nerdox.hub.module.ModuleManager;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;
import java.util.HashMap;
import java.util.Map;
public class NerdoxHubClient implements ClientModInitializer {
public static KeyBinding openKey;
private static final Map<Module, Boolean> BIND_DOWN = new HashMap<>();
@Override
public void onInitializeClient() {
KeyBinding.Category category = KeyBinding.Category.create(Identifier.of("nerdoxhub", "main"));
openKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.nerdoxhub.open", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_LEFT_CONTROL, category));
HubConfig.load("default");
ClientTickEvents.END_CLIENT_TICK.register(client -> {
while (openKey.wasPressed()) {
if (client.currentScreen == null) client.setScreen(new HubScreen());
}
pollModuleBinds(client);
CombatFeatures.tick(client);
});
HudRenderCallback.EVENT.register(HudRenderer::render);
}
/** Aplica a tecla de menu salva na config ao KeyBinding. */
public static void applyMenuKey() {
if (openKey == null) return;
openKey.setBoundKey(InputUtil.Type.KEYSYM.createFromCode(HubConfig.menuKey));
KeyBinding.updateKeysByCode();
}
private static void pollModuleBinds(MinecraftClient client) {
if (client.currentScreen != null || client.getWindow() == null) return;
long handle = client.getWindow().getHandle();
for (Module m : ModuleManager.ALL) {
int key = m.bind.key;
if (key <= 0) continue;
boolean down = GLFW.glfwGetKey(handle, key) == GLFW.GLFW_PRESS;
boolean was = BIND_DOWN.getOrDefault(m, false);
if (down && !was) {
m.enabled = !m.enabled;
HudRenderer.toast(m.name, m.enabled);
}
BIND_DOWN.put(m, down);
}
}
}