betterredfire

Create a client-side Fabric mod targeted for Minecraft version 1.21.11. Implement an "Automated Panic Button" system that sends the user's current coordinates to a registered list of players via explicit vanilla client-side chat commands.

Core Requirements:

  1. Data Storage & Management:

- Maintain a list of trusted player names. - Save this list to a local config file (e.g., trusted_players.json) in the config/ folder so it persists when Minecraft restarts.

  1. Client-Side Chat Commands:

- Register a client-side command /registerplayer <name> that adds a player's name to the trusted list and saves it. - Register a client-side command /removeplayer <name> that removes a player from the list and updates the file. - Register a client-side command /listplayers to print the current trusted list in the user's chat. - Use Fabric's ClientCommandRegistrationCallback to handle these strictly on the client side.

  1. Keybinding & Bypassed Panic Logic:

- Register a custom keybinding (default key: 'J' for Jumped). - When the user presses the 'J' key, fetch the client player's current X, Y, and Z integer coordinates. - For every player currently saved in the trusted list, the mod must automatically execute a client-side command using the explicit vanilla namespace to bypass server overrides. - The command format MUST be: minecraft:msg <TrustedPlayerName> HELP! I am getting jumped at X: <X>, Y: <Y>, Z: <Z>! - Crucial: Pass just "minecraft:msg <Name> <Message>" to client.player.networkHandler.sendChatCommand() (do not include the leading slash inside the sendChatCommand method argument, as Fabric appends it or handles it natively depending on the mapping).

Technical:

  1. Ensure build.gradle targets exactly 1.21.11. Use standard Fabric KeyBindingHelper and ClientTickEvents to handle the keypress smoothly.
Kodari AI
KodariSep 4 at 6:44 am 1
PanicButton
Client-side Fabric mod for Minecraft 1.21.11 that implements an automated panic button system. Maintains a persistent list of trusted players via JSON config file. Registers client-side chat commands to add, remove, and list trusted players. Binds a custom key (default J) that, when pressed, sends the player's current coordinates to all trusted players using the vanilla minecraft:msg command through the network handler, bypassing server overrides. Uses ClientCommandRegistrationCallback, KeyBindingHelper, and ClientTickEvents for seamless integration.
  1. Set up the Fabric 1.21.11 project and split client source sets.

  2. Add persistent trusted-player storage in config/trusted_players.json.

  3. Register client commands for add/remove/list operations.

  4. Add the J keybinding and panic message dispatch logic.

  1. Created a Fabric 1.21.11 client-only project with Java 21, Yarn mappings, Fabric Loader/API, and split client source sets.

  2. Added persistent trusted-player storage at config/trusted_players.json.

  3. Added client commands:

    • /registerplayer <name>

    • /removeplayer <name>

    • /listplayers

  4. Added the J keybinding and panic dispatch using: minecraft:msg <Name> HELP! I am getting jumped at X: <X>, Y: <Y>, Z: <Z>!

  5. Added English keybinding translations and Fabric metadata.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
7 325
src/client/java/com/kodari/automatedpanicbutton/AutomatedPanicButtonClient.java
package com.kodari.automatedpanicbutton;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.arguments.StringArgumentType;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class AutomatedPanicButtonClient implements ClientModInitializer {
    public static final String MOD_ID = "automatedpanicbutton";
    private static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
    private static final KeyBinding.Category PANIC_CATEGORY = KeyBinding.Category.create(
            Identifier.of(MOD_ID, "panic")
    );
    private static final KeyBinding PANIC_KEY = KeyBindingHelper.registerKeyBinding(
            new KeyBinding("key.automatedpanicbutton.panic", GLFW.GLFW_KEY_J, PANIC_CATEGORY)
    );

    @Override
    public void onInitializeClient() {
        TrustedPlayersConfig.load();
        registerCommands();
        ClientTickEvents.END_CLIENT_TICK.register(AutomatedPanicButtonClient::handleClientTick);
        LOGGER.info("Automated Panic Button initialized");
    }

    private static void registerCommands() {
        ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(
                ClientCommandManager.literal("registerplayer")
                        .then(ClientCommandManager.argument("name", StringArgumentType.word())
                                .executes(context -> {
                                    String name = StringArgumentType.getString(context, "name");
                                    if (TrustedPlayersConfig.addPlayer(name)) {
                                        context.getSource().sendFeedback(Text.literal("Registered trusted player: " + name));
                                    } else {
                                        context.getSource().sendFeedback(Text.literal("That player is already trusted: " + name));
                                    }
                                    return Command.SINGLE_SUCCESS;
                                }))
        ));

        ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(
                ClientCommandManager.literal("removeplayer")
                        .then(ClientCommandManager.argument("name", StringArgumentType.word())
                                .executes(context -> {
                                    String name = StringArgumentType.getString(context, "name");
                                    if (TrustedPlayersConfig.removePlayer(name)) {
                                        context.getSource().sendFeedback(Text.literal("Removed trusted player: " + name));
                                    } else {
                                        context.getSource().sendFeedback(Text.literal("That player is not trusted: " + name));
                                    }
                                    return Command.SINGLE_SUCCESS;
                                }))
        ));

        ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(
                ClientCommandManager.literal("listplayers")
                        .executes(context -> {
                            if (TrustedPlayersConfig.getPlayers().isEmpty()) {
                                context.getSource().sendFeedback(Text.literal("No trusted players are registered."));
                            } else {
                                context.getSource().sendFeedback(Text.literal(
                                        "Trusted players: " + String.join(", ", TrustedPlayersConfig.getPlayers())
                                ));
                            }
                            return Command.SINGLE_SUCCESS;
                        })
        ));
    }

    private static void handleClientTick(MinecraftClient client) {
        while (PANIC_KEY.wasPressed()) {
            sendPanicMessage(client);
        }
    }

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

        int x = (int) Math.floor(client.player.getX());
        int y = (int) Math.floor(client.player.getY());
        int z = (int) Math.floor(client.player.getZ());
        String message = "HELP! I am getting jumped at X: " + x + ", Y: " + y + ", Z: " + z + "!";

        for (String name : TrustedPlayersConfig.getPlayers()) {
            client.player.networkHandler.sendChatCommand("minecraft:msg " + name + " " + message);
        }
    }
}