Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added AimAssist #521

Open
wants to merge 1 commit into
base: 1.20.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions src/main/java/org/bleachhack/module/mods/AimAssist.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
18 changes: 18 additions & 0 deletions src/main/java/org/bleachhack/util/MathUtil.java
Original file line number Diff line number Diff line change
@@ -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))));
}
}
11 changes: 11 additions & 0 deletions src/main/java/org/bleachhack/util/world/EntityUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -54,4 +56,13 @@ public static boolean isAttackable(Entity e, boolean ignoreFriends) {
&& !(e instanceof PlayerCopyEntity)
&& (!ignoreFriends || !BleachHack.friendMang.has(e));
}

public static <T extends Entity> T findClosest(Class<T> 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;
}
}
4 changes: 4 additions & 0 deletions src/main/java/org/bleachhack/util/world/Rot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.bleachhack.util.world;

public record Rot(double yaw, double pitch) {
}
1 change: 1 addition & 0 deletions src/main/resources/bleachhack.modules.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"package": "org.bleachhack.module.mods",
"modules": [
"AimAssist",
"AirPlace",
"Ambience",
"AntiChunkBan",
Expand Down