Keshav Joshi

make a fabric 1.21.11 mod thats main function is to track any players pearls . if any player throw a pearl(me also) so in the actionbar a small arrow appears showing the direction of pearl flying pearls and arrown direction changes according to the pearl

Kodari AI
KodariSep 27 at 8:46 pm 1
PearlTracker
This mod tracks any thrown ender pearl by any player, including the user. When a pearl is thrown, a small arrow appears in the player's action bar, indicating the direction of the pearl's flight. The arrow dynamically updates its direction as the pearl travels, helping players locate and follow their thrown pearls.
  1. Track loaded ender pearls and show a live directional indicator for the nearest one.

  2. Add the client-only Fabric 1.21.11 project setup and metadata.

Created a client-only Fabric 1.21.11 mod. While any player’s ender pearl is loaded nearby, a small arrow appears above the hotbar and points toward the nearest pearl relative to your view; it updates as the pearl moves and disappears when none are loaded.

Added the Gradle setup, Fabric metadata, and HUD implementation.

Keshav Joshi

fis the direction of this mod this give opposite direction

Kodari AI
KodariSep 27 at 8:59 pm 1

Fixed the arrow’s bearing calculation in PearlDirectionClient: it now uses Minecraft’s yaw convention and the correct screen-direction sign, so it points toward the pearl instead of the opposite direction.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
5 145
src/client/java/com/example/pearldirection/PearlDirectionClient.java
package com.example.pearldirection;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.RenderTickCounter;
import net.minecraft.entity.Entity;
import net.minecraft.entity.projectile.thrown.EnderPearlEntity;
import net.minecraft.util.Identifier;

public class PearlDirectionClient implements ClientModInitializer {
    private static final String[] DIRECTIONS = {"↑", "↗", "→", "↘", "↓", "↙", "←", "↖"};

    @Override
    public void onInitializeClient() {
        HudElementRegistry.addLast(Identifier.of("pearl_direction", "pearl_indicator"), PearlDirectionClient::renderPearlDirection);
    }

    private static void renderPearlDirection(DrawContext context, RenderTickCounter tickCounter) {
        MinecraftClient client = MinecraftClient.getInstance();
        if (client.world == null || client.player == null) {
            return;
        }

        EnderPearlEntity nearestPearl = null;
        double nearestDistanceSquared = Double.MAX_VALUE;

        for (Entity entity : client.world.getEntities()) {
            if (entity instanceof EnderPearlEntity pearl) {
                double deltaX = pearl.getX() - client.player.getX();
                double deltaY = pearl.getY() - client.player.getY();
                double deltaZ = pearl.getZ() - client.player.getZ();
                double distanceSquared = deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;

                if (distanceSquared < nearestDistanceSquared) {
                    nearestDistanceSquared = distanceSquared;
                    nearestPearl = pearl;
                }
            }
        }

        if (nearestPearl == null) {
            return;
        }

        double deltaX = nearestPearl.getX() - client.player.getX();
        double deltaZ = nearestPearl.getZ() - client.player.getZ();
        double angleFromView = Math.toDegrees(Math.atan2(-deltaX, deltaZ)) - client.player.getYaw();
        int directionIndex = Math.floorMod((int) Math.round(angleFromView / 45.0), DIRECTIONS.length);

        context.drawCenteredTextWithShadow(
                client.textRenderer,
                DIRECTIONS[directionIndex],
                context.getScaledWindowWidth() / 2,
                context.getScaledWindowHeight() - 49,
                0xFFFFFFFF
        );
    }
}