regnatoropas-web

Make an aim asist that aim like an player and only aim on player that the name I written in chat e.g /aim (player) name and it automatically aim on player and auto mechanic off aim when my heart loss 5 when I will regenerate the assist start again aim on player

Kodari AI
KodariAug 28 at 12:33 pm 2
PlayerAimAssist
Creates a Fabric mod that provides an aim assist feature. Players can target a specific player by typing /aim (player name) in chat, which automatically rotates the camera toward that player. The assist automatically disables when the user loses 5 hearts of health and re-enables when health regenerates back above that threshold. The mod continuously tracks the target player's position and smoothly adjusts the player's view direction to maintain aim on the target.
  • Create a minimal Fabric 1.21.11 client-only project using split client sources.

  • Register /aim <player> and /aim off as client commands.

  • Add smooth player-only targeting with a five-heart health pause and regeneration resume.

Created a new Fabric 1.21.11 client-side Aim Assist mod.

Features:

  • /aim <player> targets a nearby player by name.

  • Smoothly rotates toward the target.

  • Only targets alive, non-spectating players.

  • /aim off disables the assist.

  • Pauses after losing five hearts.

  • Automatically resumes after health regenerates.

  • Uses the required Fabric 1.21.11 split client source structure.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
5 250
src/client/java/com/kodari/aimassist/AimAssistClient.java
package com.kodari.aimassist;

import com.mojang.brigadier.arguments.StringArgumentType;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.math.MathHelper;

public final class AimAssistClient implements ClientModInitializer {
    private static final AimController CONTROLLER = new AimController();

    @Override
    public void onInitializeClient() {
        ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(
            ClientCommandManager.literal("aim")
                .then(ClientCommandManager.literal("off")
                    .executes(context -> {
                        context.getSource().sendFeedback(CONTROLLER.clearTarget());
                        return 1;
                    }))
                .then(ClientCommandManager.argument("player", StringArgumentType.word())
                    .executes(context -> {
                        String name = StringArgumentType.getString(context, "player");
                        context.getSource().sendFeedback(CONTROLLER.setTarget(
                            MinecraftClient.getInstance(), name));
                        return 1;
                    }))
                .executes(context -> {
                    context.getSource().sendFeedback(Text.literal("Usage: /aim <player> or /aim off"));
                    return 1;
                })
        ));

        ClientTickEvents.END_CLIENT_TICK.register(CONTROLLER::tick);
    }

    private static final class AimController {
        private static final float HEALTH_LOSS_TO_PAUSE = 10.0f;
        private static final float MAX_ROTATION_PER_TICK = 12.0f;

        private String targetName;
        private String missingTargetName;
        private boolean active;
        private boolean waitingForRegeneration;
        private float healthPeak;
        private float healthAtPause;

        private Text setTarget(MinecraftClient client, String name) {
            targetName = name;
            missingTargetName = null;
            waitingForRegeneration = false;
            active = true;
            healthPeak = client.player == null ? 0.0f : client.player.getHealth();
            healthAtPause = healthPeak;
            return Text.literal("Aim assist enabled for " + name + ".");
        }

        private Text clearTarget() {
            targetName = null;
            missingTargetName = null;
            active = false;
            waitingForRegeneration = false;
            return Text.literal("Aim assist disabled.");
        }

        private void tick(MinecraftClient client) {
            ClientPlayerEntity player = client.player;
            if (player == null || client.world == null || targetName == null) {
                return;
            }

            updateHealthState(player);
            if (!active || waitingForRegeneration || client.currentScreen != null || player.isSleeping()) {
                return;
            }

            PlayerEntity target = findTarget(client, player);
            if (target == null) {
                if (!targetName.equals(missingTargetName)) {
                    player.sendMessage(Text.literal("Player not found: " + targetName), false);
                    missingTargetName = targetName;
                }
                return;
            }

            missingTargetName = null;
            rotateToward(player, target);
        }

        private void updateHealthState(ClientPlayerEntity player) {
            float health = player.getHealth();

            if (waitingForRegeneration) {
                if (health > healthAtPause) {
                    waitingForRegeneration = false;
                    active = true;
                    healthPeak = health;
                    player.sendMessage(Text.literal("Aim assist resumed after regeneration."), false);
                }
                return;
            }

            if (health > healthPeak) {
                healthPeak = health;
            }

            if (active && health <= healthPeak - HEALTH_LOSS_TO_PAUSE) {
                active = false;
                waitingForRegeneration = true;
                healthAtPause = health;
                player.sendMessage(Text.literal("Aim assist paused after losing five hearts."), false);
            }
        }

        private PlayerEntity findTarget(MinecraftClient client, ClientPlayerEntity player) {
            for (PlayerEntity candidate : client.world.getPlayers()) {
                if (candidate != player
                    && candidate.isAlive()
                    && !candidate.isSpectator()
                    && candidate.getName().getString().equalsIgnoreCase(targetName)) {
                    return candidate;
                }
            }
            return null;
        }

        private void rotateToward(ClientPlayerEntity player, PlayerEntity target) {
            double x = target.getX() - player.getX();
            double z = target.getZ() - player.getZ();
            double y = target.getY() + target.getHeight() * 0.85
                - (player.getY() + player.getHeight() * 0.9);
            double horizontalDistance = Math.sqrt(x * x + z * z);

            if (horizontalDistance < 0.0001) {
                return;
            }

            float targetYaw = (float) (MathHelper.atan2(z, x) * 180.0 / Math.PI) - 90.0f;
            float targetPitch = (float) -(MathHelper.atan2(y, horizontalDistance) * 180.0 / Math.PI);

            player.setYaw(approachAngle(player.getYaw(), targetYaw, MAX_ROTATION_PER_TICK));
            player.setPitch(MathHelper.clamp(
                approachAngle(player.getPitch(), targetPitch, MAX_ROTATION_PER_TICK), -90.0f, 90.0f));
        }

        private float approachAngle(float current, float target, float maxStep) {
            float difference = MathHelper.wrapDegrees(target - current);
            return current + MathHelper.clamp(difference, -maxStep, maxStep);
        }
    }
}