コード例 #1
0
  @Override
  public boolean update() {
    EntityLiving entity = this.getEntityHandle();
    NMSUtil.getControllerLook(entity).a(this.m_target, 30, 30);
    if ((this.m_ignoreSight || NMSUtil.getEntitySenses(entity).canSee(this.m_target))
        && --this.m_moveTick <= 0) {
      this.m_moveTick = 4 + entity.aC().nextInt(7);
      this.getRemoteEntity()
          .move(
              (LivingEntity) this.m_target.getBukkitEntity(),
              (this.m_speed == -1 ? this.getRemoteEntity().getSpeed() : this.m_speed));
    }

    this.m_attackTick = Math.max(this.m_attackTick - 1, 0);
    double minDist = entity.width * 2 * entity.width * 2;
    if (this.m_attackTick <= 0
        && entity.e(this.m_target.locX, this.m_target.boundingBox.b, this.m_target.locZ)
            <= minDist) {
      this.m_attackTick = 20;
      if (entity.aY() != null) this.getEntityHandle().aR();

      this.attack(this.m_target.getBukkitEntity());
    }
    return true;
  }
コード例 #2
0
  public void e() {
    EntityLiving entityliving = this.b.getGoalTarget();

    this.b.getControllerLook().a(entityliving, 30.0F, 30.0F);
    double d0 = this.b.e(entityliving.locX, entityliving.boundingBox.b, entityliving.locZ);
    double d1 = (double) (this.b.width * 2.0F * this.b.width * 2.0F + entityliving.width);

    --this.h;
    if ((this.e || this.b.getEntitySenses().canSee(entityliving))
        && this.h <= 0
        && (this.i == 0.0D && this.j == 0.0D && this.k == 0.0D
            || entityliving.e(this.i, this.j, this.k) >= 1.0D
            || this.b.aI().nextFloat() < 0.05F)) {
      this.i = entityliving.locX;
      this.j = entityliving.boundingBox.b;
      this.k = entityliving.locZ;
      this.h = 4 + this.b.aI().nextInt(7);
      if (d0 > 1024.0D) {
        this.h += 10;
      } else if (d0 > 256.0D) {
        this.h += 5;
      }

      if (!this.b.getNavigation().a((Entity) entityliving, this.d)) {
        this.h += 15;
      }
    }

    this.c = Math.max(this.c - 1, 0);
    if (d0 <= d1 && this.c <= 20) {
      this.c = 20;
      if (this.b.be() != null) {
        this.b.ba();
      }

      this.b.n(entityliving);
    }
  }
コード例 #3
0
  @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;
  }