Пример #1
0
  public void a(Entity entity, double d0, double d1, double d2, float f) {
    if (this.a.worldProvider.dimension != 1) {
      if (!this.b(entity, d0, d1, d2, f)) {
        this.a(entity);
        this.b(entity, d0, d1, d2, f);
      }
    } else {
      int i = MathHelper.floor(entity.locX);
      int j = MathHelper.floor(entity.locY) - 1;
      int k = MathHelper.floor(entity.locZ);
      byte b0 = 1;
      byte b1 = 0;

      for (int l = -2; l <= 2; ++l) {
        for (int i1 = -2; i1 <= 2; ++i1) {
          for (int j1 = -1; j1 < 3; ++j1) {
            int k1 = i + i1 * b0 + l * b1;
            int l1 = j + j1;
            int i2 = k + i1 * b1 - l * b0;
            boolean flag = j1 < 0;

            this.a.setTypeIdUpdate(k1, l1, i2, flag ? Block.OBSIDIAN.id : 0);
          }
        }
      }

      entity.setPositionRotation((double) i, (double) j, (double) k, entity.yaw, 0.0F);
      entity.motX = entity.motY = entity.motZ = 0.0D;
    }
  }
Пример #2
0
  public boolean b(Entity entity, double d0, double d1, double d2, float f) {
    short short1 = 128;
    double d3 = -1.0D;
    int i = 0;
    int j = 0;
    int k = 0;
    int l = MathHelper.floor(entity.locX);
    int i1 = MathHelper.floor(entity.locZ);
    long j1 = ChunkCoordIntPair.a(l, i1);
    boolean flag = true;
    double d4;
    int k1;

    if (this.c.contains(j1)) {
      ChunkCoordinatesPortal chunkcoordinatesportal = (ChunkCoordinatesPortal) this.c.getEntry(j1);

      d3 = 0.0D;
      i = chunkcoordinatesportal.x;
      j = chunkcoordinatesportal.y;
      k = chunkcoordinatesportal.z;
      chunkcoordinatesportal.d = this.a.getTime();
      flag = false;
    } else {
      for (k1 = l - short1; k1 <= l + short1; ++k1) {
        double d5 = (double) k1 + 0.5D - entity.locX;

        for (int l1 = i1 - short1; l1 <= i1 + short1; ++l1) {
          double d6 = (double) l1 + 0.5D - entity.locZ;

          for (int i2 = this.a.R() - 1; i2 >= 0; --i2) {
            if (this.a.getTypeId(k1, i2, l1) == Block.PORTAL.id) {
              while (this.a.getTypeId(k1, i2 - 1, l1) == Block.PORTAL.id) {
                --i2;
              }

              d4 = (double) i2 + 0.5D - entity.locY;
              double d7 = d5 * d5 + d4 * d4 + d6 * d6;

              if (d3 < 0.0D || d7 < d3) {
                d3 = d7;
                i = k1;
                j = i2;
                k = l1;
              }
            }
          }
        }
      }
    }

    if (d3 >= 0.0D) {
      if (flag) {
        this.c.put(j1, new ChunkCoordinatesPortal(this, i, j, k, this.a.getTime()));
        this.d.add(Long.valueOf(j1));
      }

      double d8 = (double) i + 0.5D;
      double d9 = (double) j + 0.5D;

      d4 = (double) k + 0.5D;
      int j2 = -1;

      if (this.a.getTypeId(i - 1, j, k) == Block.PORTAL.id) {
        j2 = 2;
      }

      if (this.a.getTypeId(i + 1, j, k) == Block.PORTAL.id) {
        j2 = 0;
      }

      if (this.a.getTypeId(i, j, k - 1) == Block.PORTAL.id) {
        j2 = 3;
      }

      if (this.a.getTypeId(i, j, k + 1) == Block.PORTAL.id) {
        j2 = 1;
      }

      int k2 = entity.as();

      if (j2 > -1) {
        int l2 = Direction.h[j2];
        int i3 = Direction.a[j2];
        int j3 = Direction.b[j2];
        int k3 = Direction.a[l2];
        int l3 = Direction.b[l2];
        boolean flag1 =
            !this.a.isEmpty(i + i3 + k3, j, k + j3 + l3)
                || !this.a.isEmpty(i + i3 + k3, j + 1, k + j3 + l3);
        boolean flag2 =
            !this.a.isEmpty(i + i3, j, k + j3) || !this.a.isEmpty(i + i3, j + 1, k + j3);

        if (flag1 && flag2) {
          j2 = Direction.f[j2];
          l2 = Direction.f[l2];
          i3 = Direction.a[j2];
          j3 = Direction.b[j2];
          k3 = Direction.a[l2];
          l3 = Direction.b[l2];
          k1 = i - k3;
          d8 -= (double) k3;
          int i4 = k - l3;

          d4 -= (double) l3;
          flag1 =
              !this.a.isEmpty(k1 + i3 + k3, j, i4 + j3 + l3)
                  || !this.a.isEmpty(k1 + i3 + k3, j + 1, i4 + j3 + l3);
          flag2 = !this.a.isEmpty(k1 + i3, j, i4 + j3) || !this.a.isEmpty(k1 + i3, j + 1, i4 + j3);
        }

        float f1 = 0.5F;
        float f2 = 0.5F;

        if (!flag1 && flag2) {
          f1 = 1.0F;
        } else if (flag1 && !flag2) {
          f1 = 0.0F;
        } else if (flag1 && flag2) {
          f2 = 0.0F;
        }

        d8 += (double) ((float) k3 * f1 + f2 * (float) i3);
        d4 += (double) ((float) l3 * f1 + f2 * (float) j3);
        float f3 = 0.0F;
        float f4 = 0.0F;
        float f5 = 0.0F;
        float f6 = 0.0F;

        if (j2 == k2) {
          f3 = 1.0F;
          f4 = 1.0F;
        } else if (j2 == Direction.f[k2]) {
          f3 = -1.0F;
          f4 = -1.0F;
        } else if (j2 == Direction.g[k2]) {
          f5 = 1.0F;
          f6 = -1.0F;
        } else {
          f5 = -1.0F;
          f6 = 1.0F;
        }

        double d10 = entity.motX;
        double d11 = entity.motZ;

        entity.motX = d10 * (double) f3 + d11 * (double) f6;
        entity.motZ = d10 * (double) f5 + d11 * (double) f4;
        entity.yaw = f - (float) (k2 * 90) + (float) (j2 * 90);
      } else {
        entity.motX = entity.motY = entity.motZ = 0.0D;
      }

      entity.setPositionRotation(d8, d9, d4, entity.yaw, entity.pitch);
      return true;
    } else {
      return false;
    }
  }
