Package com.flansmod.common.guns.raytracing

Examples of com.flansmod.common.guns.raytracing.PlayerBulletHit


                    else if(dPos.z != 0F)
                      hitLambda = hitPoint.z / dPos.z;
                    if(hitLambda < 0)
                      hitLambda = -hitLambda;
                   
                    hits.add(new PlayerBulletHit(new PlayerHitbox(otherPlayer, new RotatedAxes(), new Vector3f(), new Vector3f(), new Vector3f(), EnumHitboxType.BODY), hitLambda));
                  }
                }
              }
              else
              {
                Entity entity = (Entity)obj;
                if(entity != player && !entity.isDead && (entity instanceof EntityLivingBase || entity instanceof EntityAAGun))
                {
                  MovingObjectPosition mop = entity.boundingBox.calculateIntercept(data.lastMeleePositions[k].toVec3(), nextPosInWorldCoords.toVec3());
                  if(mop != null)
                  {
                    Vector3f hitPoint = new Vector3f(mop.hitVec.xCoord - data.lastMeleePositions[k].x, mop.hitVec.yCoord - data.lastMeleePositions[k].y, mop.hitVec.zCoord - data.lastMeleePositions[k].z);
                    float hitLambda = 1F;
                    if(dPos.x != 0F)
                      hitLambda = hitPoint.x / dPos.x;
                    else if(dPos.y != 0F)
                      hitLambda = hitPoint.y / dPos.y;
                    else if(dPos.z != 0F)
                      hitLambda = hitPoint.z / dPos.z;
                    if(hitLambda < 0)
                      hitLambda = -hitLambda;
                   
                    hits.add(new EntityHit(entity, hitLambda));
                  }
                }
              }
            }
           
            //We hit something
            if(!hits.isEmpty())
            {
              //Sort the hits according to the intercept position
              Collections.sort(hits);
             
              float swingDistance = dPos.length();
             
              for(BulletHit bulletHit : hits)
              {
                if(bulletHit instanceof PlayerBulletHit)
                {
                  PlayerBulletHit playerHit = (PlayerBulletHit)bulletHit;
                  float damageMultiplier = 1F;
                  switch(playerHit.hitbox.type)
                  {
                  case LEFTITEM : case RIGHTITEM : //Hit a shield. Stop the swing.
                  {
View Full Code Here


            else if(motion.z != 0F)
              hitLambda = hitPoint.z / motion.z;
            if(hitLambda < 0)
              hitLambda = -hitLambda;
           
            hits.add(new PlayerBulletHit(new PlayerHitbox(player, new RotatedAxes(), new Vector3f(), new Vector3f(), new Vector3f(), EnumHitboxType.BODY), hitLambda));
          }
        }
      }
      else
      {
        Entity entity = (Entity)obj;
        if(entity != this && entity != owner && !entity.isDead && (entity instanceof EntityLivingBase || entity instanceof EntityAAGun || entity instanceof EntityGrenade))
        {
          MovingObjectPosition mop = entity.boundingBox.calculateIntercept(origin.toVec3(), Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ));
          if(mop != null)
          {
            Vector3f hitPoint = new Vector3f(mop.hitVec.xCoord - posX, mop.hitVec.yCoord - posY, mop.hitVec.zCoord - posZ);
            float hitLambda = 1F;
            if(motion.x != 0F)
              hitLambda = hitPoint.x / motion.x;
            else if(motion.y != 0F)
              hitLambda = hitPoint.y / motion.y;
            else if(motion.z != 0F)
              hitLambda = hitPoint.z / motion.z;
            if(hitLambda < 0)
              hitLambda = -hitLambda;
           
            hits.add(new EntityHit(entity, hitLambda));
          }
        }
      }
    }
   
    //Ray trace the bullet by comparing its next position to its current position
    Vec3 posVec = Vec3.createVectorHelper(posX, posY, posZ);
    Vec3 nextPosVec = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ);
    MovingObjectPosition hit = worldObj.func_147447_a(posVec, nextPosVec, false, true, true);
   
    posVec = Vec3.createVectorHelper(posX, posY, posZ);
   
    if(hit != null)
    {
      //Calculate the lambda value of the intercept
      Vec3 hitVec = posVec.subtract(hit.hitVec);
      float lambda = 1;
      //Try each co-ordinate one at a time.
      if(motionX != 0)
        lambda = (float)(hitVec.xCoord / motionX);
      else if(motionY != 0)
        lambda = (float)(hitVec.yCoord / motionY);
      else if(motionZ != 0)
        lambda = (float)(hitVec.zCoord / motionZ);
     
      if(lambda < 0)
        lambda = -lambda;
      hits.add(new BlockHit(hit, lambda));
    }
       
    //We hit something
    if(!hits.isEmpty())
    {
      //Sort the hits according to the intercept position
      Collections.sort(hits);
     
      for(BulletHit bulletHit : hits)
      {
        if(bulletHit instanceof DriveableHit)
        {
          DriveableHit driveableHit = (DriveableHit)bulletHit;
          penetratingPower = driveableHit.driveable.bulletHit(this, driveableHit, penetratingPower);
          if(FlansMod.DEBUG)
            worldObj.spawnEntityInWorld(new EntityDebugDot(worldObj, new Vector3f(posX + motionX * driveableHit.intersectTime, posY + motionY * driveableHit.intersectTime, posZ + motionZ * driveableHit.intersectTime), 1000, 0F, 0F, 1F));

        }
        else if(bulletHit instanceof PlayerBulletHit)
        {
          PlayerBulletHit playerHit = (PlayerBulletHit)bulletHit;
          penetratingPower = playerHit.hitbox.hitByBullet(this, penetratingPower);
          if(FlansMod.DEBUG)
            worldObj.spawnEntityInWorld(new EntityDebugDot(worldObj, new Vector3f(posX + motionX * playerHit.intersectTime, posY + motionY * playerHit.intersectTime, posZ + motionZ * playerHit.intersectTime), 1000, 1F, 0F, 0F));
        }
        else if(bulletHit instanceof EntityHit)
View Full Code Here

TOP

Related Classes of com.flansmod.common.guns.raytracing.PlayerBulletHit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.