From 21ab04cf1e0d2dea63b6e4114af4280c84bc8ff3 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Sun, 9 Jun 2024 14:43:48 +0200 Subject: [PATCH] Add AimAtSetting to AimAssistHack --- .../net/wurstclient/hacks/AimAssistHack.java | 54 ++++---- .../wurstclient/settings/AimAtSetting.java | 130 ++++++++++++++++++ 2 files changed, 156 insertions(+), 28 deletions(-) create mode 100644 src/main/java/net/wurstclient/settings/AimAtSetting.java diff --git a/src/main/java/net/wurstclient/hacks/AimAssistHack.java b/src/main/java/net/wurstclient/hacks/AimAssistHack.java index 362550c1..6d9bee7a 100644 --- a/src/main/java/net/wurstclient/hacks/AimAssistHack.java +++ b/src/main/java/net/wurstclient/hacks/AimAssistHack.java @@ -12,13 +12,13 @@ import java.util.stream.Stream; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.entity.Entity; -import net.minecraft.util.math.Box; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.wurstclient.Category; import net.wurstclient.events.MouseUpdateListener; import net.wurstclient.events.UpdateListener; import net.wurstclient.hack.Hack; +import net.wurstclient.settings.AimAtSetting; import net.wurstclient.settings.CheckboxSetting; import net.wurstclient.settings.SliderSetting; import net.wurstclient.settings.SliderSetting.ValueDisplay; @@ -44,6 +44,9 @@ public final class AimAssistHack extends Hack + "360\u00b0 = aims at entities all around you.", 120, 30, 360, 10, ValueDisplay.DEGREES); + private final AimAtSetting aimAt = new AimAtSetting( + "What point in the target's hitbox AimAssist should aim at."); + private final CheckboxSetting checkLOS = new CheckboxSetting( "Check line of sight", "Won't aim at entities behind blocks.", true); @@ -93,6 +96,7 @@ public final class AimAssistHack extends Hack addSetting(range); addSetting(rotationSpeed); addSetting(fov); + addSetting(aimAt); addSetting(checkLOS); addSetting(aimWhileBlocking); @@ -137,24 +141,11 @@ public final class AimAssistHack extends Hack if(!aimWhileBlocking.isChecked() && MC.player.isUsingItem()) return; - Stream stream = EntityUtils.getAttackableEntities(); - double rangeSq = Math.pow(range.getValue(), 2); - stream = stream.filter(e -> MC.player.squaredDistanceTo(e) <= rangeSq); - - if(fov.getValue() < 360.0) - stream = stream.filter(e -> RotationUtils.getAngleToLookVec( - e.getBoundingBox().getCenter()) <= fov.getValue() / 2.0); - - stream = entityFilters.applyTo(stream); - - target = stream - .min(Comparator.comparingDouble(e -> RotationUtils - .getAngleToLookVec(e.getBoundingBox().getCenter()))) - .orElse(null); + chooseTarget(); if(target == null) return; - Vec3d hitVec = target.getBoundingBox().getCenter(); + Vec3d hitVec = aimAt.getAimPoint(target); if(checkLOS.isChecked() && !BlockUtils.hasLineOfSight(hitVec)) { target = null; @@ -162,27 +153,34 @@ public final class AimAssistHack extends Hack } WURST.getHax().autoSwordHack.setSlot(target); - faceEntityClient(target); - } - - private boolean faceEntityClient(Entity entity) - { + // get needed rotation - Box box = entity.getBoundingBox(); - Rotation needed = RotationUtils.getNeededRotations(box.getCenter()); + Rotation needed = RotationUtils.getNeededRotations(hitVec); // turn towards center of boundingBox Rotation next = RotationUtils.slowlyTurnTowards(needed, rotationSpeed.getValueI() / 20F); nextYaw = next.yaw(); nextPitch = next.pitch(); + } + + private void chooseTarget() + { + Stream stream = EntityUtils.getAttackableEntities(); - // check if facing center - if(RotationUtils.isAlreadyFacing(needed)) - return true; + double rangeSq = range.getValueSq(); + stream = stream.filter(e -> MC.player.squaredDistanceTo(e) <= rangeSq); - // if not facing center, check if facing anything in boundingBox - return RotationUtils.isFacingBox(box, range.getValue()); + if(fov.getValue() < 360.0) + stream = stream.filter(e -> RotationUtils.getAngleToLookVec( + aimAt.getAimPoint(e)) <= fov.getValue() / 2.0); + + stream = entityFilters.applyTo(stream); + + target = stream + .min(Comparator.comparingDouble( + e -> RotationUtils.getAngleToLookVec(aimAt.getAimPoint(e)))) + .orElse(null); } @Override diff --git a/src/main/java/net/wurstclient/settings/AimAtSetting.java b/src/main/java/net/wurstclient/settings/AimAtSetting.java new file mode 100644 index 00000000..edaffbc1 --- /dev/null +++ b/src/main/java/net/wurstclient/settings/AimAtSetting.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2014-2024 Wurst-Imperium and contributors. + * + * This source code is subject to the terms of the GNU General Public + * License, version 3. If a copy of the GPL was not distributed with this + * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt + */ +package net.wurstclient.settings; + +import java.util.function.Function; + +import net.minecraft.entity.Entity; +import net.minecraft.util.math.Box; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; +import net.wurstclient.util.RotationUtils; + +public final class AimAtSetting extends EnumSetting +{ + private static final String FULL_DESCRIPTION_SUFFIX = + buildDescriptionSuffix(); + + private AimAtSetting(String name, String description, AimAt[] values, + AimAt selected) + { + super(name, description, values, selected); + } + + public AimAtSetting(String name, String description, AimAt selected) + { + this(name, description + FULL_DESCRIPTION_SUFFIX, AimAt.values(), + selected); + } + + public AimAtSetting(String description, AimAt selected) + { + this("Aim at", description, selected); + } + + public AimAtSetting(String description) + { + this(description, AimAt.AUTO); + } + + public Vec3d getAimPoint(Entity e) + { + return getSelected().aimFunction.apply(e); + } + + private static String buildDescriptionSuffix() + { + StringBuilder builder = new StringBuilder("\n\n"); + AimAt[] values = AimAt.values(); + + for(AimAt value : values) + builder.append("\u00a7l").append(value.name).append("\u00a7r - ") + .append(value.description).append("\n\n"); + + return builder.toString(); + } + + private static Vec3d aimAtClosestPoint(Entity e) + { + Box box = e.getBoundingBox(); + Vec3d eyes = RotationUtils.getEyesPos(); + + if(box.contains(eyes)) + return eyes; + + double clampedX = MathHelper.clamp(eyes.x, box.minX, box.maxX); + double clampedY = MathHelper.clamp(eyes.y, box.minY, box.maxY); + double clampedZ = MathHelper.clamp(eyes.z, box.minZ, box.maxZ); + + return new Vec3d(clampedX, clampedY, clampedZ); + } + + private static Vec3d aimAtHead(Entity e) + { + float eyeHeight = e.getEyeHeight(e.getPose()); + return e.getPos().add(0, eyeHeight, 0); + } + + private static Vec3d aimAtCenter(Entity e) + { + return e.getBoundingBox().getCenter(); + } + + private static Vec3d aimAtFeet(Entity e) + { + return e.getPos().add(0, 0.001, 0); + } + + public enum AimAt + { + AUTO("Auto", "Aims at the closest point of the target's hitbox.", + AimAtSetting::aimAtClosestPoint), + + HEAD("Head", "Aims at the target's eye position.", + AimAtSetting::aimAtHead), + + CENTER("Center", "Aims at the center of the target's hitbox.", + AimAtSetting::aimAtCenter), + + FEET("Feet", "Aims at the bottom of the target's hitbox.", + AimAtSetting::aimAtFeet); + + private final String name; + private final String description; + private final Function aimFunction; + + private AimAt(String name, String description, + Function aimFunction) + { + this.name = name; + this.description = description; + this.aimFunction = aimFunction; + } + + public Vec3d getAimPoint(Entity e) + { + return aimFunction.apply(e); + } + + @Override + public String toString() + { + return name; + } + } +}