No chat to show

This project's files are all here to explore.

Files
src
build.gradle
manifest.kod
Code
27 1,378
src/client/java/com/mojoreplay/client/MojoReplayClient.java
package com.mojoreplay.client;

import com.mojoreplay.MojoReplay;
import com.mojoreplay.ReplayStatePayload;
import com.mojoreplay.client.gui.MojoReplayHud;
import com.mojoreplay.client.voice.VoiceGuidanceSystem;
import com.mojoreplay.config.MojoReplayConfig;
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.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.option.KeyBinding.Category;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;

public class MojoReplayClient implements ClientModInitializer {
    public static final Category REPLAY_CATEGORY = Category.create(
            Identifier.of(MojoReplay.MOD_ID, "replay_controls")
    );

    public static final KeyBinding TOGGLE_RECORDING = new KeyBinding(
            "key.mojoreplay.toggle_recording",
            GLFW.GLFW_KEY_UNKNOWN,
            REPLAY_CATEGORY
    );

    public static final KeyBinding OPEN_SETTINGS = new KeyBinding(
            "key.mojoreplay.open_settings",
            GLFW.GLFW_KEY_UNKNOWN,
            REPLAY_CATEGORY
    );

    public static final KeyBinding TOGGLE_HUD = new KeyBinding(
            "key.mojoreplay.toggle_hud",
            GLFW.GLFW_KEY_UNKNOWN,
            REPLAY_CATEGORY
    );

    @Override
    public void onInitializeClient() {
        // Load config
        MojoReplayConfig.load();

        // Register keybindings
        KeyBindingHelper.registerKeyBinding(TOGGLE_RECORDING);
        KeyBindingHelper.registerKeyBinding(OPEN_SETTINGS);
        KeyBindingHelper.registerKeyBinding(TOGGLE_HUD);

        // Register HUD overlay โ€” the main floating UI
        HudElementRegistry.addLast(
                Identifier.of(MojoReplay.MOD_ID, "replay_hud"),
                (context, tickCounter) -> MojoReplayHud.INSTANCE.render(context, tickCounter)
        );

        // Register network receiver for replay state updates from server
        ClientPlayNetworking.registerGlobalReceiver(
                ReplayStatePayload.ID,
                (payload, context) -> {
                    MojoReplayHud.INSTANCE.updateRecordingState(
                            payload.isRecording(),
                            payload.durationTicks(),
                            payload.keyframeCount(),
                            payload.statusMessage()
                    );
                    MojoReplay.LOGGER.info("Replay state: {}", payload.statusMessage());
                    // Voice guidance for state changes
                    VoiceGuidanceSystem.INSTANCE.announceStateChange(payload);
                }
        );

        // Client tick for keybinds and per-frame updates
        ClientTickEvents.END_CLIENT_TICK.register(client -> {
            while (TOGGLE_RECORDING.wasPressed()) {
                if (client.player != null) {
                    MojoReplayHud.INSTANCE.toggleRecording();
                }
            }
            while (OPEN_SETTINGS.wasPressed()) {
                client.setScreen(MojoReplayConfig.createScreen(client.currentScreen));
            }
            while (TOGGLE_HUD.wasPressed()) {
                var cfg = MojoReplayConfig.get();
                cfg.showHud = !cfg.showHud;
                MojoReplayConfig.save();
            }
        });

        MojoReplay.LOGGER.info("MojoReplay Client initialized");
    }
}