예제 #1
0
  /** Applies a velocity to each of the entities pushing them away from each other. Args: entity */
  public void applyEntityCollision(Entity par1Entity) {
    if (worldObj.isRemote) {
      return;
    }

    if (par1Entity == riddenByEntity) {
      return;
    }

    if ((par1Entity instanceof EntityLiving)
        && !(par1Entity instanceof EntityPlayer)
        && !(par1Entity instanceof EntityIronGolem)
        && minecartType == 0
        && motionX * motionX + motionZ * motionZ > 0.01D
        && riddenByEntity == null
        && par1Entity.ridingEntity == null) {
      par1Entity.mountEntity(this);
    }

    double d = par1Entity.posX - posX;
    double d1 = par1Entity.posZ - posZ;
    double d2 = d * d + d1 * d1;

    if (d2 >= 10.0E-005D) {
      d2 = MathHelper.sqrt_double(d2);
      d /= d2;
      d1 /= d2;
      double d3 = 1.0D / d2;

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

      d *= d3;
      d1 *= d3;
      d *= 0.1D;
      d1 *= 0.1D;
      d *= 1.0F - entityCollisionReduction;
      d1 *= 1.0F - entityCollisionReduction;
      d *= 0.5D;
      d1 *= 0.5D;

      if (par1Entity instanceof EntityMinecart) {
        double d4 = par1Entity.motionX + motionX;
        double d5 = par1Entity.motionZ + motionZ;

        if (((EntityMinecart) par1Entity).minecartType == 2 && minecartType != 2) {
          motionX *= 0.2D;
          motionZ *= 0.2D;
          addVelocity(par1Entity.motionX - d, 0.0D, par1Entity.motionZ - d1);
          par1Entity.motionX *= 0.95D;
          par1Entity.motionZ *= 0.95D;
        } else if (((EntityMinecart) par1Entity).minecartType != 2 && minecartType == 2) {
          par1Entity.motionX *= 0.2D;
          par1Entity.motionZ *= 0.2D;
          par1Entity.addVelocity(motionX + d, 0.0D, motionZ + d1);
          motionX *= 0.95D;
          motionZ *= 0.95D;
        } else {
          d4 /= 2D;
          d5 /= 2D;
          motionX *= 0.2D;
          motionZ *= 0.2D;
          addVelocity(d4 - d, 0.0D, d5 - d1);
          par1Entity.motionX *= 0.2D;
          par1Entity.motionZ *= 0.2D;
          par1Entity.addVelocity(d4 + d, 0.0D, d5 + d1);
        }
      } else {
        addVelocity(-d, 0.0D, -d1);
        par1Entity.addVelocity(d / 4D, 0.0D, d1 / 4D);
      }
    }
  }
예제 #2
0
  /** Does the first part of the explosion (destroy blocks) */
  public void doExplosionA() {
    float var1 = this.explosionSize;
    HashSet var2 = new HashSet();
    int var3;
    int var4;
    int var5;
    double var15;
    double var17;
    double var19;

    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 var6 =
                (double) ((float) var3 / ((float) this.field_77289_h - 1.0F) * 2.0F - 1.0F);
            double var8 =
                (double) ((float) var4 / ((float) this.field_77289_h - 1.0F) * 2.0F - 1.0F);
            double var10 =
                (double) ((float) var5 / ((float) this.field_77289_h - 1.0F) * 2.0F - 1.0F);
            double var12 = Math.sqrt(var6 * var6 + var8 * var8 + var10 * var10);
            var6 /= var12;
            var8 /= var12;
            var10 /= var12;
            float var14 = this.explosionSize * (0.7F + this.worldObj.rand.nextFloat() * 0.6F);
            var15 = this.explosionX;
            var17 = this.explosionY;
            var19 = this.explosionZ;

            for (float var21 = 0.3F; var14 > 0.0F; var14 -= var21 * 0.75F) {
              int var22 = MathHelper.floor_double(var15);
              int var23 = MathHelper.floor_double(var17);
              int var24 = MathHelper.floor_double(var19);
              int var25 = this.worldObj.getBlockId(var22, var23, var24);

              if (var25 > 0) {
                Block var26 = Block.blocksList[var25];
                float var27 =
                    this.exploder != null
                        ? this.exploder.func_82146_a(this, var26, var22, var23, var24)
                        : var26.getExplosionResistance(this.exploder);
                var14 -= (var27 + 0.3F) * var21;
              }

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

              var15 += var6 * (double) var21;
              var17 += var8 * (double) var21;
              var19 += var10 * (double) var21;
            }
          }
        }
      }
    }

    this.affectedBlockPositions.addAll(var2);
    this.explosionSize *= 2.0F;
    var3 = MathHelper.floor_double(this.explosionX - (double) this.explosionSize - 1.0D);
    var4 = MathHelper.floor_double(this.explosionX + (double) this.explosionSize + 1.0D);
    var5 = MathHelper.floor_double(this.explosionY - (double) this.explosionSize - 1.0D);
    int var28 = MathHelper.floor_double(this.explosionY + (double) this.explosionSize + 1.0D);
    int var7 = MathHelper.floor_double(this.explosionZ - (double) this.explosionSize - 1.0D);
    int var29 = MathHelper.floor_double(this.explosionZ + (double) this.explosionSize + 1.0D);
    List var9 =
        this.worldObj.getEntitiesWithinAABBExcludingEntity(
            this.exploder,
            AxisAlignedBB.getAABBPool()
                .addOrModifyAABBInPool(
                    (double) var3,
                    (double) var5,
                    (double) var7,
                    (double) var4,
                    (double) var28,
                    (double) var29));
    Vec3 var30 =
        this.worldObj
            .getWorldVec3Pool()
            .getVecFromPool(this.explosionX, this.explosionY, this.explosionZ);

    for (int var11 = 0; var11 < var9.size(); ++var11) {
      Entity var31 = (Entity) var9.get(var11);
      double var13 =
          var31.getDistance(this.explosionX, this.explosionY, this.explosionZ)
              / (double) this.explosionSize;

      if (var13 <= 1.0D) {
        var15 = var31.posX - this.explosionX;
        var17 = var31.posY + (double) var31.getEyeHeight() - this.explosionY;
        var19 = var31.posZ - this.explosionZ;
        double var33 =
            (double) MathHelper.sqrt_double(var15 * var15 + var17 * var17 + var19 * var19);

        if (var33 != 0.0D) {
          var15 /= var33;
          var17 /= var33;
          var19 /= var33;
          double var32 = (double) this.worldObj.getBlockDensity(var30, var31.boundingBox);
          double var34 = (1.0D - var13) * var32;
          var31.attackEntityFrom(
              DamageSource.explosion,
              (int) ((var34 * var34 + var34) / 2.0D * 8.0D * (double) this.explosionSize + 1.0D));
          var31.motionX += var15 * var34;
          var31.motionY += var17 * var34;
          var31.motionZ += var19 * var34;

          if (var31 instanceof EntityPlayer) {
            this.field_77288_k.put(
                (EntityPlayer) var31,
                this.worldObj
                    .getWorldVec3Pool()
                    .getVecFromPool(var15 * var34, var17 * var34, var19 * var34));
          }
        }
      }
    }

    this.explosionSize = var1;
  }
예제 #3
0
  /** Applies a velocity to each of the entities pushing them away from each other. Args: entity */
  public void applyEntityCollision(Entity par1Entity) {
    if (!this.worldObj.isRemote) {
      if (par1Entity != this.riddenByEntity) {
        if (par1Entity instanceof EntityLiving
            && !(par1Entity instanceof EntityPlayer)
            && !(par1Entity instanceof EntityIronGolem)
            && this.minecartType == 0
            && this.motionX * this.motionX + this.motionZ * this.motionZ > 0.01D
            && this.riddenByEntity == null
            && par1Entity.ridingEntity == null) {
          par1Entity.mountEntity(this);
        }

        double var2 = par1Entity.posX - this.posX;
        double var4 = par1Entity.posZ - this.posZ;
        double var6 = var2 * var2 + var4 * var4;

        if (var6 >= 9.999999747378752E-5D) {
          var6 = (double) MathHelper.sqrt_double(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.entityCollisionReduction);
          var4 *= (double) (1.0F - this.entityCollisionReduction);
          var2 *= 0.5D;
          var4 *= 0.5D;

          if (par1Entity instanceof EntityMinecart) {
            double var10 = par1Entity.posX - this.posX;
            double var12 = par1Entity.posZ - this.posZ;
            Vec3 var14 =
                this.worldObj.getWorldVec3Pool().getVecFromPool(var10, 0.0D, var12).normalize();
            Vec3 var15 =
                this.worldObj
                    .getWorldVec3Pool()
                    .getVecFromPool(
                        (double) MathHelper.cos(this.rotationYaw * (float) Math.PI / 180.0F),
                        0.0D,
                        (double) MathHelper.sin(this.rotationYaw * (float) Math.PI / 180.0F))
                    .normalize();
            double var16 = Math.abs(var14.dotProduct(var15));

            if (var16 < 0.800000011920929D) {
              return;
            }

            double var18 = par1Entity.motionX + this.motionX;
            double var20 = par1Entity.motionZ + this.motionZ;

            if (((EntityMinecart) par1Entity).minecartType == 2 && this.minecartType != 2) {
              this.motionX *= 0.20000000298023224D;
              this.motionZ *= 0.20000000298023224D;
              this.addVelocity(par1Entity.motionX - var2, 0.0D, par1Entity.motionZ - var4);
              par1Entity.motionX *= 0.949999988079071D;
              par1Entity.motionZ *= 0.949999988079071D;
            } else if (((EntityMinecart) par1Entity).minecartType != 2 && this.minecartType == 2) {
              par1Entity.motionX *= 0.20000000298023224D;
              par1Entity.motionZ *= 0.20000000298023224D;
              par1Entity.addVelocity(this.motionX + var2, 0.0D, this.motionZ + var4);
              this.motionX *= 0.949999988079071D;
              this.motionZ *= 0.949999988079071D;
            } else {
              var18 /= 2.0D;
              var20 /= 2.0D;
              this.motionX *= 0.20000000298023224D;
              this.motionZ *= 0.20000000298023224D;
              this.addVelocity(var18 - var2, 0.0D, var20 - var4);
              par1Entity.motionX *= 0.20000000298023224D;
              par1Entity.motionZ *= 0.20000000298023224D;
              par1Entity.addVelocity(var18 + var2, 0.0D, var20 + var4);
            }
          } else {
            this.addVelocity(-var2, 0.0D, -var4);
            par1Entity.addVelocity(var2 / 4.0D, 0.0D, var4 / 4.0D);
          }
        }
      }
    }
  }
예제 #4
0
 public void setVelocity(Vector velocity) {
   handle.motionX = velocity.getX();
   handle.motionY = velocity.getY();
   handle.motionZ = velocity.getZ();
 }
  public void doExplosion() {
    float f = explosionSize;
    int i = 16;
    for (int j = 0; j < i; j++) {
      for (int l = 0; l < i; l++) {
        label0:
        for (int j1 = 0; j1 < i; j1++) {
          if (j != 0 && j != i - 1 && l != 0 && l != i - 1 && j1 != 0 && j1 != i - 1) {
            continue;
          }
          double d = ((float) j / ((float) i - 1.0F)) * 2.0F - 1.0F;
          double d1 = ((float) l / ((float) i - 1.0F)) * 2.0F - 1.0F;
          double d2 = ((float) j1 / ((float) i - 1.0F)) * 2.0F - 1.0F;
          double d3 = Math.sqrt(d * d + d1 * d1 + d2 * d2);
          d /= d3;
          d1 /= d3;
          d2 /= d3;
          float f1 = explosionSize * (0.7F + worldObj.rand.nextFloat() * 0.6F);
          double d5 = explosionX;
          double d7 = explosionY;
          double d9 = explosionZ;
          float f2 = 0.3F;
          do {
            if (f1 <= 0.0F) {
              continue label0;
            }
            int j4 = MathHelper.floor_double(d5);
            int k4 = MathHelper.floor_double(d7);
            int l4 = MathHelper.floor_double(d9);
            int i5 = worldObj.getBlockId(j4, k4, l4);
            if (i5 > 0) {
              f1 -= (Block.blocksList[i5].getExplosionResistance(exploder) + 0.3F) * f2;
            }
            if (f1 > 0.0F) {
              destroyedBlockPositions.add(new ChunkPosition(j4, k4, l4));
            }
            d5 += d * (double) f2;
            d7 += d1 * (double) f2;
            d9 += d2 * (double) f2;
            f1 -= f2 * 0.75F;
          } while (true);
        }
      }
    }

    explosionSize *= 2.0F;
    int k = MathHelper.floor_double(explosionX - (double) explosionSize - 1.0D);
    int i1 = MathHelper.floor_double(explosionX + (double) explosionSize + 1.0D);
    int k1 = MathHelper.floor_double(explosionY - (double) explosionSize - 1.0D);
    int l1 = MathHelper.floor_double(explosionY + (double) explosionSize + 1.0D);
    int i2 = MathHelper.floor_double(explosionZ - (double) explosionSize - 1.0D);
    int j2 = MathHelper.floor_double(explosionZ + (double) explosionSize + 1.0D);
    List list =
        worldObj.getEntitiesWithinAABBExcludingEntity(
            exploder, AxisAlignedBB.getBoundingBoxFromPool(k, k1, i2, i1, l1, j2));
    Vec3D vec3d = Vec3D.createVector(explosionX, explosionY, explosionZ);
    for (int k2 = 0; k2 < list.size(); k2++) {
      Entity entity = (Entity) list.get(k2);
      double d4 = entity.getDistance(explosionX, explosionY, explosionZ) / (double) explosionSize;
      if (d4 <= 1.0D) {
        double d6 = entity.posX - explosionX;
        double d8 = entity.posY - explosionY;
        double d10 = entity.posZ - explosionZ;
        double d11 = MathHelper.sqrt_double(d6 * d6 + d8 * d8 + d10 * d10);
        d6 /= d11;
        d8 /= d11;
        d10 /= d11;
        double d12 = worldObj.func_494_a(vec3d, entity.boundingBox);
        double d13 = (1.0D - d4) * d12;
        entity.attackEntityFrom(
            exploder, (int) (((d13 * d13 + d13) / 2D) * 8D * (double) explosionSize + 1.0D));
        double d14 = d13;
        entity.motionX += d6 * d14;
        entity.motionY += d8 * d14;
        entity.motionZ += d10 * d14;
      }
    }

    explosionSize = f;
    ArrayList arraylist = new ArrayList();
    arraylist.addAll(destroyedBlockPositions);
    if (isFlaming) {
      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 = worldObj.getBlockId(i3, j3, k3);
        int i4 = worldObj.getBlockId(i3, j3 - 1, k3);
        if (l3 == 0 && Block.opaqueCubeLookup[i4] && ExplosionRNG.nextInt(3) == 0) {
          worldObj.setBlockWithNotify(i3, j3, k3, Block.fire.blockID);
        }
      }
    }
  }