mirror of
https://github.com/Wurst-Imperium/Wurst7.git
synced 2024-09-20 01:12:13 +02:00
Add AimAtSetting to AimAssistHack
This commit is contained in:
parent
a8fcc2ac28
commit
21ab04cf1e
@ -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<Entity> 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<Entity> 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
|
||||
|
130
src/main/java/net/wurstclient/settings/AimAtSetting.java
Normal file
130
src/main/java/net/wurstclient/settings/AimAtSetting.java
Normal file
@ -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<AimAtSetting.AimAt>
|
||||
{
|
||||
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<Entity, Vec3d> aimFunction;
|
||||
|
||||
private AimAt(String name, String description,
|
||||
Function<Entity, Vec3d> 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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user