diff --git a/Client/src/main/java/de/com/baseband/client/Setup.java b/Client/src/main/java/de/com/baseband/client/Setup.java index c298d2b..6439d2c 100644 --- a/Client/src/main/java/de/com/baseband/client/Setup.java +++ b/Client/src/main/java/de/com/baseband/client/Setup.java @@ -4,6 +4,7 @@ import de.com.baseband.client.feature.Feature; import de.com.baseband.client.feature.commands.*; import de.com.baseband.client.feature.modules.chat.*; import de.com.baseband.client.feature.modules.client.*; +import de.com.baseband.client.feature.modules.combat.AutoKill; import de.com.baseband.client.feature.modules.combat.AutoTotem; import de.com.baseband.client.feature.modules.movement.ElytraBot; import de.com.baseband.client.feature.modules.movement.ElytraFly; @@ -32,8 +33,8 @@ public class Setup { // OPTIONAL new AltControl(), new AutoEat(), - //new AutoKill(), - //AutoKill.INSTANCE.autoHit, + new AutoKill(), + AutoKill.INSTANCE.autoHit, //AutoKill.INSTANCE.autoCrystal, new AntiLevitation(), new AutoTotem(), diff --git a/Client/src/main/java/de/com/baseband/client/feature/Feature.java b/Client/src/main/java/de/com/baseband/client/feature/Feature.java index f8baa85..2afe4b5 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/Feature.java +++ b/Client/src/main/java/de/com/baseband/client/feature/Feature.java @@ -294,7 +294,7 @@ public abstract class Feature extends ToggleButton implements SetCommand { return true; } - public boolean renderInHUD() { + public boolean displayOnHUD() { return true; } diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/client/Spotify.java b/Client/src/main/java/de/com/baseband/client/feature/modules/client/Spotify.java index 11278ea..8403eb7 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/client/Spotify.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/client/Spotify.java @@ -25,7 +25,7 @@ public class Spotify extends Feature { public boolean renderInHUD; @Override - public boolean renderInHUD() { + public boolean displayOnHUD() { return renderInHUD; } diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/combat/AutoKill.java b/Client/src/main/java/de/com/baseband/client/feature/modules/combat/AutoKill.java index 5c75b27..f801c49 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/combat/AutoKill.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/combat/AutoKill.java @@ -1,23 +1,38 @@ package de.com.baseband.client.feature.modules.combat; +import de.com.baseband.client.BaseBand; import de.com.baseband.client.feature.Feature; +import de.com.baseband.client.feature.Features; import de.com.baseband.client.feature.category.Combat; import de.com.baseband.client.registry.PlayerDB; import de.com.baseband.client.registry.annotation.Config; import de.com.baseband.client.registry.annotation.Gate; +import de.com.baseband.client.registry.annotation.Range; import de.com.baseband.client.util.adapt.Marker; import de.tudbut.parsing.TCN; +import de.tudbut.tools.Lock; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.network.play.client.CPacketUseEntity; +import net.minecraft.util.EnumHand; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.Vec3d; import java.util.ArrayList; +import java.util.List; @Combat public class AutoKill extends Feature { + public enum TargetMode { + Nearest, + Random, + Furthest, + LowestHealth, + HighestHealth, + } + public final AutoHit autoHit = new AutoHit(); public final AutoCrystal autoCrystal = new AutoCrystal(); @@ -34,12 +49,28 @@ public class AutoKill extends Feature { @Gate(1) public boolean attackTargets = true; + @Config("TargetMode") + public TargetMode targetMode = TargetMode.Nearest; + + @Config("Retarget time (ms)") + @Range("0..2000@100") + public int retargetTime = 300; + + @Config("Threaded") + public boolean threaded = false; + + @Config("PacketHit") + public boolean packetHit = false; + ArrayList getAttackable() { ArrayList allowed = new ArrayList<>(); for (Entity entity : mc.world.loadedEntityList) { if(!(entity instanceof EntityLivingBase)) continue; if(entity instanceof EntityPlayer) { + if(entity == mc.player || entity == mc.getRenderViewEntity()) + continue; + EntityPlayer player = (EntityPlayer) entity; TCN dbp = PlayerDB.player(player.getGameProfile().getId(), player.getGameProfile().getName()); assert dbp != null; @@ -67,16 +98,59 @@ public class AutoKill extends Feature { @Override protected void setup() { - subComponents.add(autoHit); - subComponents.add(autoCrystal); + Features.ifFeaturePresent(AutoHit.class, subComponents::add); + Features.ifFeaturePresent(AutoCrystal.class, subComponents::add); } - @Combat - public class AutoHit extends Feature { + private EntityLivingBase currentTarget = null; - @Override - public void onTick() { - Vec3d eyePos = mc.player.getPositionEyes(1f); + public EntityLivingBase getPreferred(List list) { + if(targetMode == TargetMode.Random) + return list.get(BaseBand.RANDOM.nextInt(list.size())); + + EntityLivingBase best = list.get(0); + for (EntityLivingBase entity : list) { + switch (targetMode) { + case Nearest: + if(entity.getDistanceSq(mc.player) < best.getDistanceSq(mc.player)) + best = entity; + break; + case Furthest: + if(entity.getDistanceSq(mc.player) > best.getDistanceSq(mc.player)) + best = entity; + break; + case LowestHealth: + if(entity.getHealth() < best.getHealth()) + best = entity; + break; + case HighestHealth: + if(entity.getHealth() > best.getHealth()) + best = entity; + break; + } + } + return best; + } + + public void hit(EntityLivingBase entity) { + if(packetHit) + mc.player.connection.sendPacket(new CPacketUseEntity(entity)); + else + mc.playerController.attackEntity(mc.player, entity); + + mc.player.swingArm(EnumHand.MAIN_HAND); + } + + private boolean retarget() { + Vec3d eyePos = mc.player.getPositionEyes(1f); + if(currentTarget != null) { + AxisAlignedBB boundingBox = currentTarget.getEntityBoundingBox(); + double dminsq = getDminsq(boundingBox, eyePos); + if (dminsq > 3 * 3) { + currentTarget = null; + } + } + if(currentTarget == null) { ArrayList attackable = getAttackable(); for (int i = 0; i < attackable.size(); i++) { EntityLivingBase elb = attackable.get(i); @@ -86,21 +160,12 @@ public class AutoKill extends Feature { attackable.remove(i--); } } - if(attackable.isEmpty()) - return; - + if (attackable.isEmpty()) + return false; + currentTarget = getPreferred(attackable); } - - @Override - public String toString() { - return "AutoHit"; - } - - @Override - public boolean displayOnClickGUI() { - return false; - } + return true; } private static double getDminsq(AxisAlignedBB boundingBox, Vec3d eyePos) { @@ -116,6 +181,70 @@ public class AutoKill extends Feature { return dmx * dmx + dmy * dmy + dmz * dmz; } + @Combat + public class AutoHit extends Feature { + + @Config("Speed (ms)") + @Range("10..500@5") + public int speed = 100; + private final Lock speedLock = new Lock(); + + private Thread thread; + + @Override + public void onTick() { + if(!AutoKill.this.enabled) + return; + if(notIngame()) + return; + if(threaded) { + if(thread == null) { + thread = new Thread(this::runThread, this + "Thread"); + thread.start(); + } + if(!thread.isAlive()) + thread = null; + return; + } + if(speedLock.isLocked()) + return; + speedLock.lock(speed); + run(); + } + + private void runThread() { + while (threaded) { + if(notIngame()) + break; + + speedLock.lock(speed); + run(); + speedLock.waitHere(); + } + } + + private void run() { + if (!retarget()) return; + + hit(currentTarget); + } + + @Override + public String toString() { + return "AutoHit"; + } + + @Override + public boolean displayOnClickGUI() { + return false; + } + + @Override + public boolean displayOnHUD() { + return AutoKill.this.enabled; + } + } + @Combat public class AutoCrystal extends Feature { @@ -133,5 +262,10 @@ public class AutoKill extends Feature { public boolean displayOnClickGUI() { return false; } + + @Override + public boolean displayOnHUD() { + return AutoKill.this.enabled; + } } } diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/player/InteractionTweaks.java b/Client/src/main/java/de/com/baseband/client/feature/modules/player/InteractionTweaks.java index f1dab76..7fdf3e7 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/player/InteractionTweaks.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/player/InteractionTweaks.java @@ -51,7 +51,7 @@ public class InteractionTweaks extends Feature { } @Override - public boolean renderInHUD() { + public boolean displayOnHUD() { return showOnHUD; } } @@ -118,7 +118,7 @@ public class InteractionTweaks extends Feature { } @Override - public boolean renderInHUD() { + public boolean displayOnHUD() { return showOnHUD; } } diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/render/HUD.java b/Client/src/main/java/de/com/baseband/client/feature/modules/render/HUD.java index 734e2db..2496b48 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/render/HUD.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/render/HUD.java @@ -225,7 +225,7 @@ public class HUD extends Feature { } int maxWidth = TextSplitter.getStringWidth(initString); - Feature[] renderFeatures = Arrays.stream(Features.features).filter(m -> m.enabled && m.category != Category.COMMAND && m.getClass() != Client.class && m != this && m.renderInHUD()).sorted(Comparator.comparingDouble(value -> -Minecraft.getMinecraft().fontRenderer.getStringWidth(includeStatus ? value.text : value.toString()))).toArray(Feature[]::new); + Feature[] renderFeatures = Arrays.stream(Features.features).filter(m -> m.enabled && m.category != Category.COMMAND && m.getClass() != Client.class && m != this && m.displayOnHUD()).sorted(Comparator.comparingDouble(value -> -Minecraft.getMinecraft().fontRenderer.getStringWidth(includeStatus ? value.text : value.toString()))).toArray(Feature[]::new); for (Feature f : renderFeatures) { maxWidth = Math.max(mc.fontRenderer.getStringWidth(f.getHUDText()), maxWidth); }