No chat to show

This project's files are all here to explore.

Files
src
build.gradle
BUILD.txt
gradle.properties
LICENSE
settings.gradle
Code
36 3,873
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 nerdox.hub.feature.Commands;
import nerdox.hub.feature.Features;
import nerdox.hub.feature.Friends;
import nerdox.hub.feature.Waypoints;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.message.v1.ClientSendMessageEvents;
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");
		Friends.load();
		Waypoints.load();
		ClientSendMessageEvents.ALLOW_CHAT.register(message -> !Commands.handle(message));

		ClientTickEvents.END_CLIENT_TICK.register(client -> {
			while (openKey.wasPressed()) {
				if (client.currentScreen == null) client.setScreen(new HubScreen());
			}
			pollModuleBinds(client);
			Features.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);
		}
	}
}