コード例 #1
0
  protected void bi() {
    int i;

    if (this.bU() > 0) {
      i = this.bU() - 1;
      if (i <= 0) {
        // CraftBukkit start
        ExplosionPrimeEvent event = new ExplosionPrimeEvent(this.getBukkitEntity(), 7.0F, false);
        this.world.getServer().getPluginManager().callEvent(event);

        if (!event.isCancelled()) {
          this.world.createExplosion(
              this,
              this.locX,
              this.locY + (double) this.getHeadHeight(),
              this.locZ,
              event.getRadius(),
              event.getFire(),
              this.world.getGameRules().getBoolean("mobGriefing"));
        }
        // CraftBukkit end

        this.world.createExplosion(
            this,
            this.locX,
            this.locY + (double) this.getHeadHeight(),
            this.locZ,
            7.0F,
            false,
            this.world.getGameRules().getBoolean("mobGriefing"));
        this.world.d(1013, (int) this.locX, (int) this.locY, (int) this.locZ, 0);
      }

      this.p(i);
      if (this.ticksLived % 10 == 0) {
        this.heal(
            10.0F,
            org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason
                .WITHER_SPAWN); // CraftBukkit
      }
    } else {
      super.bi();

      int j;

      for (i = 1; i < 3; ++i) {
        if (this.ticksLived >= this.bt[i - 1]) {
          this.bt[i - 1] = this.ticksLived + 10 + this.random.nextInt(10);
          if (this.world.difficulty >= 2) {
            int i1001 = i - 1;
            int i1003 = this.bu[i - 1];

            this.bu[i1001] = this.bu[i - 1] + 1;
            if (i1003 > 15) {
              float f = 10.0F;
              float f1 = 5.0F;
              double d0 = MathHelper.a(this.random, this.locX - (double) f, this.locX + (double) f);
              double d1 =
                  MathHelper.a(this.random, this.locY - (double) f1, this.locY + (double) f1);
              double d2 = MathHelper.a(this.random, this.locZ - (double) f, this.locZ + (double) f);

              this.a(i + 1, d0, d1, d2, true);
              this.bu[i - 1] = 0;
            }
          }

          j = this.q(i);
          if (j > 0) {
            Entity entity = this.world.getEntity(j);

            if (entity != null && entity.isAlive() && this.e(entity) <= 900.0D && this.o(entity)) {
              this.a(i + 1, (EntityLiving) entity);
              this.bt[i - 1] = this.ticksLived + 40 + this.random.nextInt(20);
              this.bu[i - 1] = 0;
            } else {
              this.c(i, 0);
            }
          } else {
            List list =
                this.world.a(EntityLiving.class, this.boundingBox.grow(20.0D, 8.0D, 20.0D), bw);

            for (int i1 = 0; i1 < 10 && !list.isEmpty(); ++i1) {
              EntityLiving entityliving = (EntityLiving) list.get(this.random.nextInt(list.size()));

              if (entityliving != this && entityliving.isAlive() && this.o(entityliving)) {
                if (entityliving instanceof EntityHuman) {
                  if (!((EntityHuman) entityliving).abilities.isInvulnerable) {
                    this.c(i, entityliving.id);
                  }
                } else {
                  this.c(i, entityliving.id);
                }
                break;
              }

              list.remove(entityliving);
            }
          }
        }
      }

      if (this.getGoalTarget() != null) {
        this.c(0, this.getGoalTarget().id);
      } else {
        this.c(0, 0);
      }

      if (this.bv > 0) {
        --this.bv;
        if (this.bv == 0 && this.world.getGameRules().getBoolean("mobGriefing")) {
          i = MathHelper.floor(this.locY);
          j = MathHelper.floor(this.locX);
          int j1 = MathHelper.floor(this.locZ);
          boolean flag = false;

          for (int k1 = -1; k1 <= 1; ++k1) {
            for (int l1 = -1; l1 <= 1; ++l1) {
              for (int i2 = 0; i2 <= 3; ++i2) {
                int j2 = j + k1;
                int k2 = i + i2;
                int l2 = j1 + l1;
                int i3 = this.world.getTypeId(j2, k2, l2);

                if (i3 > 0
                    && i3 != Block.BEDROCK.id
                    && i3 != Block.ENDER_PORTAL.id
                    && i3 != Block.ENDER_PORTAL_FRAME.id) {
                  // CraftBukkit start
                  if (CraftEventFactory.callEntityChangeBlockEvent(this, j2, k2, l2, 0, 0)
                      .isCancelled()) {
                    continue;
                  }
                  // CraftBukkit end

                  flag = this.world.setAir(j2, k2, l2, true) || flag;
                }
              }
            }
          }

          if (flag) {
            this.world.a(
                (EntityHuman) null, 1012, (int) this.locX, (int) this.locY, (int) this.locZ, 0);
          }
        }
      }

      if (this.ticksLived % 20 == 0) {
        this.heal(1.0F);
      }
    }
  }
コード例 #2
0
 public boolean isValid() {
   return entity.isAlive() && entity.valid;
 }
コード例 #3
0
ファイル: EntityHuman.java プロジェクト: Chocanto/mc-dev
  public void attack(Entity entity) {
    if (entity.k_()) {
      int i = this.inventory.a(entity);

      if (this.hasEffect(MobEffectList.INCREASE_DAMAGE)) {
        i += 3 << this.getEffect(MobEffectList.INCREASE_DAMAGE).getAmplifier();
      }

      if (this.hasEffect(MobEffectList.WEAKNESS)) {
        i -= 2 << this.getEffect(MobEffectList.WEAKNESS).getAmplifier();
      }

      int j = 0;
      int k = 0;

      if (entity instanceof EntityLiving) {
        k = EnchantmentManager.a(this.inventory, (EntityLiving) entity);
        j += EnchantmentManager.getKnockbackEnchantmentLevel(this.inventory, (EntityLiving) entity);
      }

      if (this.isSprinting()) {
        ++j;
      }

      if (i > 0 || k > 0) {
        boolean flag =
            this.fallDistance > 0.0F
                && !this.onGround
                && !this.t()
                && !this.aU()
                && !this.hasEffect(MobEffectList.BLINDNESS)
                && this.vehicle == null
                && entity instanceof EntityLiving;

        if (flag) {
          i += this.random.nextInt(i / 2 + 2);
        }

        i += k;
        boolean flag1 = entity.damageEntity(DamageSource.playerAttack(this), i);

        if (flag1) {
          if (j > 0) {
            entity.b_(
                (double) (-MathHelper.sin(this.yaw * 3.1415927F / 180.0F) * (float) j * 0.5F),
                0.1D,
                (double) (MathHelper.cos(this.yaw * 3.1415927F / 180.0F) * (float) j * 0.5F));
            this.motX *= 0.6D;
            this.motZ *= 0.6D;
            this.setSprinting(false);
          }

          if (flag) {
            this.c(entity);
          }

          if (k > 0) {
            this.d(entity);
          }

          if (i >= 18) {
            this.a((Statistic) AchievementList.E);
          }

          this.g(entity);
        }

        ItemStack itemstack = this.U();

        if (itemstack != null && entity instanceof EntityLiving) {
          itemstack.a((EntityLiving) entity, this);
          if (itemstack.count <= 0) {
            itemstack.a(this);
            this.V();
          }
        }

        if (entity instanceof EntityLiving) {
          if (entity.isAlive()) {
            this.a((EntityLiving) entity, true);
          }

          this.a(StatisticList.w, i);
          int l =
              EnchantmentManager.getFireAspectEnchantmentLevel(
                  this.inventory, (EntityLiving) entity);

          if (l > 0) {
            entity.setOnFire(l * 4);
          }
        }

        this.c(0.3F);
      }
    }
  }
コード例 #4
0
 public boolean isDead() {
   return !entity.isAlive();
 }
