у меня ии сделал килку потому что я не очень умею делать обходы можете проверить и подсказать что там не так и можете дать Rotation пожалуйста
JavaScript:
package com.example.examplemod;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.item.ItemUseAnimation;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.Vec3;
import org.lwjgl.glfw.GLFW;
import java.util.Comparator;
import java.util.List;
public final class AttackAuraController {
private static boolean enabled = false;
private static int bindKey = GLFW.GLFW_KEY_UNKNOWN;
private static int radius = 4;
private static boolean targetPlayers = true;
private static boolean targetAnimals = false;
private static boolean jumpOnly = true;
private static boolean noAttackWhileEating = true;
private static int lockedTargetId = -1;
private static boolean attackedThisJump = false;
private AttackAuraController() {}
public static boolean isEnabled() {
return enabled;
}
public static void toggle() {
enabled = !enabled;
}
public static void forceDisable() {
enabled = false;
lockedTargetId = -1;
attackedThisJump = false;
}
public static int getBindKey() {
return bindKey;
}
public static void setBindKey(int key) {
bindKey = key;
}
public static void clearBind() {
bindKey = GLFW.GLFW_KEY_UNKNOWN;
}
public static int getRadius() {
return radius;
}
public static void setRadius(int value) {
radius = Math.max(1, Math.min(6, value));
}
public static boolean isTargetPlayers() {
return targetPlayers;
}
public static void setTargetPlayers(boolean value) {
targetPlayers = value;
}
public static boolean isTargetAnimals() {
return targetAnimals;
}
public static void setTargetAnimals(boolean value) {
targetAnimals = value;
}
public static boolean isJumpOnly() {
return jumpOnly;
}
public static void setJumpOnly(boolean value) {
jumpOnly = value;
attackedThisJump = false;
}
public static boolean isNoAttackWhileEating() {
return noAttackWhileEating;
}
public static void setNoAttackWhileEating(boolean value) {
noAttackWhileEating = value;
}
public static void onKeyInput(int key, int action) {
if (action != GLFW.GLFW_PRESS) return;
if (bindKey == GLFW.GLFW_KEY_UNKNOWN) return;
if (key == bindKey) toggle();
}
public static void onClientTick() {
if (!enabled) return;
Minecraft mc = Minecraft.getInstance();
LocalPlayer player = mc.player;
ClientLevel level = mc.level;
if (player == null || level == null || mc.gameMode == null) return;
Entity target = findTarget(player, level);
if (target == null) {
lockedTargetId = -1;
return;
}
lockedTargetId = target.getId();
aimAtTarget(player, target);
ItemUseAnimation useAnim = player.getUseItem().getUseAnimation();
boolean eating = player.isUsingItem() && (useAnim == ItemUseAnimation.EAT || useAnim == ItemUseAnimation.DRINK);
if (noAttackWhileEating && eating) {
return;
}
if (jumpOnly) {
if (player.onGround()) {
attackedThisJump = false;
return;
}
if (player.getDeltaMovement().y >= -0.08) {
return;
}
if (attackedThisJump) return;
}
if (player.getAttackStrengthScale(0.0f) < 0.93f) return;
mc.gameMode.attack(player, target);
player.swing(InteractionHand.MAIN_HAND);
if (jumpOnly) {
attackedThisJump = true;
}
}
private static Entity findTarget(LocalPlayer player, ClientLevel level) {
if (lockedTargetId != -1) {
Entity locked = level.getEntity(lockedTargetId);
if (isValidTarget(player, locked) && player.distanceTo(locked) <= radius + 0.3f) {
return locked;
}
}
Entity crosshair = findCrosshairTarget(player);
if (crosshair != null) {
return crosshair;
}
List<Entity> nearby = level.getEntities(
player,
player.getBoundingBox().inflate(radius),
entity -> isValidTarget(player, entity)
);
return nearby.stream()
.filter(entity -> isInCrosshairCone(player, entity))
.min(Comparator
.comparingDouble((Entity entity) -> -lookDot(player, entity))
.thenComparingDouble(player::distanceToSqr))
.orElseGet(() -> nearby.stream().min(Comparator.comparingDouble(player::distanceToSqr)).orElse(null));
}
private static Entity findCrosshairTarget(LocalPlayer player) {
Minecraft mc = Minecraft.getInstance();
if (!(mc.hitResult instanceof EntityHitResult ehr)) {
return null;
}
Entity entity = ehr.getEntity();
if (!isValidTarget(player, entity)) return null;
if (player.distanceTo(entity) > radius + 0.3f) return null;
return entity;
}
private static boolean isValidTarget(LocalPlayer player, Entity entity) {
if (entity == null || entity == player || !entity.isAlive()) return false;
if (targetPlayers && entity instanceof net.minecraft.world.entity.player.Player other) {
if (other.isSpectator()) return false;
return true;
}
if (targetAnimals && entity instanceof Animal) {
return true;
}
return false;
}
private static boolean isInCrosshairCone(LocalPlayer player, Entity target) {
return lookDot(player, target) >= 0.55;
}
private static double lookDot(LocalPlayer player, Entity target) {
Vec3 look = player.getLookAngle().normalize();
Vec3 toTarget = target.position().add(0.0, target.getBbHeight() * 0.5, 0.0)
.subtract(player.getEyePosition())
.normalize();
return look.dot(toTarget);
}
private static void steerBodyToTarget(LocalPlayer player, Entity target) {
double dx = target.getX() - player.getX();
double dz = target.getZ() - player.getZ();
float yaw = (float) Math.toDegrees(Math.atan2(dz, dx)) - 90.0f;
float wrapped = wrapDegrees(yaw);
player.setYHeadRot(wrapped);
player.yBodyRot = wrapped;
}
private static void pursueTarget(LocalPlayer player, Entity target) {
double dx = target.getX() - player.getX();
double dz = target.getZ() - player.getZ();
double horizontal = Math.sqrt(dx * dx + dz * dz);
if (horizontal < 1.6) return;
float yaw = player.getYHeadRot();
double yawRad = Math.toRadians(yaw);
double lookX = -Math.sin(yawRad);
double lookZ = Math.cos(yawRad);
double strafeX = Math.cos(yawRad);
double strafeZ = Math.sin(yawRad);
int phase = (player.tickCount / 10) % 4;
double strafeInput = (phase == 0 || phase == 1) ? 1.0 : -1.0;
double forwardInput = horizontal > 2.6 ? 0.9 : (horizontal < 1.9 ? -0.35 : 0.15);
if ((player.tickCount / 16) % 3 == 0) {
forwardInput *= -0.35;
}
double nx = lookX * forwardInput + strafeX * strafeInput;
double nz = lookZ * forwardInput + strafeZ * strafeInput;
double moveLen = Math.sqrt(nx * nx + nz * nz);
if (moveLen > 0.0001) {
nx /= moveLen;
nz /= moveLen;
}
double push = player.onGround() ? 0.11 : 0.075;
Vec3 current = player.getDeltaMovement();
double vx = current.x + nx * push;
double vz = current.z + nz * push;
double speed = Math.sqrt(vx * vx + vz * vz);
double maxSpeed = player.onGround() ? 0.43 : 0.36;
if (speed > maxSpeed) {
vx = (vx / speed) * maxSpeed;
vz = (vz / speed) * maxSpeed;
}
player.setDeltaMovement(vx, current.y, vz);
}
private static void aimAtTarget(LocalPlayer player, Entity target) {
double dx = target.getX() - player.getX();
double dy = (target.getY() + target.getBbHeight() * 0.5) - player.getEyeY();
double dz = target.getZ() - player.getZ();
double horizontal = Math.sqrt(dx * dx + dz * dz);
float targetYaw = (float) Math.toDegrees(Math.atan2(dz, dx)) - 90.0f;
float targetPitch = (float) -Math.toDegrees(Math.atan2(dy, horizontal));
float curYaw = player.getYRot();
float curPitch = player.getXRot();
float dyaw = wrapDegrees(targetYaw - curYaw);
float dp = targetPitch - curPitch;
float speed = 0.72f; // smooth factor per tick (0 = no move, 1 = instant snap)
float newYaw = curYaw + dyaw * speed;
float newPitch = Math.max(-90f, Math.min(90f, curPitch + dp * speed));
player.setYRot(newYaw);
player.setXRot(newPitch);
player.setYHeadRot(newYaw);
player.yBodyRot = newYaw;
player.yRotO = newYaw;
player.xRotO = newPitch;
}
private static float wrapDegrees(float value) {
float result = value % 360.0f;
if (result >= 180.0f) result -= 360.0f;
if (result < -180.0f) result += 360.0f;
return result;
}
}