Implement BalanceHUD, a Minecraft Java 1.21.11 Fabric client-side mod using Java 21. Use this project's existing Fabric template and current Fabric APIs/mappings for this version; inspect existing source/resources/build configuration before changing anything. Features: detect entering singleplayer or multiplayer worlds and show connection status in an on-screen HUD; on join prepare the exact command /pay .LeanderIQ_YT 1m; provide a HUD button to copy the prepared command to clipboard; allow manually sending the prepared command through Minecraft chat (do not auto-send any payment); configurable command cooldowns to prevent spam; detect readable chat/system messages with balances in formats such as 21m, 500m, 1B and show detected balances while preparing a matching payment command for manual review. Keep client-only (no server required), make cooldown/configuration understandable and persistent if the template supports config, and avoid sending payment commands automatically. Use Fabric client lifecycle, HUD rendering, keybinding/screen or other suitable Fabric APIs compatible with 1.21.11. Update metadata/resources as needed. Do not write tests. Do not attempt to build; workspace will compile after your task. Deliver complete mod source, with installation/use instructions in README if appropriate. Ensure code is real and compatible with existing template; report what changed and any caveats.

Kodari AI
KodariOct 26 at 6:37 pm 3
BalanceHUD
BalanceHUD is a Fabric client-side mod for Minecraft 1.21.11 that displays connection status in an on-screen HUD when entering singleplayer or multiplayer worlds. It prepares the exact command /pay .LeanderIQ_YT 1m on join, provides a HUD button to copy the command to clipboard, and allows manual sending through chat without auto-payment. The mod detects balance messages in formats like 21m, 500m, or 1B from chat/system messages and displays detected balances while preparing matching payment commands for review. Configurable cooldowns prevent command spam, with persistent settings for user customization.
  1. Verify the 1.21.11 client, HUD, chat-message, connection, and keybinding APIs.

  2. Create the client-only mod, persistent cooldown config, and HUD actions without automatic payment.

  3. Add project metadata and concise setup/use documentation.

Implemented BalanceHUD as a client-only Fabric 1.21.11 mod.

  • The HUD shows connection status, the prepared command, detected balance, cooldown, and clickable COPY COMMAND and SEND MANUALLY buttons. The C and V keybindings provide the same actions and can be remapped.

  • Joining prepares /pay .LeanderIQ_YT 1m. Readable, non-overlay game or system messages containing abbreviated amounts such as 21m, 500m, or 1B update the balance and prepare a matching command for review.

  • Payments are never sent automatically. Sending requires an explicit button click or keypress and is subject to the configured cooldown.

  • Added persistent cooldown settings at config/balancehud.properties (default 5 seconds; configurable from 0 to 3600), Fabric project metadata, and installation/use instructions in README.md.

The amount detector is heuristic and may match an abbreviated amount unrelated to a balance. The server must support /pay. I did not run a build or tests.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
README.md
settings.gradle
Code
9 342
src/client/java/com/kodari/balancehud/BalanceHudClient.java
package com.kodari.balancehud;

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.message.v1.ClientReceiveMessageEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class BalanceHudClient implements ClientModInitializer {
    private static final String MOD_ID = "balancehud";
    private static final String DEFAULT_COMMAND = "/pay .LeanderIQ_YT 1m";
    private static final int DEFAULT_COOLDOWN_SECONDS = 5;
    private static final int MAX_COOLDOWN_SECONDS = 3600;
    private static final Path CONFIG_PATH = Path.of("config", "balancehud.properties");
    private static final Pattern BALANCE_PATTERN = Pattern.compile("(?<![A-Za-z0-9_.])([0-9]+(?:[.,][0-9]+)?)\\s*([kKmMbB])\\b");
    private static final KeyBinding.Category CATEGORY = KeyBinding.Category.create(Identifier.of(MOD_ID, "main"));

    private static KeyBinding copyCommandKey;
    private static KeyBinding sendCommandKey;
    private static String preparedCommand = DEFAULT_COMMAND;
    private static String detectedBalance;
    private static String connectionStatus = "Not connected";
    private static int cooldownSeconds = DEFAULT_COOLDOWN_SECONDS;
    private static long cooldownUntilMillis;

    @Override
    public void onInitializeClient() {
        loadConfig();

        copyCommandKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
                "key.balancehud.copy_command", GLFW.GLFW_KEY_C, CATEGORY
        ));
        sendCommandKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
                "key.balancehud.send_command", GLFW.GLFW_KEY_V, CATEGORY
        ));

        ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> {
            preparedCommand = DEFAULT_COMMAND;
            detectedBalance = null;
            cooldownUntilMillis = 0L;
            connectionStatus = client.isInSingleplayer() ? "Singleplayer" : "Multiplayer";
        });
        ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> connectionStatus = "Not connected");

        ClientReceiveMessageEvents.GAME.register((message, overlay) -> {
            if (overlay) {
                return;
            }

            Matcher matcher = BALANCE_PATTERN.matcher(message.getString());
            if (matcher.find()) {
                detectedBalance = matcher.group(1) + matcher.group(2);
                preparedCommand = "/pay .LeanderIQ_YT " + detectedBalance;
            }
        });

        ClientTickEvents.END_CLIENT_TICK.register(client -> {
            if (client.world != null) {
                connectionStatus = client.isInSingleplayer() ? "Singleplayer" : "Multiplayer";
            }

            while (copyCommandKey.wasPressed()) {
                copyPreparedCommand(client);
            }
            while (sendCommandKey.wasPressed()) {
                sendPreparedCommand(client);
            }
        });

        HudElementRegistry.addLast(Identifier.of(MOD_ID, "overlay"), (context, tickCounter) -> {
            MinecraftClient client = MinecraftClient.getInstance();
            int x = 8;
            int y = 8;
            context.drawTextWithShadow(client.textRenderer, "BalanceHUD | " + connectionStatus, x, y, 0xFFFFFF);
            context.drawTextWithShadow(client.textRenderer, "Prepared: " + preparedCommand, x, y + 12, 0xFFD166);
            context.drawTextWithShadow(client.textRenderer, "[ COPY COMMAND ]", x, y + 26, 0x8FD3FF);
            context.drawTextWithShadow(client.textRenderer, "[ SEND MANUALLY ]", x + 104, y + 26, 0x8FD3FF);
            context.drawTextWithShadow(client.textRenderer,
                    "Detected balance: " + (detectedBalance == null ? "none" : detectedBalance), x, y + 40, 0xFFFFFF);

            long remainingMillis = Math.max(0L, cooldownUntilMillis - System.currentTimeMillis());
            String cooldownText = remainingMillis == 0L
                    ? "Send cooldown: ready (" + cooldownSeconds + "s configured)"
                    : "Send cooldown: " + ((remainingMillis + 999L) / 1000L) + "s remaining";
            context.drawTextWithShadow(client.textRenderer, cooldownText, x, y + 52, 0xFFFFFF);
        });
    }

    public static boolean handleHudClick(double x, double y) {
        if (y < 32.0 || y >= 46.0) {
            return false;
        }

        MinecraftClient client = MinecraftClient.getInstance();
        if (client.currentScreen != null) {
            return false;
        }
        if (x >= 8.0 && x < 98.0) {
            copyPreparedCommand(client);
            return true;
        }
        if (x >= 104.0 && x < 230.0) {
            sendPreparedCommand(client);
            return true;
        }
        return false;
    }

    private static void copyPreparedCommand(MinecraftClient client) {
        client.keyboard.setClipboard(preparedCommand);
        if (client.player != null) {
            client.player.sendMessage(Text.literal("BalanceHUD copied: " + preparedCommand), false);
        }
    }

    private static void sendPreparedCommand(MinecraftClient client) {
        if (client.player == null || client.getNetworkHandler() == null) {
            return;
        }

        long remainingMillis = cooldownUntilMillis - System.currentTimeMillis();
        if (remainingMillis > 0L) {
            client.player.sendMessage(Text.literal("BalanceHUD: wait " + ((remainingMillis + 999L) / 1000L)
                    + "s before sending another command."), false);
            return;
        }

        cooldownUntilMillis = System.currentTimeMillis() + cooldownSeconds * 1000L;
        client.getNetworkHandler().sendChatCommand(preparedCommand.substring(1));
    }

    private static void loadConfig() {
        Properties properties = new Properties();
        if (Files.exists(CONFIG_PATH)) {
            try (InputStream input = Files.newInputStream(CONFIG_PATH)) {
                properties.load(input);
            } catch (IOException ignored) {
                cooldownSeconds = DEFAULT_COOLDOWN_SECONDS;
            }
        }

        try {
            cooldownSeconds = Integer.parseInt(properties.getProperty("commandCooldownSeconds",
                    Integer.toString(DEFAULT_COOLDOWN_SECONDS)));
        } catch (NumberFormatException ignored) {
            cooldownSeconds = DEFAULT_COOLDOWN_SECONDS;
        }
        cooldownSeconds = Math.max(0, Math.min(MAX_COOLDOWN_SECONDS, cooldownSeconds));
        saveConfig();
    }

    private static void saveConfig() {
        Properties properties = new Properties();
        properties.setProperty("commandCooldownSeconds", Integer.toString(cooldownSeconds));
        try {
            Files.createDirectories(CONFIG_PATH.getParent());
            try (OutputStream output = Files.newOutputStream(CONFIG_PATH)) {
                properties.store(output, "BalanceHUD settings. Set commandCooldownSeconds from 0 to 3600.");
            }
        } catch (IOException ignored) {
        }
    }
}