Advertisement
Corosus

Tornadoes spin function

Jan 25th, 2012
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.60 KB | None | 0 0
  1. public static void spin(Entity entity, WeatherEntityConfig conf, Entity entity1) {
  2.        
  3.        
  4.         double maxHeight = tornadoHeight;
  5.         double radius = 10D;
  6.         double scale = conf.tornadoWidthScale;
  7.         double d1 = entity.posX - entity1.posX;
  8.         double d2 = entity.posZ - entity1.posZ;
  9.         float f = (float)((Math.atan2(d2, d1) * 180D) / 3.1415927410125732D) - 90F;
  10.         float f1;
  11.  
  12.         for(f1 = f; f1 < -180F; f1 += 360F) { }
  13.  
  14.         for(; f1 >= 180F; f1 -= 360F) { }
  15.  
  16.         double distY = entity.posY - entity1.posY;
  17.         double distXZ = Math.sqrt(Math.abs(d1)) + Math.sqrt(Math.abs(d2));
  18.  
  19.         if(entity1.posY - entity.posY < 0.0D) {
  20.             distY = 1.0D;
  21.         } else {
  22.             distY = entity1.posY - entity.posY;
  23.         }
  24.  
  25.         if(distY > maxHeight) {
  26.             distY = maxHeight;
  27.         }
  28.  
  29.         double grab = (10D / getWeight(entity1))/* / ((distY / maxHeight) * 1D)*/ * ((Math.abs((maxHeight - distY)) / maxHeight));
  30.         float pullY = 0.0F;
  31.  
  32.         //some random y pull
  33.         if (entity.rand.nextInt(5) != 0) {
  34.             //pullY = 0.035F;
  35.         }
  36.  
  37.         if(distXZ > 5D) {
  38.             grab = grab * (radius / distXZ);
  39.         }
  40.  
  41.         pullY += (float)(conf.tornadoLiftRate / (getWeight(entity1) / 2F)/* * (Math.abs(radius - distXZ) / radius)*/);
  42.         //} else {
  43.         //pullY = pullY / getWeight(entity1);
  44.         //}
  45.  
  46.         if  (entity1 instanceof EntityPlayer) {
  47.             double adjPull = 0.2D / ((getWeight(entity1) * ((distXZ+1D) / radius)));
  48.             /*if (!entity1.onGround) {
  49.                 adjPull /= (((float)(((double)playerInAirTime+1D) / 200D)) * 15D);
  50.  
  51.             }*/
  52.             pullY += adjPull;
  53.             //0.2D / ((getWeight(entity1) * ((distXZ+1D) / radius)) * (((distY) / maxHeight)) * 3D);
  54.             //grab = grab + (10D * ((distY / maxHeight) * 1D));
  55.             double adjGrab = (10D * (((float)(((double)playerInAirTime+1D) / 200D))));
  56.  
  57.             if (adjGrab > 50) {
  58.                 adjGrab = 50D;
  59.             }
  60.  
  61.             grab = grab - adjGrab;
  62.  
  63.             if (entity1.motionY > -2.0) {
  64.                 entity1.fallDistance = 0F;
  65.             }
  66.  
  67.             //System.out.println(adjPull);
  68.         } else if (entity1 instanceof EntityLiving) {
  69.             double adjPull = 0.005D / ((getWeight(entity1) * ((distXZ+1D) / radius)));
  70.             /*if (!entity1.onGround) {
  71.                 adjPull /= (((float)(((double)playerInAirTime+1D) / 200D)) * 15D);
  72.  
  73.             }*/
  74.             pullY -= adjPull;
  75.             //0.2D / ((getWeight(entity1) * ((distXZ+1D) / radius)) * (((distY) / maxHeight)) * 3D);
  76.             //grab = grab + (10D * ((distY / maxHeight) * 1D));
  77.             double adjGrab = (10D * (((float)(((double)(((EntityLiving)entity1).entityAge + 150)+1D) / 200D))));
  78.  
  79.             if (adjGrab > 50) {
  80.                 adjGrab = 50D;
  81.             }
  82.  
  83.             grab = grab - adjGrab;
  84.  
  85.            
  86.  
  87.             if (entity1.motionY > -2.0) {
  88.                 entity1.fallDistance = 0F;
  89.             }
  90.  
  91.             //System.out.println(adjPull);
  92.         }
  93.        
  94.         if (debug) {
  95.            
  96.             //globals
  97.             //tornadoMaxParticles = 2200;
  98.             //tornadoMaxBlocks = 1000;
  99.             //rarityOfDisintegrate = 150;
  100.             //rarityOfBreakOnFall = 5;
  101.            
  102.             //mod_EntMover.activeTornado.getStorm().tor
  103.            
  104.             //temp debugs
  105.             //tornadoInitialSpeed = 0.0F;
  106.             //grabPlayer = false;
  107.            
  108.             //mod_EntMover.activeTornado.getStorm().tornadoInitialSpeed = 0.0F;
  109.            
  110.         }
  111.  
  112.         grab += conf.relTornadoSize;
  113.        
  114.         f1 = (float)((double)f1 + (75D + grab - (10D * scale)));
  115.         float f3 = (float)Math.cos(-f1 * 0.01745329F - 3.141593F);
  116.         float f4 = (float)Math.sin(-f1 * 0.01745329F - 3.141593F);
  117.         float f5 = conf.tornadoPullRate;
  118.  
  119.         if  (entity1 instanceof EntityPlayer || entity1 instanceof EntityLiving) {
  120.             f5 /= (getWeight(entity1) * ((distXZ+1D) / radius));
  121.         }
  122.  
  123.         float moveX = f3 * f5;
  124.         float moveZ = f4 * f5;
  125.         //tornado strength changes
  126.         float str = 1F;
  127.         if (entity instanceof EntTornado) {
  128.             str = ((EntTornado)entity).strength;
  129.         }
  130.         pullY *= str / 100F;
  131.         setVel(entity1, -moveX, pullY, moveZ);
  132.         //player Yaxis safety check
  133.         /*if  (entity1 instanceof EntityPlayer && entity1.posY > 100D) {
  134.             entity1.posY = 100D;
  135.             //entity1.motionY -= 1.0D;
  136.             entity1.setPosition(entity1.posX, entity1.posY, entity1.posZ);
  137.         }*/
  138.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement