itsadityax

make a mineraft 1.21.11 fabric java mod that locates the nearest player and show direction towards it in action bar by arrow and if that player leaves the game or goesto another dimenstion then that arrow shows its last location in action bar and a key that we cna se in keybind to open its gui and inside its gui there are 2 button first to to set a button to toggle it and 2 butthon to change the player to locate to another nad also show the distance in blockt to that player

Kodari AI
KodariNov 8 at 10:32 am 4
PlayerTrackerMod
A Minecraft Fabric mod for 1.21.11 that tracks the nearest player and displays a directional arrow in the action bar pointing toward them, along with distance in blocks. If the target player leaves the game or changes dimension, the arrow shows their last known location. A configurable keybind opens a GUI with two buttons: one to toggle tracking on/off, and another to switch the tracked player to a different target.
  1. Track player locations and preserve the last known position across disconnects and dimension changes.

  2. Add an action-bar direction and distance, plus keybinds and a GUI to toggle tracking and choose a player.

Created Player Locator for Fabric 1.21.11.

  • Press P to open the GUI; use it to change targets or open controls and bind the toggle key.

  • The action bar shows direction and distance, retaining the last observed location in your dimension when a target leaves or changes dimensions.

  • Multiplayer servers also need the mod installed; it shares online players’ coordinates with locator clients. Last locations are kept for the current connection.

itsadityax

make that it works with it being istalled in server

Kodari AI
KodariNov 8 at 10:36 am 1

It already works on a Fabric 1.21.11 server when the mod and its dependencies are installed on both the server and each tracking player’s client.

Do you want it to work with only the server running the mod? That’s possible for the action bar, but vanilla clients can’t have the custom keybind or GUI.

itsadityax

without being installed in the server only client side

Kodari AI
KodariNov 8 at 10:37 am 1

I’ll switch tracking to client-visible players, keeping their last observed positions when they disappear from view. This won’t require a server mod, but it can’t locate players the server hasn’t sent to your client.

Player Locator is now client-side only; the server doesn’t need the mod.

It can locate players only while the server sends them to your client. When one leaves view, the arrow shows their last observed location—not necessarily where they went offline or changed dimensions.

itsadityax

maek it that it also locate player out of render distance

Kodari AI
KodariNov 8 at 12:16 pm 1

A client-only mod can’t reliably locate players outside render distance: the server normally doesn’t send their positions to your client.

To track them beyond that range, the server would need to install a companion mod or plugin that shares their coordinates. The client can still point to a player’s last observed location without server support.

itsadityax

no not in server anything else

Kodari AI
KodariNov 8 at 12:17 pm 1

Without server support, the client can only use the player’s last observed location. Their current position outside the range sent by the server isn’t available to the mod.

itsadityax

maek it possible

Kodari AI
KodariNov 8 at 12:17 pm 1

I can’t make the client know coordinates the server doesn’t send. Without anything installed on the server, the best available option is the last observed location already shown by the mod.

itsadityax

like locator bar that allow to see player direction

Kodari AI
KodariNov 8 at 12:22 pm 2

Vanilla’s locator bar gives the client waypoint data beyond render distance when the server enables it. I’ll use that data for the arrow and show approximate distance when available.

The locator now uses vanilla locator-bar waypoints to track players beyond render distance, without a server-side mod.