コード例 #5
0
ファイル: EntityWither.java プロジェクト: DaMarine/Alkazia
  protected void E() {
    int i;

    if (this.cj() > 0) {
      i = this.cj() - 1;
      if (i <= 0) {
        // CraftBukkit start
        // this.world.createExplosion(this, this.locX, this.locY + (double) this.getHeadHeight(),
        // this.locZ, 7.0F, false, this.world.getGameRules().getBoolean("mobGriefing"));
        ExplosionPrimeEvent event = new ExplosionPrimeEvent(this.getBukkitEntity(), 7.0F, false);
        this.world.getServer().getPluginManager().callEvent(event);

        if (!event.isCancelled()) {
          this.world.createExplosion(
              this,
              this.locX,
              this.locY + (double) this.getHeadHeight(),
              this.locZ,
              event.getRadius(),
              event.getFire(),
              this.world.getGameRules().getBoolean("mobGriefing"));
        }
        // CraftBukkit end

        // CraftBukkit start - Use relative location for far away sounds
        // this.world.a(1013, new BlockPosition(this), 0);
        int viewDistance = ((WorldServer) this.world).getServer().getViewDistance() * 16;
        for (EntityPlayer player : (List<EntityPlayer>) this.world.players) {
          double deltaX = this.locX - player.locX;
          double deltaZ = this.locZ - player.locZ;
          double distanceSquared = deltaX * deltaX + deltaZ * deltaZ;
          if (world.spigotConfig.witherSpawnSoundRadius > 0
              && distanceSquared
                  > world.spigotConfig.witherSpawnSoundRadius
                      * world.spigotConfig.witherSpawnSoundRadius) continue; // Spigot
          if (distanceSquared > viewDistance * viewDistance) {
            double deltaLength = Math.sqrt(distanceSquared);
            double relativeX = player.locX + (deltaX / deltaLength) * viewDistance;
            double relativeZ = player.locZ + (deltaZ / deltaLength) * viewDistance;
            player.playerConnection.sendPacket(
                new PacketPlayOutWorldEvent(
                    1013,
                    new BlockPosition((int) relativeX, (int) this.locY, (int) relativeZ),
                    0,
                    true));
          } else {
            player.playerConnection.sendPacket(
                new PacketPlayOutWorldEvent(
                    1013,
                    new BlockPosition((int) this.locX, (int) this.locY, (int) this.locZ),
                    0,
                    true));
          }
        }
        // CraftBukkit end
      }

      this.r(i);
      if (this.ticksLived % 10 == 0) {
        this.heal(10.0F, EntityRegainHealthEvent.RegainReason.WITHER_SPAWN); // CraftBukkit
      }

    } else {
      super.E();

      int j;

      for (i = 1; i < 3; ++i) {
        if (this.ticksLived >= this.bm[i - 1]) {
          this.bm[i - 1] = this.ticksLived + 10 + this.random.nextInt(10);
          if (this.world.getDifficulty() == EnumDifficulty.NORMAL
              || this.world.getDifficulty() == EnumDifficulty.HARD) {
            int k = i - 1;
            int l = this.bn[i - 1];

            this.bn[k] = this.bn[i - 1] + 1;
            if (l > 15) {
              float f = 10.0F;
              float f1 = 5.0F;
              double d0 = MathHelper.a(this.random, this.locX - (double) f, this.locX + (double) f);
              double d1 =
                  MathHelper.a(this.random, this.locY - (double) f1, this.locY + (double) f1);
              double d2 = MathHelper.a(this.random, this.locZ - (double) f, this.locZ + (double) f);

              this.a(i + 1, d0, d1, d2, true);
              this.bn[i - 1] = 0;
            }
          }

          j = this.s(i);
          if (j > 0) {
            Entity entity = this.world.a(j);

            if (entity != null
                && entity.isAlive()
                && this.h(entity) <= 900.0D
                && this.hasLineOfSight(entity)) {
              this.a(i + 1, (EntityLiving) entity);
              this.bm[i - 1] = this.ticksLived + 40 + this.random.nextInt(20);
              this.bn[i - 1] = 0;
            } else {
              this.b(i, 0);
            }
          } else {
            List list =
                this.world.a(
                    EntityLiving.class,
                    this.getBoundingBox().grow(20.0D, 8.0D, 20.0D),
                    Predicates.and(EntityWither.bp, IEntitySelector.d));

            for (int i1 = 0; i1 < 10 && !list.isEmpty(); ++i1) {
              EntityLiving entityliving = (EntityLiving) list.get(this.random.nextInt(list.size()));

              if (entityliving != this
                  && entityliving.isAlive()
                  && this.hasLineOfSight(entityliving)) {
                if (entityliving instanceof EntityHuman) {
                  if (!((EntityHuman) entityliving).abilities.isInvulnerable) {
                    this.b(i, entityliving.getId());
                  }
                } else {
                  this.b(i, entityliving.getId());
                }
                break;
              }

              list.remove(entityliving);
            }
          }
        }
      }

      if (this.getGoalTarget() != null) {
        this.b(0, this.getGoalTarget().getId());
      } else {
        this.b(0, 0);
      }

      if (this.bo > 0) {
        --this.bo;
        if (this.bo == 0 && this.world.getGameRules().getBoolean("mobGriefing")) {
          i = MathHelper.floor(this.locY);
          j = MathHelper.floor(this.locX);
          int j1 = MathHelper.floor(this.locZ);
          boolean flag = false;

          for (int k1 = -1; k1 <= 1; ++k1) {
            for (int l1 = -1; l1 <= 1; ++l1) {
              for (int i2 = 0; i2 <= 3; ++i2) {
                int j2 = j + k1;
                int k2 = i + i2;
                int l2 = j1 + l1;
                Block block = this.world.getType(new BlockPosition(j2, k2, l2)).getBlock();

                if (block.getMaterial() != Material.AIR
                    && block != Blocks.BEDROCK
                    && block != Blocks.END_PORTAL
                    && block != Blocks.END_PORTAL_FRAME
                    && block != Blocks.COMMAND_BLOCK
                    && block != Blocks.BARRIER) {
                  // CraftBukkit start
                  if (CraftEventFactory.callEntityChangeBlockEvent(this, j2, k2, l2, Blocks.AIR, 0)
                      .isCancelled()) {
                    continue;
                  }
                  // CraftBukkit end
                  flag = this.world.setAir(new BlockPosition(j2, k2, l2), true) || flag;
                }
              }
            }
          }

          if (flag) {
            this.world.a((EntityHuman) null, 1012, new BlockPosition(this), 0);
          }
        }
      }

      if (this.ticksLived % 20 == 0) {
        this.heal(1.0F, EntityRegainHealthEvent.RegainReason.REGEN); // CraftBukkit
      }
    }
  }