Package net.minecraft.util

Examples of net.minecraft.util.MovingObjectPosition


        float cosPitch = -MathHelper.cos(-entityplayer.rotationPitch * 0.01745329F);
        float sinPitch = MathHelper.sin(-entityplayer.rotationPitch * 0.01745329F);
        double length = 5D;
        Vec3 posVec = Vec3.createVectorHelper(entityplayer.posX, entityplayer.posY + 1.62D - entityplayer.yOffset, entityplayer.posZ);       
        Vec3 lookVec = posVec.addVector(sinYaw * cosPitch * length, sinPitch * length, cosYaw * cosPitch * length);
        MovingObjectPosition movingobjectposition = world.rayTraceBlocks(posVec, lookVec, true);
       
        //Result check
        if(movingobjectposition == null)
        {
            return itemstack;
View Full Code Here


       
        worldObj.spawnEntityInWorld(new EntityDebugVector(worldObj, lookOrigin, lookVector, 20));
       
        Vector3f lookTarget = Vector3f.add(lookVector, lookOrigin, null);
       
        MovingObjectPosition hit = worldObj.rayTraceBlocks(lookOrigin.toVec3(), lookTarget.toVec3());
       
        //MovingObjectPosition hit = ((EntityLivingBase)seats[0].riddenByEntity).rayTrace(reach, 1F);
        if(hit != null && hit.typeOfHit == MovingObjectType.BLOCK)
        {
          if(breakingBlock == null || breakingBlock.x != hit.blockX || breakingBlock.y != hit.blockY || breakingBlock.z != hit.blockZ)
View Full Code Here

        float cosPitch = -MathHelper.cos(-entityplayer.rotationPitch * 0.01745329F);
        float sinPitch = MathHelper.sin(-entityplayer.rotationPitch * 0.01745329F);
        double length = 5D;
        Vec3 posVec = Vec3.createVectorHelper(entityplayer.posX, entityplayer.posY + 1.62D - entityplayer.yOffset, entityplayer.posZ);       
        Vec3 lookVec = posVec.addVector(sinYaw * cosPitch * length, sinPitch * length, cosYaw * cosPitch * length);
        MovingObjectPosition movingobjectposition = world.rayTraceBlocks(posVec, lookVec, type.placeableOnWater);
       
        //Result check
        if(movingobjectposition == null)
        {
            return itemstack;
View Full Code Here

        float f7 = f4 * f5;
        float f8 = f6;
        float f9 = f3 * f5;
        double d3 = 5D;
        Vec3 vec3d1 = vec3d.addVector(f7 * d3, f8 * d3, f9 * d3);
        MovingObjectPosition movingobjectposition = world.rayTraceBlocks(vec3d, vec3d1, true);
        if(movingobjectposition == null)
        {
            return itemstack;
        }
        if(movingobjectposition.typeOfHit == MovingObjectType.BLOCK)
View Full Code Here

                }
               
                //If we couldn't get a snapshot, use normal entity hitbox calculations
                if(otherData == null || shouldDoNormalHitDetect)
                {
                  MovingObjectPosition mop = data.lastMeleePositions[k] == null ? player.boundingBox.calculateIntercept(nextPosInWorldCoords.toVec3(), Vec3.createVectorHelper(0F, 0F, 0F)) : player.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 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)
View Full Code Here

          float cosPitch = -MathHelper.cos(-entityplayer.rotationPitch * 0.01745329F);
          float sinPitch = MathHelper.sin(-entityplayer.rotationPitch * 0.01745329F);
          double length = 5D;
          Vec3 posVec = Vec3.createVectorHelper(entityplayer.posX, entityplayer.posY + 1.62D - entityplayer.yOffset, entityplayer.posZ);       
          Vec3 lookVec = posVec.addVector(sinYaw * cosPitch * length, sinPitch * length, cosYaw * cosPitch * length);
          MovingObjectPosition look = world.rayTraceBlocks(posVec, lookVec, true);
         
          //Result check
      if (look != null && look.typeOfHit == MovingObjectType.BLOCK)
      {
        if (look.sideHit == 1)
View Full Code Here

        }
       
        //If we couldn't get a snapshot, use normal entity hitbox calculations
        if(data == null || shouldDoNormalHitDetect)
        {
          MovingObjectPosition mop = player.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 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)
        {
          EntityHit entityHit = (EntityHit)bulletHit;
          if(entityHit.entity.attackEntityFrom(getBulletDamage(false), damage * type.damageVsLiving) && entityHit.entity instanceof EntityLivingBase)
          {
            EntityLivingBase living = (EntityLivingBase)entityHit.entity;
            for(PotionEffect effect : type.hitEffects)
            {
              living.addPotionEffect(new PotionEffect(effect));
            }
            //If the attack was allowed, we should remove their immortality cooldown so we can shoot them again. Without this, any rapid fire gun become useless
            living.arrowHitTimer++;
            living.hurtResistantTime = living.maxHurtResistantTime / 2;
          }
          if(type.setEntitiesOnFire)
            entityHit.entity.setFire(20);
          penetratingPower -= 1F;
          if(FlansMod.DEBUG)
            worldObj.spawnEntityInWorld(new EntityDebugDot(worldObj, new Vector3f(posX + motionX * entityHit.intersectTime, posY + motionY * entityHit.intersectTime, posZ + motionZ * entityHit.intersectTime), 1000, 1F, 1F, 0F));
        }
        else if(bulletHit instanceof BlockHit)
        {
          BlockHit blockHit = (BlockHit)bulletHit;
          MovingObjectPosition raytraceResult = blockHit.raytraceResult;
          //If the hit wasn't an entity hit, then it must've been a block hit
          int xTile = raytraceResult.blockX;
          int yTile = raytraceResult.blockY;
          int zTile = raytraceResult.blockZ;
          if(FlansMod.DEBUG)
View Full Code Here

          EntityLivingBase checkEntity = (EntityLivingBase)list.get(l);
          //Don't check the player using it
          if(checkEntity == entityplayer)
            continue;
          //Do a more accurate ray trace on this entity
          MovingObjectPosition hit = checkEntity.boundingBox.calculateIntercept(posVec, lookVec);
          //If it hit, heal it
          if(hit != null)
            hitLiving = checkEntity;
        }
            //Now heal whatever it was we just decided to heal
View Full Code Here

        float cosPitch = -MathHelper.cos(-entityplayer.rotationPitch * 0.01745329F);
        float sinPitch = MathHelper.sin(-entityplayer.rotationPitch * 0.01745329F);
        double length = 5D;
        Vec3 posVec = Vec3.createVectorHelper(entityplayer.posX, entityplayer.posY + 1.62D - entityplayer.yOffset, entityplayer.posZ);       
        Vec3 lookVec = posVec.addVector(sinYaw * cosPitch * length, sinPitch * length, cosYaw * cosPitch * length);
        MovingObjectPosition movingobjectposition = world.rayTraceBlocks(posVec, lookVec, true);
       
        //Result check
    if (movingobjectposition == null)
    {
      return itemstack;
View Full Code Here

      if(FlansMod.DEBUG && worldObj.isRemote)
      {
        worldObj.spawnEntityInWorld(new EntityDebugVector(worldObj, new Vector3f(lastPos), Vector3f.sub(currentRelPos, lastRelPos, null), 10, 1F, 0F, 0F));
      }
     
      MovingObjectPosition hit = worldObj.rayTraceBlocks(lastPos, currentPos, crashInWater);
      if(hit != null && hit.typeOfHit == MovingObjectType.BLOCK)
      {
        int x = hit.blockX;
        int y = hit.blockY;
        int z = hit.blockZ;
View Full Code Here

TOP

Related Classes of net.minecraft.util.MovingObjectPosition

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.