Distance is approximate when available. This works only when the server sends locator waypoints; otherwise, the mod falls back to the last observed location.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
manifest.kod
settings.gradle
Code
8 290
src/client/java/com/kodari/playerlocator/client/PlayerLocatorClient.java
package com.kodari.playerlocator.client;

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.ClientPlayConnectionEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.world.waypoint.TrackedWaypoint;
import org.lwjgl.glfw.GLFW;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public class PlayerLocatorClient implements ClientModInitializer {
    private static final Map<UUID, Target> targets = new HashMap<>();
    private static UUID selected;
    private static boolean enabled = true;
    private static int ticks;
    private static KeyBinding menuKey;
    private static KeyBinding toggleKey;

    private record Position(String dimension, double x, double y, double z) {}
    private static class Target {
        String name;
        boolean online;
        Position current;
        TrackedWaypoint waypoint;
        final Map<String, Position> last = new HashMap<>();
    }

    @Override
    public void onInitializeClient() {
        KeyBinding.Category category = KeyBinding.Category.create(Identifier.of("playerlocator", "controls"));
        menuKey = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.playerlocator.menu", GLFW.GLFW_KEY_P, category));
        toggleKey = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.playerlocator.toggle", GLFW.GLFW_KEY_UNKNOWN, category));
        ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> {
            targets.clear();
            selected = null;
        });
        ClientTickEvents.END_CLIENT_TICK.register(client -> {
            while (menuKey.wasPressed()) client.setScreen(new LocatorScreen());
            while (toggleKey.wasPressed()) {
                enabled = !enabled;
                if (client.player != null) client.player.sendMessage(Text.literal("Player locator " + (enabled ? "enabled" : "disabled")), true);
            }
            if (client.player != null && client.world != null) {
                observePlayers(client);
                if (enabled && ++ticks % 10 == 0) updateActionBar(client);
            }
        });
    }

    private static void observePlayers(MinecraftClient client) {
        targets.values().forEach(target -> {
            target.online = false;
            target.waypoint = null;
        });
        String dimension = client.world.getRegistryKey().getValue().toString();
        for (var player : client.world.getPlayers()) {
            if (player.getUuid().equals(client.player.getUuid())) continue;
            UUID id = player.getUuid();
            Position position = new Position(dimension, player.getX(), player.getY(), player.getZ());
            Target target = targets.computeIfAbsent(id, ignored -> new Target());
            target.name = player.getName().getString();
            target.current = position;
            target.last.put(position.dimension(), position);
            target.online = true;
        }
        client.getNetworkHandler().getWaypointHandler().forEachWaypoint(client.player, waypoint ->
            waypoint.getSource().left().ifPresent(id -> {
                if (id.equals(client.player.getUuid())) return;
                var entry = client.getNetworkHandler().getPlayerListEntry(id);
                Target target = targets.get(id);
                if (target == null && entry == null) return;
                if (target == null) {
                    target = new Target();
                    targets.put(id, target);
                }
                if (entry != null) target.name = entry.getProfile().name();
                target.waypoint = waypoint;
                target.online = true;
            })
        );
    }

    static boolean isEnabled() { return enabled; }
    static void toggle() { enabled = !enabled; }

    static String targetName() {
        Target target = targets.get(selected);
        return target == null ? "Nearest" : target.name;
    }

    static void nextTarget() {
        MinecraftClient client = MinecraftClient.getInstance();
        if (client.player == null) return;
        List<UUID> ids = new ArrayList<>(targets.keySet());
        ids.remove(client.player.getUuid());
        ids.sort(Comparator.comparing(id -> targets.get(id).name, String.CASE_INSENSITIVE_ORDER));
        int index = ids.indexOf(selected);
        selected = index + 1 >= ids.size() ? null : ids.get(index + 1);
    }

    private static void updateActionBar(MinecraftClient client) {
        String dimension = client.player.getEntityWorld().getRegistryKey().getValue().toString();
        UUID chosen = selected;
        if (chosen == null) {
            double best = Double.POSITIVE_INFINITY;
            for (var entry : targets.entrySet()) {
                Target candidate = entry.getValue();
                if (entry.getKey().equals(client.player.getUuid()) || !candidate.online) continue;
                double distance;
                if (candidate.waypoint != null) {
                    distance = candidate.waypoint.squaredDistanceTo(client.player);
                } else if (candidate.current != null && candidate.current.dimension().equals(dimension)) {
                    double dx = candidate.current.x() - client.player.getX();
                    double dy = candidate.current.y() - client.player.getY();
                    double dz = candidate.current.z() - client.player.getZ();
                    distance = dx * dx + dy * dy + dz * dz;
                } else continue;
                if (chosen == null || distance < best) { best = distance; chosen = entry.getKey(); }
            }
            if (chosen != null) selected = chosen;
        }
        Target target = targets.get(chosen);
        if (target == null) {
            client.player.sendMessage(Text.literal("Player locator: no player found"), true);
            return;
        }
        if (target.waypoint != null) {
            double yaw = target.waypoint.getRelativeYaw(client.world, client.gameRenderer.getCamera(), entity -> 1.0f);
            int direction = Math.floorMod((int) Math.round(yaw / 45.0), 8);
            String[] arrows = {"↑", "↗", "→", "↘", "↓", "↙", "←", "↖"};
            double distance = Math.sqrt(target.waypoint.squaredDistanceTo(client.player));
            String distanceText = Double.isFinite(distance) ? "~" + Math.round(distance) + " blocks" : "distance unavailable";
            client.player.sendMessage(Text.literal(arrows[direction] + " " + target.name + " - " + distanceText), true);
            return;
        }
        Position pos = target.last.get(dimension);
        if (pos == null) {
            client.player.sendMessage(Text.literal(target.name + ": no last location in this dimension"), true);
            return;
        }
        double dx = pos.x() - client.player.getX();
        double dy = pos.y() - client.player.getY();
        double dz = pos.z() - client.player.getZ();
        double distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
        double bearing = Math.toDegrees(Math.atan2(-dx, dz));
        int direction = Math.floorMod((int) Math.round((bearing - client.player.getYaw()) / 45.0), 8);
        String[] arrows = {"↑", "↗", "→", "↘", "↓", "↙", "←", "↖"};
        boolean live = target.online && target.current != null && target.current.dimension().equals(dimension);
        client.player.sendMessage(Text.literal(arrows[direction] + " " + target.name + " - " + Math.round(distance) + " blocks" + (live ? "" : " (last location)")), true);
    }
}