From 57b52dcbfcecd60a4bd9b341e74291ce612db728 Mon Sep 17 00:00:00 2001 From: Volcan <78641040+Volcan4436@users.noreply.github.com> Date: Sun, 1 Sep 2024 13:37:46 +1000 Subject: [PATCH] AimAssist --- .../org/bleachhack/module/mods/AimAssist.java | 103 ++++++++++++++++++ .../java/org/bleachhack/util/MathUtil.java | 18 +++ .../bleachhack/util/world/EntityUtils.java | 11 ++ .../java/org/bleachhack/util/world/Rot.java | 4 + src/main/resources/bleachhack.modules.json | 1 + 5 files changed, 137 insertions(+) create mode 100644 src/main/java/org/bleachhack/module/mods/AimAssist.java create mode 100644 src/main/java/org/bleachhack/util/MathUtil.java create mode 100644 src/main/java/org/bleachhack/util/world/Rot.java diff --git a/src/main/java/org/bleachhack/module/mods/AimAssist.java b/src/main/java/org/bleachhack/module/mods/AimAssist.java new file mode 100644 index 000000000..ab57deec8 --- /dev/null +++ b/src/main/java/org/bleachhack/module/mods/AimAssist.java @@ -0,0 +1,103 @@ +package org.bleachhack.module.mods; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.item.FireworkRocketItem; +import net.minecraft.item.ItemStack; +import net.minecraft.util.hit.EntityHitResult; +import net.minecraft.util.hit.HitResult; +import net.minecraft.util.math.MathHelper; +import org.bleachhack.event.events.EventTick; +import org.bleachhack.eventbus.BleachSubscribe; +import org.bleachhack.module.Module; +import org.bleachhack.module.ModuleCategory; +import org.bleachhack.setting.module.SettingSlider; +import org.bleachhack.setting.module.SettingToggle; +import org.bleachhack.util.MathUtil; +import org.bleachhack.util.world.EntityUtils; +import org.bleachhack.util.world.Rot; + +public class AimAssist extends Module { + + public AimAssist() { + super("AimAssist", KEY_UNBOUND, ModuleCategory.COMBAT, "Automatically aims at entities.", + new SettingSlider("Distance", 3, 10, 10, 2).withDesc("The distance of the aim."), + new SettingSlider("Smoothness", 0, 10, 6, 2).withDesc("The smoothness of the aim."), + new SettingToggle("SeeOnly", true).withDesc("Only aims at entities you can see."), + new SettingToggle("Vertical", true).withDesc("Aim at vertical entities."), + new SettingToggle("Horizontal", true).withDesc("Aim at horizontal entities.")); + } + + + public static boolean isOverEntity() { + if (mc.crosshairTarget == null) return false; + HitResult hitResult = mc.crosshairTarget; + if (hitResult.getType() == HitResult.Type.ENTITY) { + Entity entity = ((EntityHitResult) hitResult).getEntity(); + return true; + } else { + return false; + } + } + + public boolean isHoldingFirework() { + PlayerInventory inventory = mc.player.getInventory(); + ItemStack heldItem = inventory.getMainHandStack(); + + return heldItem.getItem() instanceof FireworkRocketItem; + } + + @BleachSubscribe + public void onTick(EventTick event) { + if (isHoldingFirework()) return; + if (isOverEntity()) return; + if (mc.currentScreen != null) return; + + PlayerEntity targetPlayer = EntityUtils.findClosest(PlayerEntity.class, getSetting(0).asSlider().getValueFloat()); + + if (targetPlayer == null || (getSetting(2).asToggle().getState() && !mc.player.canSee(targetPlayer))) { + return; + } + Rot targetRot = MathUtil.getDir(mc.player, targetPlayer.getPos()); + + float yawDist = MathHelper.subtractAngles((float) targetRot.yaw(), mc.player.getYaw()); + float pitchDist = MathHelper.subtractAngles((float) targetRot.pitch(), mc.player.getPitch()); + + float yaw; + float pitch; + + float stren = getSetting(1).asSlider().getValueFloat() / 10; + + + yaw = mc.player.getYaw(); + if (Math.abs(yawDist) > stren) { + yaw = mc.player.getYaw(); + if (yawDist < 0) { + yaw += stren; + } else if (yawDist > 0) { + yaw -= stren; + } + } else { + // aw = (float) targetRot.yaw(); + } + + pitch = mc.player.getPitch(); + if (Math.abs(pitchDist) > stren) { + pitch = mc.player.getPitch(); + if (pitchDist < 0) { + pitch += stren; + } else if (pitchDist > 0) { + pitch -= stren; + } + } else { + // pitch = (float) targetRot.pitch(); + } + + float stren2 = getSetting(1).asSlider().getValueFloat() / 50; + yaw = MathHelper.lerpAngleDegrees(stren2, mc.player.getYaw(), (float) targetRot.yaw()); + pitch = MathHelper.lerpAngleDegrees(stren2, mc.player.getPitch(), (float) targetRot.pitch()); + if (getSetting(3).asToggle().getState()) mc.player.setYaw(yaw); + if (getSetting(4).asToggle().getState()) mc.player.setPitch(pitch); + } +} diff --git a/src/main/java/org/bleachhack/util/MathUtil.java b/src/main/java/org/bleachhack/util/MathUtil.java new file mode 100644 index 000000000..ebffeb44e --- /dev/null +++ b/src/main/java/org/bleachhack/util/MathUtil.java @@ -0,0 +1,18 @@ +package org.bleachhack.util; + +import net.minecraft.entity.Entity; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; +import org.bleachhack.util.world.Rot; + +public class MathUtil { + + public static Rot getDir(Entity entity, Vec3d vec) { + double dx = vec.x - entity.getX(), + dy = vec.y - entity.getY(), + dz = vec.z - entity.getZ(), + dist = MathHelper.sqrt((float) (dx * dx + dz * dz)); + + return new Rot(MathHelper.wrapDegrees(Math.toDegrees(Math.atan2(dz, dx)) - 90.0), -MathHelper.wrapDegrees(Math.toDegrees(Math.atan2(dy, dist)))); + } +} diff --git a/src/main/java/org/bleachhack/util/world/EntityUtils.java b/src/main/java/org/bleachhack/util/world/EntityUtils.java index df9539c1f..c07098ed6 100644 --- a/src/main/java/org/bleachhack/util/world/EntityUtils.java +++ b/src/main/java/org/bleachhack/util/world/EntityUtils.java @@ -22,6 +22,8 @@ import net.minecraft.entity.projectile.ShulkerBulletEntity; import org.bleachhack.BleachHack; +import static org.bleachhack.util.world.WorldUtils.mc; + public class EntityUtils { public static boolean isAnimal(Entity e) { @@ -54,4 +56,13 @@ public static boolean isAttackable(Entity e, boolean ignoreFriends) { && !(e instanceof PlayerCopyEntity) && (!ignoreFriends || !BleachHack.friendMang.has(e)); } + + public static T findClosest(Class entityClass, float range) { + for (Entity entity : mc.world.getEntities()) { + if (entityClass.isAssignableFrom(entity.getClass()) && !entity.equals(mc.player) && entity.distanceTo(mc.player) <= range) { + return (T) entity; + } + } + return null; + } } diff --git a/src/main/java/org/bleachhack/util/world/Rot.java b/src/main/java/org/bleachhack/util/world/Rot.java new file mode 100644 index 000000000..f0286eb97 --- /dev/null +++ b/src/main/java/org/bleachhack/util/world/Rot.java @@ -0,0 +1,4 @@ +package org.bleachhack.util.world; + +public record Rot(double yaw, double pitch) { +} diff --git a/src/main/resources/bleachhack.modules.json b/src/main/resources/bleachhack.modules.json index a8eca1b0c..b2643ec98 100644 --- a/src/main/resources/bleachhack.modules.json +++ b/src/main/resources/bleachhack.modules.json @@ -1,6 +1,7 @@ { "package": "org.bleachhack.module.mods", "modules": [ + "AimAssist", "AirPlace", "Ambience", "AntiChunkBan",