Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 14.48 KB | None | 0 0
  1. public class Killaura extends Module {
  2.  
  3.     private final NumberValue<Double> range = new NumberValue<>("Range",4.0,1.0,6.0);
  4.     private final NumberValue<Double> cps = new NumberValue<>("CPS",10.0,1.0,20.0);
  5.     private final NumberValue<Double> miss = new NumberValue<>("Miss rate",0.0,0.0,100.0);
  6.     private final NumberValue<Double> fov = new NumberValue<>("FOV",180.0,0.0,180.0);
  7.  
  8.     private BooleanValue randomCps = new BooleanValue("Random cps", false);
  9.     private BooleanValue invisibles = new BooleanValue("Invisibles", false);
  10.     private BooleanValue ghosthand = new BooleanValue("Ghosthand", false);
  11.     private BooleanValue mobs = new BooleanValue("Mobs", false);
  12.     private BooleanValue slowdown = new BooleanValue("Slowdown", false);
  13.     private BooleanValue inventory = new BooleanValue("Inventory", false);
  14.     private BooleanValue autoblock = new BooleanValue("Autoblock", false);
  15.  
  16.     private ModeValue mode = new ModeValue("Mode", "Nearest");
  17.  
  18.     private int inFight = 0;
  19.     public boolean isLooking = false;
  20.     private Entity lastAttacked = null;
  21.     private Entity switchTarget = null;
  22.     private boolean attackedSwitch = false;
  23.     private ArrayList<Entity> attackHistory = new ArrayList();
  24.     private Entity lastLooked = null;
  25.     private double delay = 0.0;
  26.     public boolean isBlocking = false;
  27.  
  28.     public Killaura() {
  29.         super("Killaura", "Automatically attacks entities in range.", Category.COMBAT);
  30.         mode.getModes().add("Nearest");
  31.         mode.getModes().add("Cross");
  32.         mode.getModes().add("Switch");
  33.         getValues().add(range);
  34.         getValues().add(cps);
  35.         getValues().add(miss);
  36.         getValues().add(fov);
  37.         getValues().add(randomCps);
  38.         getValues().add(invisibles);
  39.         getValues().add(ghosthand);
  40.         getValues().add(mobs);
  41.         getValues().add(slowdown);
  42.         getValues().add(inventory);
  43.         getValues().add(autoblock);
  44.         getValues().add(mode);
  45.     }
  46.  
  47.     @Subscribe
  48.     public void onUpdate(EventUpdate e){
  49.         if (!this.isEnabled()) {
  50.             this.lastLooked = null;
  51.             this.lastAttacked = null;
  52.             this.noAtack();
  53.             this.isLooking = false;
  54.             return;
  55.         }
  56.         if (mc.thePlayer.hurtTime > 0) {
  57.             this.inFight = 20;
  58.         } else if (this.inFight > 0) {
  59.             --this.inFight;
  60.         }
  61.         if (this.slowdown.isEnabled() && this.isBlocking) {
  62.             mc.thePlayer.motionX /= 1.1;
  63.             mc.thePlayer.motionZ /= 1.1;
  64.         }
  65.         if (mc.currentScreen != null && !this.inventory.isEnabled()) {
  66.             this.noAtack();
  67.             this.isLooking = false;
  68.             return;
  69.         }
  70.         ArrayList<Entity> possibleTargets = this.getTargets();
  71.         if (possibleTargets.isEmpty()) {
  72.             this.noAtack();
  73.             this.isLooking = false;
  74.             return;
  75.         }
  76.         Entity target = this.chooseTarget(possibleTargets);
  77.         if (mode.getValue().equalsIgnoreCase("switch")) {
  78.             this.switchTarget = target;
  79.         }
  80.         Entity attackTarget = this.getRaycastTarget(target);
  81.         this.isLooking = true;
  82.         boolean look = this.updateLook(target, attackTarget);
  83.         if (look) {
  84.             this.prepareAttack(target, attackTarget);
  85.         } else {
  86.             this.noAtack();
  87.         }
  88.     }
  89.  
  90.     private ArrayList<Entity> getTargets() {
  91.         ArrayList<Entity> possible = new ArrayList<Entity>();
  92.         for (Entity e : mc.theWorld.loadedEntityList) {
  93.             double distance;
  94.             EntityPlayer player;
  95.             if (e.equals(mc.thePlayer) || (this.mobs.isEnabled() ? !(e instanceof EntityLiving) && !(e instanceof EntityPlayer) : !(e instanceof EntityPlayer))) continue;
  96.             if (e.isInvisibleToPlayer(mc.thePlayer) && !this.invisibles.isEnabled() || e instanceof EntityPlayer && /*(AntiBots.instance.isBot(player = (EntityPlayer)e) || !this.isTarget(player)) || */ !this.ghosthand.isEnabled() && !mc.thePlayer.canEntityBeSeen(e) || (distance = this.getDistanceToEntity(e)) > this.range.getValue() || this.fov.getValue() < 180.0 && !this.isInsideAngle(e)) continue;
  97.             possible.add(e);
  98.         }
  99.         return possible;
  100.     }
  101.  
  102.     boolean isTarget(EntityPlayer player) {
  103.         return !Client.getInstance().getModuleManager().find("Teams").isEnabled() || !Teams.isInTeam(player);
  104.     }
  105.  
  106.     private boolean isInsideAngle(Entity e) {
  107.         double y;
  108.         double xDiff = e.posX - mc.thePlayer.posX;
  109.         double zDiff = e.posZ - mc.thePlayer.posZ;
  110.         double angle = Math.toDegrees(Math.atan2(xDiff, zDiff)) + (double)mc.thePlayer.rotationYaw;
  111.         double x = Math.sin(Math.toRadians(angle));
  112.         double a = Math.toDegrees(Math.atan2(x, y = Math.cos(Math.toRadians(angle))));
  113.         return Math.abs(a) < this.fov.getValue();
  114.     }
  115.  
  116.     private Entity chooseTarget(ArrayList<Entity> targets) {
  117.         if (mode.getValue().equalsIgnoreCase("nearest")) {
  118.             return this.getNearest(targets);
  119.         }
  120.         if (mode.getValue().equalsIgnoreCase("switch")) {
  121.             if (this.switchTarget == null || this.getDistanceToEntity(this.switchTarget) > this.range.getValue() + 0.5) {
  122.                 this.attackedSwitch = false;
  123.                 return this.getNearest(targets);
  124.             }
  125.             if (this.attackedSwitch) {
  126.                 this.attackedSwitch = false;
  127.                 for (Entity e : targets) {
  128.                     if (this.attackHistory.contains(e)) continue;
  129.                     return e;
  130.                 }
  131.                 this.attackHistory.clear();
  132.                 return this.getNearest(targets);
  133.             }
  134.             return this.switchTarget;
  135.         }
  136.         if (mode.getValue().equalsIgnoreCase("cross")) {
  137.             return this.getNearestToCross(targets);
  138.         }
  139.         if (targets.contains(this.lastAttacked)) {
  140.             return this.lastAttacked;
  141.         }
  142.         return this.getNearest(targets);
  143.     }
  144.  
  145.     private Entity getNearest(ArrayList<Entity> targets) {
  146.         if (targets.size() == 1) {
  147.             return targets.get(0);
  148.         }
  149.         Entity nearest = targets.get(0);
  150.         double diff = this.getDistanceToEntity(nearest);
  151.         for (Entity e : targets) {
  152.             double newDiff;
  153.             if (e.equals(nearest) || !((newDiff = this.getDistanceToEntity(e)) < diff)) continue;
  154.             nearest = e;
  155.             diff = newDiff;
  156.         }
  157.         return nearest;
  158.     }
  159.  
  160.     private Entity getNearestToCross(ArrayList<Entity> targets) {
  161.         if (targets.size() == 1) {
  162.             return targets.get(0);
  163.         }
  164.         double diff = 180.0;
  165.         Entity nearest = targets.get(0);
  166.         for (Entity e : targets) {
  167.             double y;
  168.             double xDiff = e.posX - mc.thePlayer.posX;
  169.             double zDiff = e.posZ - mc.thePlayer.posZ;
  170.             double angle = Math.toDegrees(Math.atan2(xDiff, zDiff)) + (double)mc.thePlayer.rotationYaw;
  171.             double x = Math.sin(Math.toRadians(angle));
  172.             double a = Math.abs(Math.toDegrees(Math.atan2(x, y = Math.cos(Math.toRadians(angle)))));
  173.             if (!(a < diff)) continue;
  174.             diff = a;
  175.             nearest = e;
  176.         }
  177.         return nearest;
  178.     }
  179.  
  180.     private double getDistanceToEntity(Entity e) {
  181.         Location3D playerEye = new Location3D(mc.thePlayer.posX, mc.thePlayer.posY + (double)mc.thePlayer.getEyeHeight(), mc.thePlayer.posZ);
  182.         Location3D targetBody = new Location3D(e.posX, e.getEntityBoundingBox().minY + (e.getEntityBoundingBox().maxY - e.getEntityBoundingBox().minY) / 2.0, e.posZ);
  183.         return playerEye.distance(targetBody);
  184.     }
  185.  
  186.     private Entity getRaycastTarget(Entity target) {
  187.         ArrayList<Entity> inRange = new ArrayList<Entity>();
  188.         for (Entity e : mc.theWorld.loadedEntityList) {
  189.             if (!(e instanceof EntityLiving) && !(e instanceof EntityPlayer) || e.equals(mc.thePlayer) || this.getDistanceToEntity(e) > 6.0) continue;
  190.             inRange.add(e);
  191.         }
  192.         if (inRange.size() == 1 && ((Entity)inRange.get(0)).equals(target)) {
  193.             return target;
  194.         }
  195.         Location3D playerEye = new Location3D(mc.thePlayer.posX, mc.thePlayer.posY + (double)mc.thePlayer.getEyeHeight(), mc.thePlayer.posZ);
  196.         Location3D targetBody = new Location3D(target.posX, target.getEntityBoundingBox().minY + (target.getEntityBoundingBox().maxY - target.getEntityBoundingBox().minY) / 2.0, target.posZ);
  197.         Line3D line = new Line3D(playerEye, targetBody);
  198.         for (Location3D point : line.getPointsOn(0.10000000149011612)) {
  199.             ArrayList<Entity> inside = new ArrayList<Entity>();
  200.             for (Entity e : inRange) {
  201.                 if (!this.isInsideEntity(e, point.getX(), point.getY(), point.getZ())) continue;
  202.                 inside.add(e);
  203.             }
  204.             if (inside.isEmpty()) continue;
  205.             return this.getNearest(inside);
  206.         }
  207.         return target;
  208.     }
  209.  
  210.     private boolean isInsideEntity(Entity e, double x, double y, double z) {
  211.         boolean inZ;
  212.         boolean inX = e.getEntityBoundingBox().minX < x && e.getEntityBoundingBox().maxX > x;
  213.         boolean inY = e.getEntityBoundingBox().minY < y && e.getEntityBoundingBox().maxY > y;
  214.         boolean bl = inZ = e.getEntityBoundingBox().minZ < z && e.getEntityBoundingBox().maxZ > z;
  215.         return inX && inY && inZ;
  216.     }
  217.  
  218.     private boolean updateLook(Entity target, Entity attackTarget) {
  219.         if (this.getDistanceToEntity(target) < 0.8) {
  220.             this.lastLooked = target;
  221.             return true;
  222.         }
  223.         double hitboxX = target.getEntityBoundingBox().maxX - target.getEntityBoundingBox().minX;
  224.         double hitboxY = target.getEntityBoundingBox().maxY - target.getEntityBoundingBox().minY;
  225.         double hitboxZ = target.getEntityBoundingBox().maxZ - target.getEntityBoundingBox().minZ;
  226.         double randomXOff = 0.0;
  227.         double randomYOff = 0.0;
  228.         double randomZOff = 0.0;
  229.         randomXOff = Math.random() * hitboxX - hitboxX / 2.0;
  230.         randomYOff = Math.random() * hitboxY - hitboxY / 2.0 + mc.thePlayer.motionY*0.6;
  231.         randomZOff = Math.random() * hitboxZ - hitboxZ / 2.0;
  232.  
  233.         Location3D playerEye = new Location3D(mc.thePlayer.posX, mc.thePlayer.posY + (double)mc.thePlayer.getEyeHeight(), mc.thePlayer.posZ);
  234.         Location3D targetBody = new Location3D(target.posX, target.getEntityBoundingBox().minY + (target.getEntityBoundingBox().maxY - target.getEntityBoundingBox().minY) / 2.0, target.posZ);
  235.         targetBody.add(randomXOff, randomYOff, randomZOff);
  236.         BlickWinkel3D cam = new BlickWinkel3D(playerEye, targetBody);
  237.         float yaw = (float)cam.getYaw();
  238.         float pitch = (float)cam.getPitch();
  239.         Wrapper.setNextPitch(pitch);
  240.         Wrapper.setNextYaw(yaw);
  241.         if (this.slowdown.isEnabled() && mc.thePlayer.onGround) {
  242.             Line3D view = new Line3D(playerEye, mc.thePlayer.rotationYaw, 0.0, 1.0);
  243.             Line3D simView = new Line3D(playerEye, yaw, 0.0, 1.0);
  244.             double diff = view.getEnd().distance(simView.getEnd());
  245.             if (diff > 0.8) {
  246.                 mc.thePlayer.motionX /= 1.2000000476837158;
  247.                 mc.thePlayer.motionZ /= 1.2000000476837158;
  248.             }
  249.         }
  250.         boolean looked = target.equals(this.lastLooked);
  251.         this.lastLooked = target;
  252.         return looked;
  253.     }
  254.  
  255.     private void prepareAttack(Entity target, Entity attackTarget) {
  256.         this.delay = this.randomCps.isEnabled() ? (this.delay += Math.sin(System.currentTimeMillis() / 500L) / 3.0 + 1.0 + (Math.random() / 2.0 - 0.25)) : (this.delay += 1.0);
  257.         double delay_target = 20.0 / this.cps.getValue();
  258.         if (this.delay < delay_target) {
  259.             this.noAtack();
  260.             return;
  261.         }
  262.         this.delay -= delay_target;
  263.         if (this.miss.getValue() > 0.0 && Math.random() < this.miss.getValue() / 100.0) {
  264.             this.noAtack();
  265.             mc.thePlayer.swingItem();
  266.             return;
  267.         }
  268.         this.lastAttacked = target;
  269.         if (mode.getValue().equalsIgnoreCase("switch")) {
  270.             this.attackHistory.add(target);
  271.         }
  272.         this.attackedSwitch = true;
  273.         this.attackEntity(attackTarget);
  274.     }
  275.  
  276.     private void attackEntity(Entity attack) {
  277.         if (this.isBlocking) {
  278.             this.unblock();
  279.         }
  280.         /*if (AutoSword.instance.isEnabled()) {
  281.             AutoSword.takeSword();
  282.         }*/
  283.         mc.thePlayer.swingItem();
  284.         /*if (KnockbackPlus.instance.isEnabled()) {
  285.             mc.thePlayer.sendQueue.addToSendQueue(new C0BPacketEntityAction(mc.thePlayer, C0BPacketEntityAction.Action.STOP_SPRINTING));
  286.             mc.thePlayer.sendQueue.addToSendQueue(new C0BPacketEntityAction(mc.thePlayer, C0BPacketEntityAction.Action.START_SPRINTING));
  287.             Wrapper.mc.getNetHandler().getNetworkManager().sendPacket(new C02PacketUseEntity(attack, C02PacketUseEntity.Action.ATTACK));
  288.             mc.thePlayer.sendQueue.addToSendQueue(new C0BPacketEntityAction(mc.thePlayer, C0BPacketEntityAction.Action.STOP_SPRINTING));
  289.         } else {*/
  290.             Wrapper.mc.getNetHandler().getNetworkManager().sendPacket(new C02PacketUseEntity(attack, C02PacketUseEntity.Action.ATTACK));
  291.         //}
  292.         Wrapper.mc.thePlayer.onCriticalHit(attack);
  293.         if (!(!this.autoblock.isEnabled() || this.inFight <= 0 || mc.thePlayer.onGround && this.slowdown.isEnabled())) {
  294.             this.block();
  295.         }
  296.     }
  297.  
  298.     private void noAtack() {
  299.         if (this.isBlocking) {
  300.             this.unblock();
  301.         }
  302.     }
  303.  
  304.     private void unblock() {
  305.         this.isBlocking = false;
  306.         if (Wrapper.mc.thePlayer.getCurrentEquippedItem() != null && Wrapper.mc.thePlayer.getCurrentEquippedItem().getItem() instanceof ItemSword) {
  307.             C07PacketPlayerDigging unblock = new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.RELEASE_USE_ITEM, new BlockPos(0, 0, 0), EnumFacing.DOWN);
  308.             Wrapper.mc.thePlayer.sendQueue.addToSendQueue(unblock);
  309.         }
  310.     }
  311.  
  312.     private void block() {
  313.         if (Wrapper.mc.thePlayer.getCurrentEquippedItem() != null && Wrapper.mc.thePlayer.getCurrentEquippedItem().getItem() instanceof ItemSword) {
  314.             this.isBlocking = true;
  315.             C08PacketPlayerBlockPlacement block = new C08PacketPlayerBlockPlacement(new BlockPos(-1, -1, -1), 255, Wrapper.mc.thePlayer.getCurrentEquippedItem(), 0.0f, 0.0f, 0.0f);
  316.             Wrapper.mc.thePlayer.sendQueue.addToSendQueue(block);
  317.         }
  318.     }
  319.  
  320. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement