Shemol Haywood

make a mod that makes it if im looking at a player or a mob my mouse doesnt let me move from them like if im looking at something and i try to look awa it doesnt work unless im holding a ender pearl and make it so i can disable it with a keybind i set

Kodari AI
KodariOct 30 at 3:26 pm 1
GazeLock
A Minecraft mod that locks your camera onto the entity you're looking at, preventing you from looking away. The lock activates automatically when viewing a player or mob, and can be temporarily disabled by holding an ender pearl. Includes a configurable keybind to toggle the entire feature on and off, giving players full control over when the gaze lock applies.
  1. Add a client-side target lock for players and mobs, released while an ender pearl is held.

  2. Add a toggle keybind that players can remap in Controls.

  3. Create the Fabric 1.21.11 project files and client entrypoint.

Added the Fabric 1.21.11 client mod. It locks your aim to the player or mob you first look at, and holding an ender pearl in either hand temporarily releases the lock. Press G to toggle Entity Focus; remap the key in Options → Controls.

Shemol Haywood

make it not work if im below 4 hunger bars below 4 hearts and after i hit the target it diables until i look at them again

Kodari AI
KodariOct 30 at 3:30 pm 1
  1. Add the hunger and health checks so target lock only applies at 4+ hunger bars and 4+ hearts.

  2. After you hit the locked target, release the lock and wait until you look at it again.

Added both conditions. Target lock now pauses below 4 hunger bars or 4 hearts. Hitting the locked target releases it; you must look away and then back at that target to lock on again.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
6 192
src/client/java/com/kodari/entityfocus/EntityFocusClient.java
package com.kodari.entityfocus;

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.event.player.AttackEntityCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.Items;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.math.Vec3d;

public class EntityFocusClient implements ClientModInitializer {
    private KeyBinding toggleKey;
    private LivingEntity target;
    private LivingEntity suppressedTarget;
    private Object targetWorld;
    private boolean enabled = true;

    @Override
    public void onInitializeClient() {
        KeyBinding.Category category = KeyBinding.Category.create(Identifier.of("entityfocus", "controls"));
        toggleKey = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.entityfocus.toggle", 71, category));
        ClientTickEvents.END_CLIENT_TICK.register(this::onClientTick);
        AttackEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
            if (target == entity) {
                suppressedTarget = target;
                target = null;
            }
            return ActionResult.PASS;
        });
    }

    private void onClientTick(MinecraftClient client) {
        while (toggleKey.wasPressed()) {
            enabled = !enabled;
            if (!enabled) {
                target = null;
                suppressedTarget = null;
            }
        }

        if (!enabled || client.player == null || client.world == null) {
            target = null;
            suppressedTarget = null;
            targetWorld = null;
            return;
        }

        if (targetWorld != client.world) {
            target = null;
            suppressedTarget = null;
            targetWorld = client.world;
        }

        if (client.player.getHungerManager().getFoodLevel() < 8 || client.player.getHealth() < 8.0F) {
            target = null;
            suppressedTarget = null;
            return;
        }

        if (target != null && !target.isAlive()) {
            target = null;
        }

        if (suppressedTarget != null && !suppressedTarget.isAlive()) {
            suppressedTarget = null;
        }

        LivingEntity aimedAt = client.crosshairTarget instanceof EntityHitResult hit
                && hit.getEntity() instanceof LivingEntity living && living.isAlive() ? living : null;
        if (suppressedTarget != null && aimedAt != suppressedTarget) {
            suppressedTarget = null;
        }

        if (target == null && aimedAt != null && aimedAt != suppressedTarget) {
            target = aimedAt;
            targetWorld = client.world;
        }

        if (target == null || client.player.isHolding(Items.ENDER_PEARL)) {
            return;
        }

        Vec3d targetEyePos = target.getEyePos();
        Vec3d playerEyePos = client.player.getEyePos();
        double dx = targetEyePos.x - playerEyePos.x;
        double dy = targetEyePos.y - playerEyePos.y;
        double dz = targetEyePos.z - playerEyePos.z;
        double horizontalDistance = Math.sqrt(dx * dx + dz * dz);
        float yaw = (float) (Math.toDegrees(Math.atan2(dz, dx)) - 90.0);
        float pitch = (float) -Math.toDegrees(Math.atan2(dy, horizontalDistance));
        client.player.setAngles(yaw, pitch);
    }
}