Начинающий
- Статус
- Оффлайн
- Регистрация
- 23 Июн 2025
- Сообщения
- 47
- Реакции
- 0
- Выберите загрузчик игры
- Vanilla
Код:
package im.expensive.functions.impl.combat;
import com.google.common.eventbus.Subscribe;
import im.expensive.command.friends.FriendStorage;
import im.expensive.events.EventMotion;
import im.expensive.functions.api.Category;
import im.expensive.functions.api.Function;
import im.expensive.functions.api.FunctionRegister;
import im.expensive.functions.settings.impl.SliderSetting;
import im.expensive.utils.math.SensUtils;
import im.expensive.utils.math.StopWatch;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BowItem;
import net.minecraft.item.ItemStack;
import net.minecraft.item.TridentItem;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Vector2f;
@FunctionRegister(name = "AimHelper", type = Category.Combat)
public class AimAssist extends Function {
private final SliderSetting range = new SliderSetting("Дистанция", 40f, 10f, 100f, 1f);
private final SliderSetting speed = new SliderSetting("Скорость наводки", 5f, 1f, 20f, 0.5f);
private final SliderSetting predict = new SliderSetting("Предикт", 1.0f, 0.1f, 3.0f, 0.1f);
private LivingEntity target;
private Vector2f rotateVector = new Vector2f(0, 0);
private final StopWatch stopWatch = new StopWatch();
private boolean isRotated;
public AimAssist() {
addSettings(range, speed, predict);
}
@Override
public void onEnable() {
super.onEnable();
reset();
target = null;
}
@Override
public void onDisable() {
super.onDisable();
reset();
target = null;
}
@Subscribe
public void onMotion(EventMotion e) {
if (!isHoldingWeapon() || !mc.player.isHandActive()) {
target = null;
reset();
return;
}
target = findTarget();
if (target != null) {
updateRotation();
float yaw = rotateVector.x;
float pitch = rotateVector.y;
e.setYaw(yaw);
e.setPitch(pitch);
mc.player.rotationYawHead = yaw;
mc.player.renderYawOffset = yaw;
mc.player.rotationPitchHead = pitch;
} else {
reset();
}
}
private void updateRotation() {
float[] rotations = calculateRotations(target);
if (rotations != null) {
float yawToTarget = rotations[0];
float pitchToTarget = rotations[1];
float yawDelta = MathHelper.wrapDegrees(yawToTarget - rotateVector.x);
float pitchDelta = MathHelper.wrapDegrees(pitchToTarget - rotateVector.y);
float yawStep = MathHelper.clamp(yawDelta, -speed.get(), speed.get());
float pitchStep = MathHelper.clamp(pitchDelta, -speed.get(), speed.get());
float gcd = SensUtils.getGCDValue();
float nextYaw = rotateVector.x + Math.round(yawStep / gcd) * gcd;
float nextPitch = rotateVector.y + Math.round(pitchStep / gcd) * gcd;
rotateVector = new Vector2f(nextYaw, MathHelper.clamp(nextPitch, -90, 90));
isRotated = true;
}
}
private void reset() {
if (target == null) {
float returnSpeed = 35.0F;
float yawDelta = MathHelper.wrapDegrees(mc.player.rotationYaw - rotateVector.x);
float pitchDelta = mc.player.rotationPitch - rotateVector.y;
float stepX = MathHelper.clamp(yawDelta, -returnSpeed, returnSpeed);
float stepY = MathHelper.clamp(pitchDelta, -returnSpeed, returnSpeed);
rotateVector = new Vector2f(rotateVector.x + stepX, rotateVector.y + stepY);
}
isRotated = false;
}
private float[] calculateRotations(LivingEntity entity) {
double x = entity.getPosX() + (entity.getPosX() - entity.prevPosX) * predict.get();
double z = entity.getPosZ() + (entity.getPosZ() - entity.prevPosZ) * predict.get();
double y = entity.getPosY() + entity.getEyeHeight() / 2.0;
double diffX = x - mc.player.getPosX();
double diffZ = z - mc.player.getPosZ();
double diffY = y - (mc.player.getPosY() + mc.player.getEyeHeight());
double dist = MathHelper.sqrt(diffX * diffX + diffZ * diffZ);
float velocity = getVelocity();
float g = 0.006f;
float pitch = (float) -Math.toDegrees(Math.atan((velocity * velocity - Math.sqrt(Math.max(0, velocity * velocity * velocity * velocity - g * (g * dist * dist + 2 * diffY * velocity * velocity)))) / (g * dist)));
if (Float.isNaN(pitch)) {
pitch = (float) -Math.toDegrees(Math.atan2(diffY, dist));
}
float yaw = (float) (MathHelper.atan2(diffZ, diffX) * (180 / Math.PI)) - 90.0F;
return new float[]{yaw, pitch};
}
private float getVelocity() {
ItemStack stack = mc.player.getActiveItemStack();
if (stack.getItem() instanceof BowItem) {
int i = mc.player.getItemInUseMaxCount();
float f = (float) i / 20.0F;
f = (f * f + f * 2.0F) / 3.0F;
return Math.min(f, 1.0f) * 3.0F;
} else if (stack.getItem() instanceof TridentItem) {
return 2.5F;
}
return 1.0F;
}
private boolean isHoldingWeapon() {
return mc.player.getHeldItemMainhand().getItem() instanceof BowItem ||
mc.player.getHeldItemMainhand().getItem() instanceof TridentItem;
}
private LivingEntity findTarget() {
LivingEntity bestEntity = null;
double bestDist = range.get();
for (PlayerEntity player : mc.world.getPlayers()) {
if (player == mc.player || !player.isAlive() || player.isInvisible()) continue;
if (FriendStorage.isFriend(player.getName().getString())) continue;
if (AntiBot.isBot(player)) continue;
double dist = mc.player.getDistance(player);
if (dist < bestDist) {
bestDist = dist;
bestEntity = player;
}
}
return bestEntity;
}
}
}
Последнее редактирование: