betterredfire

Create a client-side Fabric mod targeted for Minecraft version 1.21.11. Implement an On-Screen HUD overlay that detects when another player enters the client's entity render distance, featuring an in-game UI configuration screen to move the radar placement.

Core Radar Mechanics:

  1. Scan for nearby player entities loaded on the client side using client.world.getPlayers() (exclude the client player themselves).
  2. For each detected player, format the text string cleanly on the HUD to show:

[Player Name] - [Distance]m ([Height Indicator]) [[Compass Direction]] - Distance: True 3D Euclidean distance. - Height Indicator: Display "(Above)" if Y is > 3 blocks higher, "(Below)" if > 3 blocks lower, otherwise "(Same Level)". - Compass Direction: Calculate the horizontal angle from the client player to the target player to determine the relative direction (North, South, East, West, North-East, etc.).

UI and Alignment Screen (Crucial):

  1. Create a custom Screen class (extending Minecraft's Screen class) that opens when the player presses a hotkey (default to key bind 'O').
  2. While this screen is open, display a box representing the Radar text area.
  3. Allow the user to toggle through screen positions or drag the text area to change its alignment (e.g., Top-Left, Top-Right, Bottom-Left, Bottom-Right, or custom X/Y coordinates).
  4. Save these X and Y position coordinates to a simple local config file (like a JSON or .properties file) inside the config/ folder so the position is remembered when closing and restarting Minecraft.
  5. Update the HudRenderCallback to draw the player radar text at these saved config coordinates.

Technical:

  1. Ensure build.gradle targets exactly 1.21.11. Use standard Fabric HudRenderCallback and KeyBindingHelper hooks so it compiles flawlessly without broken code or packet errors.
Kodari AI
KodariSep 4 at 5:11 am 1
PlayerRadarHUD
Client-side Fabric mod for Minecraft 1.21.11 that displays an on-screen radar HUD showing nearby players within render distance. The HUD lists each detected player with their name, true 3D Euclidean distance in meters, vertical height indicator (Above/Below/Same Level based on 3-block threshold), and compass direction calculated from horizontal angle. Features a configuration screen accessible via the 'O' hotkey that allows dragging or toggling the radar text area between preset positions (Top-Left, Top-Right, Bottom-Left, Bottom-Right) or custom X/Y coordinates. Position settings persist to a JSON config file in the config/ folder, and the HudRenderCallback draws the radar at saved coordinates on every frame.
  1. Create the Fabric 1.21.11 Gradle project and client-only metadata.

  2. Add cached JSON configuration persistence for HUD coordinates.

  3. Register the O keybind, modern HUD element, nearby-player formatting, and draggable layout screen.

  4. Add localized UI strings.

  • Created a complete Fabric 1.21.11 client mod project with Java 21, Yarn mappings, Fabric Loader 0.19.2, and Fabric API 0.141.4.

  • Added nearby-player HUD radar using loaded players, true 3D distance, height indicators, and compass directions.

  • Added the O keybind to open a draggable radar layout screen with preset positions and reset support.

  • Added persistent config/player-radar.json coordinate storage.

  • Used HudElementRegistry, the 1.21.11 replacement for the removed legacy HudRenderCallback.

  • Added English localization for the keybind, configuration screen, buttons, and empty radar state.

betterredfire

The compilation failed with this error:

code
Compilation failed with 14 error(s):

ERROR in src/main/java/client/java/com/kodari/playerradar/screen/RadarConfigScreen.java at line 62: cannot find symbol
        context.drawBorder(
               ^
  symbol: method drawBorder(int,int,int,int,int)
  location: variable context of type DrawContext

ERROR in src/main/java/client/java/com/kodari/playerradar/screen/RadarConfigScreen.java at line 109: method does not override or implement a method from a supertype
    @Override
    ^

ERROR in src/main/java/client/java/com/kodari/playerradar/screen/RadarConfigScreen.java at line 111: method mouseClicked in interface ParentElement cannot be applied to given types;
        if (super.mouseClicked(mouseX, mouseY, button)) {
                 ^

ERROR in src/main/java/client/java/com/kodari/playerradar/screen/RadarConfigScreen.java at line 124: method does not override or implement a method from a supertype
    @Override
    ^

ERROR in src/main/java/client/java/com/kodari/playerradar/screen/RadarConfigScreen.java at line 132: method mouseDragged in interface ParentElement cannot be applied to given types;
        return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
                    ^

ERROR in src/main/java/client/java/com/kodari/playerradar/screen/RadarConfigScreen.java at line 135: method does not override or implement a method from a supertype
    @Override
    ^

ERROR in src/main/java/client/java/com/kodari/playerradar/screen/RadarConfigScreen.java at line 140: method mouseReleased in interface ParentElement cannot be applied to given types;
        return super.mouseReleased(mouseX, mouseY, button);
                    ^

ERROR in   src/main/java/client/java/com/kodari/playerradar/screen/RadarConfigScreen.java at line 111: method mouseClicked in interface ParentElement cannot be applied to given types;
          if (super.mouseClicked(mouseX, mouseY, button)) {
                   ^

ERROR in   src/main/java/client/java/com/kodari/playerradar/screen/RadarConfigScreen.java at line 132: method mouseDragged in interface ParentElement cannot be applied to given types;
          return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
                      ^

ERROR in   src/main/java/client/java/com/kodari/playerradar/screen/RadarConfigScreen.java at line 140: method mouseReleased in interface ParentElement cannot be applied to given types;
          return super.mouseReleased(mouseX, mouseY, button);
                      ^

ERROR in   src/main/java/client/java/com/kodari/playerradar/screen/RadarConfigScreen.java at line 109: method does not override or implement a method from a supertype
      @Override
      ^

ERROR in   src/main/java/client/java/com/kodari/playerradar/screen/RadarConfigScreen.java at line 124: method does not override or implement a method from a supertype
      @Override
      ^

ERROR in   src/main/java/client/java/com/kodari/playerradar/screen/RadarConfigScreen.java at line 135: method does not override or implement a method from a supertype
      @Override
      ^

ERROR in   src/main/java/client/java/com/kodari/playerradar/screen/RadarConfigScreen.java at line 62: cannot find symbol
          context.drawBorder(
                 ^
  symbol: method drawBorder(int,int,int,int,int)
  location: variable context of type DrawContext


=== COMPILATION ERROR ANALYSIS ===

MISSING METHODS:
  - drawBorder(int,int,int,int,int)
ACTION: Check method names and signatures

FILES TO INVESTIGATE:
  - src/main/java/client/java/com/kodari/playerradar/screen/RadarConfigScreen.java
  -   src/main/java/client/java/com/kodari/playerradar/screen/RadarConfigScreen.java

Please fix this error by creating a new artifact with the corrected code.

Kodari AI
KodariSep 4 at 5:12 am 1

Fixed the Fabric 1.21.11 screen API incompatibilities in RadarConfigScreen:

  • Replaced removed DrawContext.drawBorder(...) with drawStrokedRectangle(...).

  • Updated mouse event handlers to use the new Click API:

    • mouseClicked(Click, boolean)

    • mouseDragged(Click, double, double)

    • mouseReleased(Click)

  • Updated superclass calls and coordinate/button access accordingly.

  • Removed the unused import.

Corrected artifact: src/client/java/com/kodari/playerradar/screen/RadarConfigScreen.java

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
10 518
src/client/java/com/kodari/playerradar/PlayerRadarClient.java
package com.kodari.playerradar;

import com.kodari.playerradar.config.RadarConfigManager;
import com.kodari.playerradar.hud.PlayerRadarHud;
import com.kodari.playerradar.screen.RadarConfigScreen;
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.hud.HudElementRegistry;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;

public final class PlayerRadarClient implements ClientModInitializer {
    public static final String MOD_ID = "player-radar";
    private static final KeyBinding.Category KEY_CATEGORY = KeyBinding.Category.create(
            Identifier.of(MOD_ID, "category")
    );
    private static KeyBinding openConfigKey;

    @Override
    public void onInitializeClient() {
        RadarConfigManager.load();

        openConfigKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
                "key.player-radar.open_config",
                InputUtil.Type.KEYSYM,
                GLFW.GLFW_KEY_O,
                KEY_CATEGORY
        ));

        HudElementRegistry.addLast(
                Identifier.of(MOD_ID, "radar"),
                PlayerRadarHud::render
        );

        ClientTickEvents.END_CLIENT_TICK.register(client -> {
            while (openConfigKey.wasPressed()) {
                if (client.currentScreen == null) {
                    client.setScreen(new RadarConfigScreen());
                }
            }
        });
    }
}