示例#1
0
  public static void flyingMoveLogic(EntityLiving entity, float f, float f1) {
    if (entity.M()) {
      entity.a(f, f1, 0.02F);
      entity.move(entity.motX, entity.motY, entity.motZ);
      entity.motX *= 0.800000011920929D;
      entity.motY *= 0.800000011920929D;
      entity.motZ *= 0.800000011920929D;
    } else if (entity.P()) {
      entity.a(f, f1, 0.02F);
      entity.move(entity.motX, entity.motY, entity.motZ);
      entity.motX *= 0.5D;
      entity.motY *= 0.5D;
      entity.motZ *= 0.5D;
    } else {
      float f2 = 0.91F;

      if (entity.onGround) {
        f2 =
            entity.world.getType(
                        MathHelper.floor(entity.locX),
                        MathHelper.floor(entity.boundingBox.b) - 1,
                        MathHelper.floor(entity.locZ))
                    .frictionFactor
                * 0.91F;
      }

      float f3 = 0.16277136F / (f2 * f2 * f2);

      entity.a(f, f1, entity.onGround ? 0.1F * f3 : 0.02F);
      f2 = 0.91F;
      if (entity.onGround) {
        f2 =
            entity.world.getType(
                        MathHelper.floor(entity.locX),
                        MathHelper.floor(entity.boundingBox.b) - 1,
                        MathHelper.floor(entity.locZ))
                    .frictionFactor
                * 0.91F;
      }

      entity.move(entity.motX, entity.motY, entity.motZ);
      entity.motX *= f2;
      entity.motY *= f2;
      entity.motZ *= f2;
    }

    entity.aF = entity.aG;
    double d0 = entity.locX - entity.lastX;
    double d1 = entity.locZ - entity.lastZ;
    float f4 = MathHelper.sqrt(d0 * d0 + d1 * d1) * 4.0F;

    if (f4 > 1.0F) {
      f4 = 1.0F;
    }

    entity.aG += (f4 - entity.aG) * 0.4F;
    entity.aH += entity.aG;
  }
示例#2
0
  public static List getBlockBBsInBB(World world, AxisAlignedBB axisalignedbb) {
    UnsafeList unsafeList = new UnsafeList();
    int minX = MathHelper.floor(axisalignedbb.a);
    int maxX = MathHelper.floor(axisalignedbb.d + 1.0D);
    int minY = MathHelper.floor(axisalignedbb.b);
    int maxY = MathHelper.floor(axisalignedbb.e + 1.0D);
    int minZ = MathHelper.floor(axisalignedbb.c);
    int maxZ = MathHelper.floor(axisalignedbb.f + 1.0D);

    for (int x = minX; x < maxX; x++) {
      for (int z = minZ; z < maxZ; z++) {
        if (world.isChunkLoaded(x, z)) {
          for (int y = minY - 1; y < maxY; y++) {
            Block block = Block.e(world.getBlockAt(x, y, z).getTypeId());

            if (block != null) {
              block.a(((CraftWorld) world).getHandle(), x, y, z, axisalignedbb, unsafeList, null);
            }
          }
        }
      }
    }
    return unsafeList;
  }
  @Override
  public boolean update() {
    EntityHuman passenger = (EntityHuman) this.getEntityHandle().passenger;
    EntityLiving entity = this.getEntityHandle();
    float f = MathHelper.g(passenger.yaw - entity.yaw) * 0.5f;

    if (f > 5) f = 5;

    if (f < -5) f = -5;

    entity.yaw = MathHelper.g(entity.yaw + f);
    if (this.m_currentSpeed < this.m_maxSpeed)
      this.m_currentSpeed += (this.m_maxSpeed - this.m_currentSpeed) * 0.01;

    if (this.m_currentSpeed > this.m_maxSpeed) this.m_currentSpeed = this.m_maxSpeed;

    int x = MathHelper.floor(entity.locX);
    int y = MathHelper.floor(entity.locY);
    int z = MathHelper.floor(entity.locZ);
    float speed = this.m_currentSpeed;

    if (this.m_speedBoosted) {
      if (this.m_speedBoostTime++ > this.m_maxSpeedBoostTime) this.m_speedBoosted = false;

      speed +=
          speed
              * 1.15
              * MathHelper.sin(
                  (float) (this.m_speedBoostTime / this.m_maxSpeedBoostTime * Math.PI));
    }

    float f2 = 0.91f;
    if (entity.onGround) {
      f2 = 0.54600006F;
      Block block = entity.world.getType(MathHelper.d(x), MathHelper.d(y) - 1, MathHelper.d(z));
      if (block.getMaterial() != Material.AIR) f2 = block.frictionFactor * 0.91f;
    }

    float f3 = 0.16277136F / (f2 * f2 * f2);
    float f4 = MathHelper.sin(entity.yaw * 3.1415927F / 180.0F);
    float f5 = MathHelper.cos(entity.yaw * 3.1415927F / 180.0F);
    float f6 = entity.bl() * f3;
    float f7 = Math.max(speed, 1.0F);

    f7 = f6 / f7;
    float f8 = speed * f7;
    float f9 = -(f8 * f4);
    float f10 = f8 * f5;

    if (MathHelper.abs(f9) > MathHelper.abs(f10)) {
      if (f9 < 0.0F) {
        f9 -= entity.width / 2.0F;
      }

      if (f9 > 0.0F) {
        f9 += entity.width / 2.0F;
      }

      f10 = 0.0F;
    } else {
      f9 = 0.0F;
      if (f10 < 0.0F) {
        f10 -= entity.width / 2.0F;
      }

      if (f10 > 0.0F) {
        f10 += entity.width / 2.0F;
      }
    }

    int nextX = MathHelper.floor(entity.locX + f9);
    int nextZ = MathHelper.floor(entity.locZ + f10);
    PathPoint point =
        new PathPoint(
            MathHelper.d(entity.width + 1),
            MathHelper.d(entity.length + passenger.length + 1),
            MathHelper.d(entity.width + 1));
    if (x != nextX || z != nextZ) {
      Block type1 = entity.world.getType(x, y, z);
      Block type2 = entity.world.getType(x, y - 1, z);
      boolean isStep = this.isStep(type1) || type1 == null && this.isStep(type2);

      if (!isStep
          && Pathfinder.a(entity, nextX, y, nextZ, point, false, false, true) == 0
          && Pathfinder.a(entity, x, y + 1, z, point, false, false, true) == 1
          && Pathfinder.a(entity, nextX, y + 1, nextZ, point, false, false, true) == 1)
        NMSUtil.getControllerLook(entity).a();
    }

    if (!passenger.abilities.canInstantlyBuild
        && this.m_currentSpeed >= this.m_maxSpeed * 0.5
        && entity.aI().nextFloat() < 0.006f
        && !this.m_speedBoosted) {
      ItemStack item = passenger.be();

      if (item != null && item.getItem() == Items.CARROT_STICK) {
        item.damage(1, passenger);
        if (item.count == 0) {
          ItemStack newItem = new ItemStack(Items.FISHING_ROD);
          newItem.setTag(item.tag);
          passenger.inventory.items[passenger.inventory.itemInHandIndex] = newItem;
        }
      }
    }

    entity.e(0, speed);
    return true;
  }