Пример #1
0
  public void w_() {
    super.w_();
    if (this.lastPitch == 0.0F && this.lastYaw == 0.0F) {
      float f = MathHelper.a(this.motX * this.motX + this.motZ * this.motZ);

      this.lastYaw =
          this.yaw = (float) (Math.atan2(this.motX, this.motZ) * 180.0D / 3.1415927410125732D);
      this.lastPitch =
          this.pitch = (float) (Math.atan2(this.motY, (double) f) * 180.0D / 3.1415927410125732D);
    }

    int i = this.world.getTypeId(this.e, this.f, this.g);

    if (i > 0) {
      Block.byId[i].updateShape(this.world, this.e, this.f, this.g);
      AxisAlignedBB axisalignedbb = Block.byId[i].e(this.world, this.e, this.f, this.g);

      if (axisalignedbb != null && axisalignedbb.a(Vec3D.create(this.locX, this.locY, this.locZ))) {
        this.inGround = true;
      }
    }

    if (this.shake > 0) {
      --this.shake;
    }

    if (this.inGround) {
      i = this.world.getTypeId(this.e, this.f, this.g);
      int j = this.world.getData(this.e, this.f, this.g);

      if (i == this.h && j == this.i) {
        ++this.k;
        if (this.k == 1200) {
          this.die();
        }
      } else {
        this.inGround = false;
        this.motX *= (double) (this.random.nextFloat() * 0.2F);
        this.motY *= (double) (this.random.nextFloat() * 0.2F);
        this.motZ *= (double) (this.random.nextFloat() * 0.2F);
        this.k = 0;
        this.l = 0;
      }
    } else {
      ++this.l;
      Vec3D vec3d = Vec3D.create(this.locX, this.locY, this.locZ);
      Vec3D vec3d1 =
          Vec3D.create(this.locX + this.motX, this.locY + this.motY, this.locZ + this.motZ);
      MovingObjectPosition movingobjectposition = this.world.rayTrace(vec3d, vec3d1, false, true);

      vec3d = Vec3D.create(this.locX, this.locY, this.locZ);
      vec3d1 = Vec3D.create(this.locX + this.motX, this.locY + this.motY, this.locZ + this.motZ);
      if (movingobjectposition != null) {
        vec3d1 =
            Vec3D.create(
                movingobjectposition.f.a, movingobjectposition.f.b, movingobjectposition.f.c);
      }

      Entity entity = null;
      List list =
          this.world.b(
              (Entity) this,
              this.boundingBox.a(this.motX, this.motY, this.motZ).b(1.0D, 1.0D, 1.0D));
      double d0 = 0.0D;

      int k;
      float f1;

      for (k = 0; k < list.size(); ++k) {
        Entity entity1 = (Entity) list.get(k);

        if (entity1.e_() && (entity1 != this.shooter || this.l >= 5)) {
          f1 = 0.3F;
          AxisAlignedBB axisalignedbb1 =
              entity1.boundingBox.b((double) f1, (double) f1, (double) f1);
          MovingObjectPosition movingobjectposition1 = axisalignedbb1.a(vec3d, vec3d1);

          if (movingobjectposition1 != null) {
            double d1 = vec3d.b(movingobjectposition1.f);

            if (d1 < d0 || d0 == 0.0D) {
              entity = entity1;
              d0 = d1;
            }
          }
        }
      }

      if (entity != null) {
        movingobjectposition = new MovingObjectPosition(entity);
      }

      float f2;

      if (movingobjectposition != null) {
        // CraftBukkit start
        ProjectileHitEvent phe = new ProjectileHitEvent((Projectile) this.getBukkitEntity());
        this.world.getServer().getPluginManager().callEvent(phe);
        // CraftBukkit end
        if (movingobjectposition.entity != null) {
          f2 = MathHelper.a(this.motX * this.motX + this.motY * this.motY + this.motZ * this.motZ);
          int l = (int) Math.ceil((double) f2 * 2.0D);

          if (this.d) {
            l += this.random.nextInt(l / 2 + 2);
          }

          DamageSource damagesource = null;

          if (this.shooter == null) {
            damagesource = DamageSource.arrow(this, this);
          } else {
            damagesource = DamageSource.arrow(this, this.shooter);
          }

          // CraftBukkit start
          boolean stick;
          if (entity instanceof EntityLiving) {

            org.bukkit.entity.Entity damagee = movingobjectposition.entity.getBukkitEntity();
            Projectile projectile = (Projectile) this.getBukkitEntity();

            EntityDamageByEntityEvent event =
                new EntityDamageByEntityEvent(
                    projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, l);
            Bukkit.getPluginManager().callEvent(event);

            if (event.isCancelled()) {
              stick = !projectile.doesBounce();
            } else {
              // this function returns if the arrow should stick in or not, i.e. !bounce
              stick = movingobjectposition.entity.damageEntity(damagesource, event.getDamage());
            }
          } else {
            stick = movingobjectposition.entity.damageEntity(damagesource, l);
          }
          if (stick) {
            // CraftBukkit end
            if (movingobjectposition.entity instanceof EntityLiving) {
              ++((EntityLiving) movingobjectposition.entity).aH;
            }

            this.world.makeSound(
                this, "random.bowhit", 1.0F, 1.2F / (this.random.nextFloat() * 0.2F + 0.9F));
            this.die();
          } else {
            this.motX *= -0.10000000149011612D;
            this.motY *= -0.10000000149011612D;
            this.motZ *= -0.10000000149011612D;
            this.yaw += 180.0F;
            this.lastYaw += 180.0F;
            this.l = 0;
          }
        } else {
          this.e = movingobjectposition.b;
          this.f = movingobjectposition.c;
          this.g = movingobjectposition.d;
          this.h = this.world.getTypeId(this.e, this.f, this.g);
          this.i = this.world.getData(this.e, this.f, this.g);
          this.motX = (double) ((float) (movingobjectposition.f.a - this.locX));
          this.motY = (double) ((float) (movingobjectposition.f.b - this.locY));
          this.motZ = (double) ((float) (movingobjectposition.f.c - this.locZ));
          f2 = MathHelper.a(this.motX * this.motX + this.motY * this.motY + this.motZ * this.motZ);
          this.locX -= this.motX / (double) f2 * 0.05000000074505806D;
          this.locY -= this.motY / (double) f2 * 0.05000000074505806D;
          this.locZ -= this.motZ / (double) f2 * 0.05000000074505806D;
          this.world.makeSound(
              this, "random.bowhit", 1.0F, 1.2F / (this.random.nextFloat() * 0.2F + 0.9F));
          this.inGround = true;
          this.shake = 7;
          this.d = false;
        }
      }

      if (this.d) {
        for (k = 0; k < 4; ++k) {
          this.world.a(
              "crit",
              this.locX + this.motX * (double) k / 4.0D,
              this.locY + this.motY * (double) k / 4.0D,
              this.locZ + this.motZ * (double) k / 4.0D,
              -this.motX,
              -this.motY + 0.2D,
              -this.motZ);
        }
      }

      this.locX += this.motX;
      this.locY += this.motY;
      this.locZ += this.motZ;
      f2 = MathHelper.a(this.motX * this.motX + this.motZ * this.motZ);
      this.yaw = (float) (Math.atan2(this.motX, this.motZ) * 180.0D / 3.1415927410125732D);

      for (this.pitch = (float) (Math.atan2(this.motY, (double) f2) * 180.0D / 3.1415927410125732D);
          this.pitch - this.lastPitch < -180.0F;
          this.lastPitch -= 360.0F) {;
      }

      while (this.pitch - this.lastPitch >= 180.0F) {
        this.lastPitch += 360.0F;
      }

      while (this.yaw - this.lastYaw < -180.0F) {
        this.lastYaw -= 360.0F;
      }

      while (this.yaw - this.lastYaw >= 180.0F) {
        this.lastYaw += 360.0F;
      }

      this.pitch = this.lastPitch + (this.pitch - this.lastPitch) * 0.2F;
      this.yaw = this.lastYaw + (this.yaw - this.lastYaw) * 0.2F;
      float f3 = 0.99F;

      f1 = 0.05F;
      if (this.az()) {
        for (int i1 = 0; i1 < 4; ++i1) {
          float f4 = 0.25F;

          this.world.a(
              "bubble",
              this.locX - this.motX * (double) f4,
              this.locY - this.motY * (double) f4,
              this.locZ - this.motZ * (double) f4,
              this.motX,
              this.motY,
              this.motZ);
        }

        f3 = 0.8F;
      }

      this.motX *= (double) f3;
      this.motY *= (double) f3;
      this.motZ *= (double) f3;
      this.motY -= (double) f1;
      this.setPosition(this.locX, this.locY, this.locZ);
    }
  }