Пример #3
0
 public void setVelocity(Vector vel) {
   entity.motX = vel.getX();
   entity.motY = vel.getY();
   entity.motZ = vel.getZ();
   entity.velocityChanged = true;
 }
  public void collide(Entity var1) {
    if (!this.world.isClientSide) {
      if (!var1.noclip && !this.noclip) {
        if (var1 != this.passenger) {
          if (var1 instanceof EntityLiving
              && !(var1 instanceof EntityHuman)
              && !(var1 instanceof EntityIronGolem)
              && this.s() == EntityMinecartAbstract.EnumMinecartType.RIDEABLE
              && this.motX * this.motX + this.motZ * this.motZ > 0.01D
              && this.passenger == null
              && var1.vehicle == null) {
            var1.mount(this);
          }

          double var2 = var1.locX - this.locX;
          double var4 = var1.locZ - this.locZ;
          double var6 = var2 * var2 + var4 * var4;
          if (var6 >= 9.999999747378752E-5D) {
            var6 = (double) MathHelper.sqrt(var6);
            var2 /= var6;
            var4 /= var6;
            double var8 = 1.0D / var6;
            if (var8 > 1.0D) {
              var8 = 1.0D;
            }

            var2 *= var8;
            var4 *= var8;
            var2 *= 0.10000000149011612D;
            var4 *= 0.10000000149011612D;
            var2 *= (double) (1.0F - this.U);
            var4 *= (double) (1.0F - this.U);
            var2 *= 0.5D;
            var4 *= 0.5D;
            if (var1 instanceof EntityMinecartAbstract) {
              double var10 = var1.locX - this.locX;
              double var12 = var1.locZ - this.locZ;
              Vec3D var14 = (new Vec3D(var10, 0.0D, var12)).a();
              Vec3D var15 =
                  (new Vec3D(
                          (double) MathHelper.cos(this.yaw * 3.1415927F / 180.0F),
                          0.0D,
                          (double) MathHelper.sin(this.yaw * 3.1415927F / 180.0F)))
                      .a();
              double var16 = Math.abs(var14.b(var15));
              if (var16 < 0.800000011920929D) {
                return;
              }

              double var18 = var1.motX + this.motX;
              double var20 = var1.motZ + this.motZ;
              if (((EntityMinecartAbstract) var1).s()
                      == EntityMinecartAbstract.EnumMinecartType.FURNACE
                  && this.s() != EntityMinecartAbstract.EnumMinecartType.FURNACE) {
                this.motX *= 0.20000000298023224D;
                this.motZ *= 0.20000000298023224D;
                this.g(var1.motX - var2, 0.0D, var1.motZ - var4);
                var1.motX *= 0.949999988079071D;
                var1.motZ *= 0.949999988079071D;
              } else if (((EntityMinecartAbstract) var1).s()
                      != EntityMinecartAbstract.EnumMinecartType.FURNACE
                  && this.s() == EntityMinecartAbstract.EnumMinecartType.FURNACE) {
                var1.motX *= 0.20000000298023224D;
                var1.motZ *= 0.20000000298023224D;
                var1.g(this.motX + var2, 0.0D, this.motZ + var4);
                this.motX *= 0.949999988079071D;
                this.motZ *= 0.949999988079071D;
              } else {
                var18 /= 2.0D;
                var20 /= 2.0D;
                this.motX *= 0.20000000298023224D;
                this.motZ *= 0.20000000298023224D;
                this.g(var18 - var2, 0.0D, var20 - var4);
                var1.motX *= 0.20000000298023224D;
                var1.motZ *= 0.20000000298023224D;
                var1.g(var18 + var2, 0.0D, var20 + var4);
              }
            } else {
              this.g(-var2, 0.0D, -var4);
              var1.g(var2 / 4.0D, 0.0D, var4 / 4.0D);
            }
          }
        }
      }
    }
  }
Пример #5
0
  public void collide(Entity entity) {
    if (!this.world.isStatic) {
      if (entity != this.passenger) {
        if (entity instanceof EntityLiving
            && !(entity instanceof EntityHuman)
            && !(entity instanceof EntityIronGolem)
            && this.type == 0
            && this.motX * this.motX + this.motZ * this.motZ > 0.01D
            && this.passenger == null
            && entity.vehicle == null) {
          entity.mount(this);
        }

        double d0 = entity.locX - this.locX;
        double d1 = entity.locZ - this.locZ;
        double d2 = d0 * d0 + d1 * d1;

        if (d2 >= 9.999999747378752E-5D) {
          d2 = (double) MathHelper.sqrt(d2);
          d0 /= d2;
          d1 /= d2;
          double d3 = 1.0D / d2;

          if (d3 > 1.0D) {
            d3 = 1.0D;
          }

          d0 *= d3;
          d1 *= d3;
          d0 *= 0.10000000149011612D;
          d1 *= 0.10000000149011612D;
          d0 *= (double) (1.0F - this.Z);
          d1 *= (double) (1.0F - this.Z);
          d0 *= 0.5D;
          d1 *= 0.5D;
          if (entity instanceof EntityMinecart) {
            double d4 = entity.locX - this.locX;
            double d5 = entity.locZ - this.locZ;
            Vec3D vec3d = this.world.getVec3DPool().create(d4, 0.0D, d5).a();
            Vec3D vec3d1 =
                this.world
                    .getVec3DPool()
                    .create(
                        (double) MathHelper.cos(this.yaw * 3.1415927F / 180.0F),
                        0.0D,
                        (double) MathHelper.sin(this.yaw * 3.1415927F / 180.0F))
                    .a();
            double d6 = Math.abs(vec3d.b(vec3d1));

            if (d6 < 0.800000011920929D) {
              return;
            }

            double d7 = entity.motX + this.motX;
            double d8 = entity.motZ + this.motZ;

            if (((EntityMinecart) entity).type == 2 && this.type != 2) {
              this.motX *= 0.20000000298023224D;
              this.motZ *= 0.20000000298023224D;
              this.g(entity.motX - d0, 0.0D, entity.motZ - d1);
              entity.motX *= 0.949999988079071D;
              entity.motZ *= 0.949999988079071D;
            } else if (((EntityMinecart) entity).type != 2 && this.type == 2) {
              entity.motX *= 0.20000000298023224D;
              entity.motZ *= 0.20000000298023224D;
              entity.g(this.motX + d0, 0.0D, this.motZ + d1);
              this.motX *= 0.949999988079071D;
              this.motZ *= 0.949999988079071D;
            } else {
              d7 /= 2.0D;
              d8 /= 2.0D;
              this.motX *= 0.20000000298023224D;
              this.motZ *= 0.20000000298023224D;
              this.g(d7 - d0, 0.0D, d8 - d1);
              entity.motX *= 0.20000000298023224D;
              entity.motZ *= 0.20000000298023224D;
              entity.g(d7 + d0, 0.0D, d8 + d1);
            }
          } else {
            this.g(-d0, 0.0D, -d1);
            entity.g(d0 / 4.0D, 0.0D, d1 / 4.0D);
          }
        }
      }
    }
  }
Пример #6
0
  /** Does the first part of the explosion (destroy blocks) */
  public void a() {
    float var1 = this.size;
    HashSet var2 = new HashSet();
    int var3;
    int var4;
    int var5;
    double var6;
    double var8;
    double var10;

    for (var3 = 0; var3 < this.field_77289_h; ++var3) {
      for (var4 = 0; var4 < this.field_77289_h; ++var4) {
        for (var5 = 0; var5 < this.field_77289_h; ++var5) {
          if (var3 == 0
              || var3 == this.field_77289_h - 1
              || var4 == 0
              || var4 == this.field_77289_h - 1
              || var5 == 0
              || var5 == this.field_77289_h - 1) {
            double var12 =
                (double) ((float) var3 / ((float) this.field_77289_h - 1.0F) * 2.0F - 1.0F);
            double var14 =
                (double) ((float) var4 / ((float) this.field_77289_h - 1.0F) * 2.0F - 1.0F);
            double var16 =
                (double) ((float) var5 / ((float) this.field_77289_h - 1.0F) * 2.0F - 1.0F);
            double var18 = Math.sqrt(var12 * var12 + var14 * var14 + var16 * var16);
            var12 /= var18;
            var14 /= var18;
            var16 /= var18;
            float var20 = this.size * (0.7F + this.world.random.nextFloat() * 0.6F);
            var6 = this.posX;
            var8 = this.posY;
            var10 = this.posZ;

            for (float var21 = 0.3F; var20 > 0.0F; var20 -= var21 * 0.75F) {
              int var22 = MathHelper.floor(var6);
              int var23 = MathHelper.floor(var8);
              int var24 = MathHelper.floor(var10);
              int var25 = this.world.getTypeId(var22, var23, var24);

              if (var25 > 0) {
                Block var26 = Block.byId[var25];
                float var27 =
                    this.source != null
                        ? this.source.func_82146_a(this, var26, var22, var23, var24)
                        : var26.getExplosionResistance(
                            this.source,
                            this.world,
                            var22,
                            var23,
                            var24,
                            this.posX,
                            this.posY,
                            this.posZ);
                var20 -= (var27 + 0.3F) * var21;
              }

              if (var20 > 0.0F) {
                var2.add(new ChunkPosition(var22, var23, var24));
              }

              var6 += var12 * (double) var21;
              var8 += var14 * (double) var21;
              var10 += var16 * (double) var21;
            }
          }
        }
      }
    }

    this.field_77281_g.addAll(var2);
    this.size *= 2.0F;
    var3 = MathHelper.floor(this.posX - (double) this.size - 1.0D);
    var4 = MathHelper.floor(this.posX + (double) this.size + 1.0D);
    var5 = MathHelper.floor(this.posY - (double) this.size - 1.0D);
    int var28 = MathHelper.floor(this.posY + (double) this.size + 1.0D);
    int var13 = MathHelper.floor(this.posZ - (double) this.size - 1.0D);
    int var29 = MathHelper.floor(this.posZ + (double) this.size + 1.0D);
    List var15 =
        this.world.getEntities(
            this.source,
            AxisAlignedBB.a()
                .a(
                    (double) var3,
                    (double) var5,
                    (double) var13,
                    (double) var4,
                    (double) var28,
                    (double) var29));
    Vec3D var30 = this.world.getVec3DPool().create(this.posX, this.posY, this.posZ);

    for (int var17 = 0; var17 < var15.size(); ++var17) {
      Entity var31 = (Entity) var15.get(var17);
      double var19 = var31.f(this.posX, this.posY, this.posZ) / (double) this.size;

      if (var19 <= 1.0D) {
        var6 = var31.locX - this.posX;
        var8 = var31.locY + (double) var31.getHeadHeight() - this.posY;
        var10 = var31.locZ - this.posZ;
        double var33 = (double) MathHelper.sqrt(var6 * var6 + var8 * var8 + var10 * var10);

        if (var33 != 0.0D) {
          var6 /= var33;
          var8 /= var33;
          var10 /= var33;
          double var32 = (double) this.world.a(var30, var31.boundingBox);
          double var34 = (1.0D - var19) * var32;
          var31.damageEntity(
              DamageSource.EXPLOSION,
              (int) ((var34 * var34 + var34) / 2.0D * 8.0D * (double) this.size + 1.0D));
          var31.motX += var6 * var34;
          var31.motY += var8 * var34;
          var31.motZ += var10 * var34;

          if (var31 instanceof EntityHuman) {
            this.field_77288_k.put(
                (EntityHuman) var31,
                this.world.getVec3DPool().create(var6 * var34, var8 * var34, var10 * var34));
          }
        }
      }
    }

    this.size = var1;
  }
Пример #7
0
  public void a() {
    float f = this.size;
    byte b0 = 16;

    int i;
    int j;
    int k;
    double d0;
    double d1;
    double d2;

    for (i = 0; i < b0; ++i) {
      for (j = 0; j < b0; ++j) {
        for (k = 0; k < b0; ++k) {
          if (i == 0 || i == b0 - 1 || j == 0 || j == b0 - 1 || k == 0 || k == b0 - 1) {
            double d3 = (double) ((float) i / ((float) b0 - 1.0F) * 2.0F - 1.0F);
            double d4 = (double) ((float) j / ((float) b0 - 1.0F) * 2.0F - 1.0F);
            double d5 = (double) ((float) k / ((float) b0 - 1.0F) * 2.0F - 1.0F);
            double d6 = Math.sqrt(d3 * d3 + d4 * d4 + d5 * d5);

            d3 /= d6;
            d4 /= d6;
            d5 /= d6;
            float f1 = this.size * (0.7F + this.world.random.nextFloat() * 0.6F);

            d0 = this.posX;
            d1 = this.posY;
            d2 = this.posZ;

            for (float f2 = 0.3F; f1 > 0.0F; f1 -= f2 * 0.75F) {
              int l = MathHelper.floor(d0);
              int i1 = MathHelper.floor(d1);
              int j1 = MathHelper.floor(d2);
              int k1 = this.world.getTypeId(l, i1, j1);

              if (k1 > 0) {
                f1 -= (Block.byId[k1].a(this.source) + 0.3F) * f2;
              }

              if (f1 > 0.0F) {
                this.g.add(new ChunkPosition(l, i1, j1));
              }

              d0 += d3 * (double) f2;
              d1 += d4 * (double) f2;
              d2 += d5 * (double) f2;
            }
          }
        }
      }
    }

    this.size *= 2.0F;
    i = MathHelper.floor(this.posX - (double) this.size - 1.0D);
    j = MathHelper.floor(this.posX + (double) this.size + 1.0D);
    k = MathHelper.floor(this.posY - (double) this.size - 1.0D);
    int l1 = MathHelper.floor(this.posY + (double) this.size + 1.0D);
    int i2 = MathHelper.floor(this.posZ - (double) this.size - 1.0D);
    int j2 = MathHelper.floor(this.posZ + (double) this.size + 1.0D);
    List list =
        this.world.b(
            this.source,
            AxisAlignedBB.b(
                (double) i, (double) k, (double) i2, (double) j, (double) l1, (double) j2));
    Vec3D vec3d = Vec3D.create(this.posX, this.posY, this.posZ);

    for (int k2 = 0; k2 < list.size(); ++k2) {
      Entity entity = (Entity) list.get(k2);
      double d7 = entity.e(this.posX, this.posY, this.posZ) / (double) this.size;

      if (d7 <= 1.0D) {
        d0 = entity.locX - this.posX;
        d1 = entity.locY - this.posY;
        d2 = entity.locZ - this.posZ;
        double d8 = (double) MathHelper.a(d0 * d0 + d1 * d1 + d2 * d2);

        d0 /= d8;
        d1 /= d8;
        d2 /= d8;
        double d9 = (double) this.world.a(vec3d, entity.boundingBox);
        double d10 = (1.0D - d7) * d9;

        // CraftBukkit start - explosion damage hook
        CraftServer server = ((WorldServer) this.world).getServer();
        org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity();
        DamageCause damageType;
        int damageDone = (int) ((d10 * d10 + d10) / 2.0D * 8.0D * (double) this.size + 1.0D);

        if (damagee == null) {
          // nothing was hurt
        } else if (this.source == null) { // Block explosion
          // TODO: get the x/y/z of the tnt block?
          // does this even get called ever? @see EntityTNTPrimed - not BlockTNT or whatever
          damageType = EntityDamageEvent.DamageCause.BLOCK_EXPLOSION;

          EntityDamageByBlockEvent event =
              new EntityDamageByBlockEvent(null, damagee, damageType, damageDone);
          server.getPluginManager().callEvent(event);

          if (!event.isCancelled()) {
            entity.damageEntity(this.source, event.getDamage());
            entity.motX += d0 * d10;
            entity.motY += d1 * d10;
            entity.motZ += d2 * d10;
          }
        } else {
          org.bukkit.entity.Entity damager = this.source.getBukkitEntity();
          damageType = EntityDamageEvent.DamageCause.ENTITY_EXPLOSION;

          EntityDamageByEntityEvent event =
              new EntityDamageByEntityEvent(damager, damagee, damageType, damageDone);
          server.getPluginManager().callEvent(event);

          if (!event.isCancelled()) {
            entity.damageEntity(this.source, event.getDamage());

            entity.motX += d0 * d10;
            entity.motY += d1 * d10;
            entity.motZ += d2 * d10;
          }
        }
        // CraftBukkit end
      }
    }

    this.size = f;
    ArrayList arraylist = new ArrayList();

    arraylist.addAll(this.g);
    if (this.a) {
      for (int l2 = arraylist.size() - 1; l2 >= 0; --l2) {
        ChunkPosition chunkposition = (ChunkPosition) arraylist.get(l2);
        int i3 = chunkposition.x;
        int j3 = chunkposition.y;
        int k3 = chunkposition.z;
        int l3 = this.world.getTypeId(i3, j3, k3);
        int i4 = this.world.getTypeId(i3, j3 - 1, k3);

        if (l3 == 0 && Block.o[i4] && this.h.nextInt(3) == 0) {
          this.world.setTypeId(i3, j3, k3, Block.FIRE.id);
        }
      }
    }
  }
Пример #8
0
  public void a() {
    // CraftBukkit start
    if (this.size < 0.1F) {
      return;
    }
    // CraftBukkit end

    float f = this.size;
    HashSet hashset = new HashSet();

    int i;
    int j;
    int k;
    double d0;
    double d1;
    double d2;

    for (i = 0; i < this.i; ++i) {
      for (j = 0; j < this.i; ++j) {
        for (k = 0; k < this.i; ++k) {
          if (i == 0 || i == this.i - 1 || j == 0 || j == this.i - 1 || k == 0 || k == this.i - 1) {
            double d3 = (double) ((float) i / ((float) this.i - 1.0F) * 2.0F - 1.0F);
            double d4 = (double) ((float) j / ((float) this.i - 1.0F) * 2.0F - 1.0F);
            double d5 = (double) ((float) k / ((float) this.i - 1.0F) * 2.0F - 1.0F);
            double d6 = Math.sqrt(d3 * d3 + d4 * d4 + d5 * d5);

            d3 /= d6;
            d4 /= d6;
            d5 /= d6;
            float f1 = this.size * (0.7F + this.world.random.nextFloat() * 0.6F);

            d0 = this.posX;
            d1 = this.posY;
            d2 = this.posZ;

            for (float f2 = 0.3F; f1 > 0.0F; f1 -= f2 * 0.75F) {
              int l = MathHelper.floor(d0);
              int i1 = MathHelper.floor(d1);
              int j1 = MathHelper.floor(d2);
              int k1 = this.world.getTypeId(l, i1, j1);

              if (k1 > 0) {
                Block block = Block.byId[k1];
                float f3 =
                    this.source != null
                        ? this.source.a(this, this.world, l, i1, j1, block)
                        : block.a(this.source);

                f1 -= (f3 + 0.3F) * f2;
              }

              if (f1 > 0.0F
                  && (this.source == null || this.source.a(this, this.world, l, i1, j1, k1, f1))
                  && i1 < 256
                  && i1 >= 0) { // CraftBukkit - don't wrap explosions
                hashset.add(new ChunkPosition(l, i1, j1));
              }

              d0 += d3 * (double) f2;
              d1 += d4 * (double) f2;
              d2 += d5 * (double) f2;
            }
          }
        }
      }
    }

    this.blocks.addAll(hashset);
    this.size *= 2.0F;
    i = MathHelper.floor(this.posX - (double) this.size - 1.0D);
    j = MathHelper.floor(this.posX + (double) this.size + 1.0D);
    k = MathHelper.floor(this.posY - (double) this.size - 1.0D);
    int l1 = MathHelper.floor(this.posY + (double) this.size + 1.0D);
    int i2 = MathHelper.floor(this.posZ - (double) this.size - 1.0D);
    int j2 = MathHelper.floor(this.posZ + (double) this.size + 1.0D);
    List list =
        this.world.getEntities(
            this.source,
            AxisAlignedBB.a()
                .a((double) i, (double) k, (double) i2, (double) j, (double) l1, (double) j2));
    Vec3D vec3d = this.world.getVec3DPool().create(this.posX, this.posY, this.posZ);

    for (int k2 = 0; k2 < list.size(); ++k2) {
      Entity entity = (Entity) list.get(k2);
      double d7 = entity.f(this.posX, this.posY, this.posZ) / (double) this.size;

      if (d7 <= 1.0D) {
        d0 = entity.locX - this.posX;
        d1 = entity.locY + (double) entity.getHeadHeight() - this.posY;
        d2 = entity.locZ - this.posZ;
        double d8 = (double) MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2);

        if (d8 != 0.0D) {
          d0 /= d8;
          d1 /= d8;
          d2 /= d8;
          double d9 = (double) this.world.a(vec3d, entity.boundingBox);
          double d10 = (1.0D - d7) * d9;

          // CraftBukkit start - Explosion damage hook
          org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity();
          float damageDone =
              (float) ((int) ((d10 * d10 + d10) / 2.0D * 8.0D * (double) this.size + 1.0D));

          if (damagee == null) {
            // nothing was hurt
          } else if (this.source == null) { // Block explosion (without an entity source; bed etc.)
            EntityDamageByBlockEvent event =
                new EntityDamageByBlockEvent(
                    null, damagee, EntityDamageEvent.DamageCause.BLOCK_EXPLOSION, damageDone);
            Bukkit.getPluginManager().callEvent(event);

            if (!event.isCancelled()) {
              damagee.setLastDamageCause(event);
              entity.damageEntity(DamageSource.explosion(this), (float) event.getDamage());
              double d11 = EnchantmentProtection.a(entity, d10);

              entity.motX += d0 * d11;
              entity.motY += d1 * d11;
              entity.motZ += d2 * d11;
              if (entity instanceof EntityHuman) {
                this.l.put(
                    (EntityHuman) entity,
                    this.world.getVec3DPool().create(d0 * d10, d1 * d10, d2 * d10));
              }
            }
          } else {
            final org.bukkit.entity.Entity damager = this.source.getBukkitEntity();
            final EntityDamageEvent.DamageCause damageCause;

            if (damager instanceof org.bukkit.entity.TNTPrimed) {
              damageCause = EntityDamageEvent.DamageCause.BLOCK_EXPLOSION;
            } else {
              damageCause = EntityDamageEvent.DamageCause.ENTITY_EXPLOSION;
            }

            EntityDamageByEntityEvent event =
                new EntityDamageByEntityEvent(damager, damagee, damageCause, damageDone);
            Bukkit.getPluginManager().callEvent(event);

            if (!event.isCancelled()) {
              entity.getBukkitEntity().setLastDamageCause(event);
              entity.damageEntity(DamageSource.explosion(this), (float) event.getDamage());

              entity.motX += d0 * d10;
              entity.motY += d1 * d10;
              entity.motZ += d2 * d10;
              if (entity instanceof EntityHuman) {
                this.l.put(
                    (EntityHuman) entity,
                    this.world.getVec3DPool().create(d0 * d10, d1 * d10, d2 * d10));
              }
            }
          }
          // CraftBukkit end
        }
      }
    }

    this.size = f;
  }
Пример #9
0
  public void a() {
    // CraftBukkit start
    if (this.size < 0.1F) {
      return;
    }
    // CraftBukkit end
    HashSet hashset = Sets.newHashSet();
    boolean flag = true;

    int i;
    int j;

    for (int k = 0; k < 16; ++k) {
      for (i = 0; i < 16; ++i) {
        for (j = 0; j < 16; ++j) {
          if (k == 0 || k == 15 || i == 0 || i == 15 || j == 0 || j == 15) {
            double d0 = (double) ((float) k / 15.0F * 2.0F - 1.0F);
            double d1 = (double) ((float) i / 15.0F * 2.0F - 1.0F);
            double d2 = (double) ((float) j / 15.0F * 2.0F - 1.0F);
            double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);

            d0 /= d3;
            d1 /= d3;
            d2 /= d3;
            float f = this.size * (0.7F + this.world.random.nextFloat() * 0.6F);
            double d4 = this.posX;
            double d5 = this.posY;
            double d6 = this.posZ;

            for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
              BlockPosition blockposition = new BlockPosition(d4, d5, d6);
              IBlockData iblockdata = this.world.getType(blockposition);

              if (iblockdata.getBlock().getMaterial() != Material.AIR) {
                float f2 =
                    this.source != null
                        ? this.source.a(this, this.world, blockposition, iblockdata)
                        : iblockdata.getBlock().a((Entity) null);

                f -= (f2 + 0.3F) * 0.3F;
              }

              if (f > 0.0F
                  && (this.source == null
                      || this.source.a(this, this.world, blockposition, iblockdata, f))
                  && blockposition.getY() < 256
                  && blockposition.getY() >= 0) { // CraftBukkit - don't wrap explosions
                hashset.add(blockposition);
              }

              d4 += d0 * 0.30000001192092896D;
              d5 += d1 * 0.30000001192092896D;
              d6 += d2 * 0.30000001192092896D;
            }
          }
        }
      }
    }

    this.blocks.addAll(hashset);
    float f3 = this.size * 2.0F;

    i = MathHelper.floor(this.posX - (double) f3 - 1.0D);
    j = MathHelper.floor(this.posX + (double) f3 + 1.0D);
    int l = MathHelper.floor(this.posY - (double) f3 - 1.0D);
    int i1 = MathHelper.floor(this.posY + (double) f3 + 1.0D);
    int j1 = MathHelper.floor(this.posZ - (double) f3 - 1.0D);
    int k1 = MathHelper.floor(this.posZ + (double) f3 + 1.0D);
    List list =
        this.world.getEntities(
            this.source,
            new AxisAlignedBB(
                (double) i, (double) l, (double) j1, (double) j, (double) i1, (double) k1));
    Vec3D vec3d = new Vec3D(this.posX, this.posY, this.posZ);

    for (int l1 = 0; l1 < list.size(); ++l1) {
      Entity entity = (Entity) list.get(l1);

      if (!entity.aW()) {
        double d7 = entity.f(this.posX, this.posY, this.posZ) / (double) f3;

        if (d7 <= 1.0D) {
          double d8 = entity.locX - this.posX;
          double d9 = entity.locY + (double) entity.getHeadHeight() - this.posY;
          double d10 = entity.locZ - this.posZ;
          double d11 = (double) MathHelper.sqrt(d8 * d8 + d9 * d9 + d10 * d10);

          if (d11 != 0.0D) {
            d8 /= d11;
            d9 /= d11;
            d10 /= d11;
            double d12 = (double) this.world.a(vec3d, entity.getBoundingBox());
            double d13 = (1.0D - d7) * d12;

            // entity.damageEntity(DamageSource.explosion(this), (float) ((int) ((d13 * d13 + d13) /
            // 2.0D * 8.0D * (double) f3 + 1.0D)));+                        // CraftBukkit start
            CraftEventFactory.entityDamage = source;
            boolean wasDamaged =
                entity.damageEntity(
                    DamageSource.explosion(this),
                    (float) ((int) ((d13 * d13 + d13) / 2.0D * 8.0D * (double) f3 + 1.0D)));
            CraftEventFactory.entityDamage = null;
            if (!wasDamaged
                && !(entity instanceof EntityTNTPrimed || entity instanceof EntityFallingBlock)) {
              continue;
            }
            // CraftBukkit end
            double d14 = EnchantmentProtection.a(entity, d13);

            entity.motX += d8 * d14;
            entity.motY += d9 * d14;
            entity.motZ += d10 * d14;
            if (entity instanceof EntityHuman && !((EntityHuman) entity).abilities.isInvulnerable) {
              this.k.put((EntityHuman) entity, new Vec3D(d8 * d13, d9 * d13, d10 * d13));
            }
          }
        }
      }
    }
  }