Advertisement
Corosus

Untitled

Jan 7th, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.27 KB | None | 0 0
  1. @Override
  2.     public void tickCollisionEntities() {
  3.         boolean volleyBallTest = true;
  4.        
  5.         float triggerDist = 4.0F;
  6.        
  7.         if (volleyBallTest) {
  8.             double size = 1D;
  9.             List entities = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.expand(size, size, size));
  10.            
  11.             for (int i = 0; entities != null && i < entities.size(); ++i)
  12.             {
  13.                 Entity var10 = (Entity)entities.get(i);
  14.                
  15.                 if (var10 != null) {
  16.                     if (!var10.isDead) {
  17.                         if (var10 instanceof EntityPlayer) {
  18.                             EntityPlayer entP = (EntityPlayer)var10;
  19.                            
  20.                             if (entP.swingProgress > 0.2F) {
  21.                                 double speed = Math.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
  22.                                 System.out.println("dist: " + var10.getDistanceToEntity(this));
  23.                                 if (var10.getDistanceToEntity(this) < triggerDist) {
  24.                                     System.out.println("hit ball!");
  25.                                     hitEvent(this, var10);
  26.                                 }
  27.                             }
  28.                         }
  29.                     }
  30.                 }
  31.             }
  32.         }
  33.     }
  34.    
  35.     public void hitEvent(Entity ball, Entity player) {
  36.        
  37.         float hitPower = 0.5F;
  38.        
  39.         double vecX = ball.posX - player.posX;
  40.         double vecY = ball.posY - player.posY;
  41.         double vecZ = ball.posZ - player.posZ;
  42.        
  43.         Vec3 vecBallToPlayer = Vec3.createVectorHelper(vecX, vecY, vecZ).normalize();
  44.         Vec3 vecThrust = getHitAim(player).normalize();
  45.        
  46.         //invert z to fix things
  47.         vecThrust.zCoord *= -1;
  48.        
  49.         vecThrust.xCoord *= hitPower;
  50.         vecThrust.yCoord *= hitPower;
  51.         vecThrust.zCoord *= hitPower;
  52.        
  53.         ball.motionX = vecThrust.xCoord;
  54.         ball.motionY = vecThrust.yCoord;
  55.         ball.motionZ = vecThrust.zCoord;
  56.        
  57.         //more adjustments
  58.         ball.motionY += 0.3F;
  59.     }
  60.    
  61.     public Vec3 getHitAim(Entity ent) {
  62.         float f1 = MathHelper.cos(ent.rotationYaw * 0.017453292F/* - (float)Math.PI*/);
  63.         float f2 = MathHelper.sin(ent.rotationYaw * 0.017453292F/* - (float)Math.PI*/);
  64.         float f3 = -MathHelper.cos(-ent.rotationPitch * 0.017453292F);
  65.         float f4 = MathHelper.sin(-ent.rotationPitch * 0.017453292F);
  66.         return Vec3.createVectorHelper((double)(f2 * f3), (double)f4, (double)(f1 * f3));
  67.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement