Advertisement
peacestorm

getNearestMob

Jun 13th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getNearestMob(range, minRange) {
  2.     let mobs = Entity.getAll();
  3.     if(targetMobsSetting == "on") {
  4.         for(let i = 0; i < mobs.length; i++) {
  5.             let ent = mobs[i];
  6.             let x = Entity.getX(ent) - getPlayerX();
  7.             let y = Entity.getY(ent) - getPlayerY();
  8.             let z = Entity.getZ(ent) - getPlayerZ();
  9.             if(x*x+y*y+z*z>range*range) {
  10.                 continue;
  11.             }
  12.             if(minRange != null) {
  13.                 if(x*x+y*y+z*z<=minRange*minRange) {
  14.                     continue;
  15.                 }
  16.             }
  17.             if(Entity.getEntityTypeId(ent) != EntityType.ARROW && Entity.getEntityTypeId(ent) != EntityType.BOAT && Entity.getEntityTypeId(ent) != EntityType.EGG && Entity.getEntityTypeId(ent) != EntityType.ENDER_PEARL && Entity.getEntityTypeId(ent) != EntityType.EXPERIENCE_ORB && Entity.getEntityTypeId(ent) != EntityType.EXPERIENCE_POTION && Entity.getEntityTypeId(ent) != EntityType.FALLING_BLOCK && Entity.getEntityTypeId(ent) != EntityType.FIREBALL && Entity.getEntityTypeId(ent) != EntityType.FISHING_HOOK && Entity.getEntityTypeId(ent) != EntityType.ITEM && Entity.getEntityTypeId(ent) != EntityType.LIGHTNING_BOLT && Entity.getEntityTypeId(ent) != EntityType.MINECART && Entity.getEntityTypeId(ent) != EntityType.PAINTING && Entity.getEntityTypeId(ent) != EntityType.PRIMED_TNT && Entity.getEntityTypeId(ent) != EntityType.SMALL_FIREBALL && Entity.getEntityTypeId(ent) != EntityType.SNOWBALL && Entity.getEntityTypeId(ent) != EntityType.THROWN_POTION && ent != getPlayerEnt()) {
  18.                 return ent;
  19.             }
  20.         }
  21.     }
  22.     return null;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement