Advertisement
Corosus

fleeeee

Jul 6th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.19 KB | None | 0 0
  1. public void fleeFrom(Entity fleeFrom) {
  2.         //ent field rerouting!
  3.         EntityLiving ent = c_AIP.i.player;
  4.         /*this.faceEntity(fleeFrom, 180F, 180F);
  5.         //this.rotationYaw += 180;
  6.        
  7.         double d1 = posX - fleeFrom.posX;
  8.         double d2 = posZ - fleeFrom.posZ;
  9.         float f2 = (float)((Math.atan2(d2, d1) * 180D) / 3.1415927410125732D) - 90F;
  10.         float f3 = f2 - rotationYaw;
  11.        
  12.         rotationYaw = updateRotation2(rotationYaw, f3, 360F);*/
  13.        
  14.         double d = fleeFrom.posX - ent.posX;
  15.         double d1;
  16.         for (d1 = fleeFrom.posZ - ent.posZ; d * d + d1 * d1 < 0.0001D; d1 = (Math.random() - Math.random()) * 0.01D)
  17.         {
  18.             d = (Math.random() - Math.random()) * 0.01D;
  19.         }
  20.         float f = MathHelper.sqrt_double(d * d + d1 * d1);
  21.  
  22.         //knockBack(entity, i, d, d1);
  23.        
  24.         float yaw = (float)((Math.atan2(d1, d) * 180D) / 3.1415927410125732D)/* - ent.rotationYaw*/;
  25.        
  26.         float look = ent.worldObj.rand.nextInt(15)-7;
  27.         //int height = 10;
  28.         double dist = ent.worldObj.rand.nextInt(2)+4;
  29.        
  30.         //dist adjuster
  31.         if (fleeFrom instanceof EntityCreeper) {
  32.             dist = ent.worldObj.rand.nextInt(8)+8;
  33.         }
  34.        
  35.         int gatherX = (int)(ent.posX + ((double)(-Math.sin((yaw+look) / 180.0F * 3.1415927F) * Math.cos(ent.rotationPitch / 180.0F * 3.1415927F)) * dist));
  36.         int gatherY = (int)(ent.posY-0.5 + (double)(-MathHelper.sin(ent.rotationPitch / 180.0F * 3.1415927F) * dist) - 0D); //center.posY - 0D;
  37.         int gatherZ = (int)(ent.posZ + ((double)(Math.cos((yaw+look) / 180.0F * 3.1415927F) * Math.cos(ent.rotationPitch / 180.0F * 3.1415927F)) * dist));
  38.        
  39.         gatherX = (int)(ent.posX - (d / f * dist));
  40.         gatherZ = (int)(ent.posZ - (d1 / f * dist));
  41.        
  42.         int id = ent.worldObj.getBlockId(gatherX, gatherY, gatherZ);
  43.         int id2 = ent.worldObj.getBlockId(gatherX, gatherY+1, gatherZ);
  44.        
  45.         int offset = 0;
  46.        
  47.         int finalY = gatherY;
  48.        
  49.         while (offset < 10) {
  50.             if (id != 0 && id2 == 0) {
  51.                 finalY += offset;
  52.                 break;
  53.             }
  54.            
  55.             //id = ent.worldObj.getBlockId(gatherX, gatherY+offset++, gatherZ);
  56.             id = ent.worldObj.getBlockId(gatherX, gatherY-offset, gatherZ);
  57.             id2 = ent.worldObj.getBlockId(gatherX, gatherY-offset+1, gatherZ);
  58.            
  59.             if (id != 0 && id2 == 0) {
  60.                 finalY -= offset;
  61.                 break;
  62.             }
  63.            
  64.             //id = ent.worldObj.getBlockId(gatherX, gatherY+offset++, gatherZ);
  65.             id = ent.worldObj.getBlockId(gatherX, gatherY+offset, gatherZ);
  66.             id2 = ent.worldObj.getBlockId(gatherX, gatherY+offset+1, gatherZ);
  67.            
  68.             offset++;
  69.         }
  70.        
  71.         if (offset < 10) {
  72.             System.out.println("flee");
  73.             //if (c_AIP.i.pathToEntity == null) {
  74.                 c_AIP.i.walkTo(ent, gatherX, finalY, gatherZ, maxPFRange , 600, -1);
  75.             //}
  76.             //this.walkTo(this, homeX, homeY, homeZ, maxPFRange, 600);
  77.         } else {
  78.             //System.out.println("flee failed");
  79.             //c_AIP.i.walkTo(ent, c_AIP.i.homeX, c_AIP.i.homeY, c_AIP.i.homeZ, maxPFRange, 600, -1);
  80.         }
  81.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement