Ejemplo n.º 1
0
  @SideOnly(Side.CLIENT)
  public static void func_150918_a(
      World p_150918_0_, int p_150918_1_, int p_150918_2_, int p_150918_3_, int p_150918_4_) {
    if (p_150918_4_ == 0) {
      p_150918_4_ = 15;
    }

    Block block = p_150918_0_.getBlock(p_150918_1_, p_150918_2_, p_150918_3_);

    if (block.getMaterial() != Material.air) {
      block.setBlockBoundsBasedOnState(p_150918_0_, p_150918_1_, p_150918_2_, p_150918_3_);

      for (int i1 = 0; i1 < p_150918_4_; ++i1) {
        double d0 = itemRand.nextGaussian() * 0.02D;
        double d1 = itemRand.nextGaussian() * 0.02D;
        double d2 = itemRand.nextGaussian() * 0.02D;
        p_150918_0_.spawnParticle(
            "happyVillager",
            (double) ((float) p_150918_1_ + itemRand.nextFloat()),
            (double) p_150918_2_ + (double) itemRand.nextFloat() * block.getBlockBoundsMaxY(),
            (double) ((float) p_150918_3_ + itemRand.nextFloat()),
            d0,
            d1,
            d2);
      }
    } else {
      for (int i1 = 0; i1 < p_150918_4_; ++i1) {
        double d0 = itemRand.nextGaussian() * 0.02D;
        double d1 = itemRand.nextGaussian() * 0.02D;
        double d2 = itemRand.nextGaussian() * 0.02D;
        p_150918_0_.spawnParticle(
            "happyVillager",
            (double) ((float) p_150918_1_ + itemRand.nextFloat()),
            (double) p_150918_2_ + (double) itemRand.nextFloat() * 1.0f,
            (double) ((float) p_150918_3_ + itemRand.nextFloat()),
            d0,
            d1,
            d2);
      }
    }
  }
 private void setBlockBoundsBasedOnSelection(World world, int x, int y, int z) {
   float m = ConfigurationLib.littleBlocksSize;
   if (xSelected == -10) {
     this.setBlockBounds(0f, 0f, 0f, 0f, 0f, 0f);
   } else {
     TileEntityLittleChunk tile = (TileEntityLittleChunk) world.getTileEntity(x, y, z);
     Block block = tile.getBlock(xSelected, ySelected, zSelected);
     // System.out.println("Content: " + content);
     if (block == null) {
       this.setBlockBounds(
           xSelected / m,
           ySelected / m,
           zSelected / m,
           (xSelected + 1) / m,
           (ySelected + 1) / m,
           (zSelected + 1) / m);
     } else {
       if (block != null) {
         if (BlockStairs.func_150148_a /* isBlockStairsID */(block)) {
           block.setBlockBounds(0, 0, 0, 1, 1, 1);
         } else {
           block.setBlockBoundsBasedOnState(
               tile.getLittleWorld(),
               (x << 3) + xSelected,
               (y << 3) + ySelected,
               (z << 3) + zSelected);
         }
         this.setBlockBounds(
             (float) (xSelected + block.getBlockBoundsMinX()) / m,
             (float) (ySelected + block.getBlockBoundsMinY()) / m,
             (float) (zSelected + block.getBlockBoundsMinZ()) / m,
             (float) (xSelected + block.getBlockBoundsMaxX()) / m,
             (float) (ySelected + block.getBlockBoundsMaxY()) / m,
             (float) (zSelected + block.getBlockBoundsMaxZ()) / m);
       }
     }
   }
 }
  // @Override
  @Override
  public void onUpdate() {
    super.onUpdate();

    if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) {
      float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
      this.prevRotationYaw =
          this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
      // this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(this.motionY, (double)f) *
      // 180.0D / Math.PI);
    }

    Block block =
        this.worldObj.getBlock(this.field_145791_d, this.field_145792_e, this.field_145789_f);

    if (block.getMaterial() != Material.air) {
      block.setBlockBoundsBasedOnState(
          this.worldObj, this.field_145791_d, this.field_145792_e, this.field_145789_f);
      AxisAlignedBB axisalignedbb =
          block.getCollisionBoundingBoxFromPool(
              this.worldObj, this.field_145791_d, this.field_145792_e, this.field_145789_f);

      if (axisalignedbb != null
          && axisalignedbb.isVecInside(Vec3.createVectorHelper(this.posX, this.posY, this.posZ))) {
        this.inGround = true;
      }
    }

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

    if (this.inGround) {
      /*int j = this.worldObj.getBlockMetadata(this.field_145791_d, this.field_145792_e, this.field_145789_f);

      if (block == this.field_145790_g && j == this.inData)
      {
          ++this.ticksInGround;

          if (this.ticksInGround == 1200)
          {
              this.setDead();
          }
      }
      else
      {
          this.inGround = false;
          this.motionX *= (double)(this.rand.nextFloat() * 0.2F);
          this.motionY *= (double)(this.rand.nextFloat() * 0.2F);
          this.motionZ *= (double)(this.rand.nextFloat() * 0.2F);
          this.ticksInGround = 0;
          this.ticksInAir = 0;
      }*/

      if (!this.worldObj.isRemote) {
        this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 2.5F, true);
        ExplosionChaos.burn(this.worldObj, (int) this.posX, (int) this.posY, (int) this.posZ, 10);
        ExplosionChaos.flameDeath(
            this.worldObj, (int) this.posX, (int) this.posY, (int) this.posZ, 20);
        ExplosionNukeGeneric.waste(
            this.worldObj, (int) this.posX, (int) this.posY, (int) this.posZ, 20);
        ExplosionChaos.poison(this.worldObj, (int) this.posX, (int) this.posY, (int) this.posZ, 20);
      }
      this.worldObj.spawnEntityInWorld(
          new EntityLightningBolt(this.worldObj, this.posX, this.posY, this.posZ));
      this.setDead();
    } else {
      ++this.ticksInAir;
      Vec3 vec31 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
      Vec3 vec3 =
          Vec3.createVectorHelper(
              this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
      MovingObjectPosition movingobjectposition =
          this.worldObj.func_147447_a(vec31, vec3, false, true, false);
      vec31 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
      vec3 =
          Vec3.createVectorHelper(
              this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);

      if (movingobjectposition != null) {
        vec3 =
            Vec3.createVectorHelper(
                movingobjectposition.hitVec.xCoord,
                movingobjectposition.hitVec.yCoord,
                movingobjectposition.hitVec.zCoord);
      }

      Entity entity = null;
      List list =
          this.worldObj.getEntitiesWithinAABBExcludingEntity(
              this,
              this.boundingBox
                  .addCoord(this.motionX, this.motionY, this.motionZ)
                  .expand(1.0D, 1.0D, 1.0D));
      double d0 = 0.0D;
      int i;
      float f1;

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

        if (entity1.canBeCollidedWith()
            && (entity1 != this.shootingEntity || this.ticksInAir >= 5)) {
          f1 = 0.3F;
          AxisAlignedBB axisalignedbb1 = entity1.boundingBox.expand(f1, f1, f1);
          MovingObjectPosition movingobjectposition1 =
              axisalignedbb1.calculateIntercept(vec31, vec3);

          if (movingobjectposition1 != null) {
            double d1 = vec31.distanceTo(movingobjectposition1.hitVec);

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

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

      if (movingobjectposition != null
          && movingobjectposition.entityHit != null
          && movingobjectposition.entityHit instanceof EntityPlayer) {
        EntityPlayer entityplayer = (EntityPlayer) movingobjectposition.entityHit;

        if (entityplayer.capabilities.disableDamage
            || this.shootingEntity instanceof EntityPlayer
                && !((EntityPlayer) this.shootingEntity).canAttackPlayer(entityplayer)) {
          movingobjectposition = null;
        }
      }

      float f2;
      float f4;

      if (movingobjectposition != null) {
        if (movingobjectposition.entityHit != null) {
          f2 =
              MathHelper.sqrt_double(
                  this.motionX * this.motionX
                      + this.motionY * this.motionY
                      + this.motionZ * this.motionZ);
          int k = MathHelper.ceiling_double_int(f2 * this.damage);

          if (this.getIsCritical()) {
            k += this.rand.nextInt(k / 2 + 2);
          }

          DamageSource damagesource = null;

          if (this.shootingEntity == null) {
            damagesource = DamageSource.causeIndirectMagicDamage(this, this);
          } else {
            damagesource = DamageSource.causeIndirectMagicDamage(this, this);
          }

          if (this.isBurning() && !(movingobjectposition.entityHit instanceof EntityEnderman)) {
            movingobjectposition.entityHit.setFire(5);
          }

          if (movingobjectposition.entityHit.attackEntityFrom(damagesource, k)) {
            if (movingobjectposition.entityHit instanceof EntityLivingBase) {
              EntityLivingBase entitylivingbase = (EntityLivingBase) movingobjectposition.entityHit;

              if (!this.worldObj.isRemote) {
                entitylivingbase.setArrowCountInEntity(
                    entitylivingbase.getArrowCountInEntity() + 1);
              }

              if (this.knockbackStrength > 0) {
                f4 =
                    MathHelper.sqrt_double(
                        this.motionX * this.motionX + this.motionZ * this.motionZ);

                if (f4 > 0.0F) {
                  movingobjectposition.entityHit.addVelocity(
                      this.motionX * this.knockbackStrength * 0.6000000238418579D / f4,
                      0.1D,
                      this.motionZ * this.knockbackStrength * 0.6000000238418579D / f4);
                }
              }

              if (this.shootingEntity != null && this.shootingEntity instanceof EntityLivingBase) {
                EnchantmentHelper.func_151384_a(entitylivingbase, this.shootingEntity);
                EnchantmentHelper.func_151385_b(
                    (EntityLivingBase) this.shootingEntity, entitylivingbase);
              }

              if (this.shootingEntity != null
                  && movingobjectposition.entityHit != this.shootingEntity
                  && movingobjectposition.entityHit instanceof EntityPlayer
                  && this.shootingEntity instanceof EntityPlayerMP) {
                ((EntityPlayerMP) this.shootingEntity)
                    .playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(6, 0.0F));
              }
            }

            if (!(movingobjectposition.entityHit instanceof EntityEnderman)) {
              if (!this.worldObj.isRemote) {
                this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 2.5F, true);
              }
              this.setDead();
            }
          } else {
            this.motionX *= -0.10000000149011612D;
            this.motionY *= -0.10000000149011612D;
            this.motionZ *= -0.10000000149011612D;
            this.rotationYaw += 180.0F;
            this.prevRotationYaw += 180.0F;
            this.ticksInAir = 0;
          }
        } else {
          this.field_145791_d = movingobjectposition.blockX;
          this.field_145792_e = movingobjectposition.blockY;
          this.field_145789_f = movingobjectposition.blockZ;
          this.field_145790_g =
              this.worldObj.getBlock(this.field_145791_d, this.field_145792_e, this.field_145789_f);
          this.inData =
              this.worldObj.getBlockMetadata(
                  this.field_145791_d, this.field_145792_e, this.field_145789_f);
          this.motionX = ((float) (movingobjectposition.hitVec.xCoord - this.posX));
          this.motionY = ((float) (movingobjectposition.hitVec.yCoord - this.posY));
          this.motionZ = ((float) (movingobjectposition.hitVec.zCoord - this.posZ));
          f2 =
              MathHelper.sqrt_double(
                  this.motionX * this.motionX
                      + this.motionY * this.motionY
                      + this.motionZ * this.motionZ);
          this.posX -= this.motionX / f2 * 0.05000000074505806D;
          this.posY -= this.motionY / f2 * 0.05000000074505806D;
          this.posZ -= this.motionZ / f2 * 0.05000000074505806D;
          this.playSound("random.bowhit", 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
          this.inGround = true;
          this.arrowShake = 7;
          this.setIsCritical(false);

          if (this.field_145790_g.getMaterial() != Material.air) {
            this.field_145790_g.onEntityCollidedWithBlock(
                this.worldObj, this.field_145791_d, this.field_145792_e, this.field_145789_f, this);
          }
        }
      }

      if (true) {
        for (i = 0; i < 4; ++i) {
          this.worldObj.spawnParticle(
              "smoke",
              this.posX,
              this.posY,
              this.posZ,
              0,
              0,
              0 /*this.posX + this.motionX * (double)i / 4.0D, this.posY + this.motionY * (double)i / 4.0D, this.posZ + this.motionZ * (double)i / 4.0D, -this.motionX, -this.motionY + 0.2D, -this.motionZ*/);
        }
      }

      this.posX += this.motionX;
      this.posY += this.motionY;
      this.posZ += this.motionZ;
      f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
      this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);

      // for (this.rotationPitch = (float)(Math.atan2(this.motionY, (double)f2) * 180.0D / Math.PI);
      // this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
      {;
      }

      /*while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
      {
          this.prevRotationPitch += 360.0F;
      }

      while (this.rotationYaw - this.prevRotationYaw < -180.0F)
      {
          this.prevRotationYaw -= 360.0F;
      }

      while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
      {
          this.prevRotationYaw += 360.0F;
      }*/

      // this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch)
      // * 0.2F;
      // this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
      float f3 = 0.99F;
      f1 = 0.05F;

      if (this.isInWater()) {
        for (int l = 0; l < 4; ++l) {
          f4 = 0.25F;
          this.worldObj.spawnParticle(
              "bubble",
              this.posX - this.motionX * f4,
              this.posY - this.motionY * f4,
              this.posZ - this.motionZ * f4,
              this.motionX,
              this.motionY,
              this.motionZ);
        }

        f3 = 0.8F;
      }

      if (this.isWet()) {
        this.extinguish();
      }

      this.motionX *= f3;
      this.motionY *= f3;
      this.motionZ *= f3;
      this.motionY -= gravity;
      this.setPosition(this.posX, this.posY, this.posZ);
      this.func_145775_I();
    }
  }
  /** Called to update the entity's position/logic. */
  public void onUpdate() {
    super.onUpdate();

    if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) {
      float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
      this.prevRotationYaw =
          this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
      this.prevRotationPitch =
          this.rotationPitch = (float) (Math.atan2(this.motionY, (double) f) * 180.0D / Math.PI);
    }

    Block i = this.worldObj.getBlock(this.xTile, this.yTile, this.zTile);

    if (!i.equals(Blocks.air)) {
      i.setBlockBoundsBasedOnState(this.worldObj, this.xTile, this.yTile, this.zTile);
      AxisAlignedBB axisalignedbb =
          i.getCollisionBoundingBoxFromPool(this.worldObj, this.xTile, this.yTile, this.zTile);

      if (axisalignedbb != null
          && axisalignedbb.isVecInside(Vec3.createVectorHelper(this.posX, this.posY, this.posZ))) {
        this.inGround = true;
      }
    }

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

    if (this.inGround) {
      Block j = this.worldObj.getBlock(this.xTile, this.yTile, this.zTile);
      int k = this.worldObj.getBlockMetadata(this.xTile, this.yTile, this.zTile);

      if (j == this.inTile && k == this.inData) {
        ++this.ticksInGround;

        if (this.ticksInGround == 1200) {
          this.setDead();
        }
      } else {
        this.inGround = false;
        this.motionX *= (double) (this.rand.nextFloat() * 0.2F);
        this.motionY *= (double) (this.rand.nextFloat() * 0.2F);
        this.motionZ *= (double) (this.rand.nextFloat() * 0.2F);
        this.ticksInGround = 0;
        this.ticksInAir = 0;
      }
    } else {
      ++this.ticksInAir;
      Vec3 vec31 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
      Vec3 vec3 =
          Vec3.createVectorHelper(
              this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
      MovingObjectPosition movingobjectposition =
          this.worldObj.func_147447_a(vec31, vec3, false, true, false);
      vec31 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
      vec3 =
          Vec3.createVectorHelper(
              this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);

      if (movingobjectposition != null) {
        vec31 =
            Vec3.createVectorHelper(
                movingobjectposition.hitVec.xCoord,
                movingobjectposition.hitVec.yCoord,
                movingobjectposition.hitVec.zCoord);
      }

      Entity entity = null;
      List list =
          this.worldObj.getEntitiesWithinAABBExcludingEntity(
              this,
              this.boundingBox
                  .addCoord(this.motionX, this.motionY, this.motionZ)
                  .expand(1.0D, 1.0D, 1.0D));
      double d0 = 0.0D;
      int l;
      float f1;

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

        if (entity1.canBeCollidedWith()
            && (entity1 != this.shootingEntity || this.ticksInAir >= 5)) {
          f1 = 0.3F;
          AxisAlignedBB axisalignedbb1 =
              entity1.boundingBox.expand((double) f1, (double) f1, (double) f1);
          MovingObjectPosition movingobjectposition1 =
              axisalignedbb1.calculateIntercept(vec3, vec31);

          if (movingobjectposition1 != null) {
            double d1 = vec3.distanceTo(movingobjectposition1.hitVec);

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

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

      if (movingobjectposition != null
          && movingobjectposition.entityHit != null
          && movingobjectposition.entityHit instanceof EntityPlayer) {
        EntityPlayer entityplayer = (EntityPlayer) movingobjectposition.entityHit;

        if (entityplayer.capabilities.disableDamage
            || this.shootingEntity instanceof EntityPlayer
                && !((EntityPlayer) this.shootingEntity).canAttackPlayer(entityplayer)) {
          movingobjectposition = null;
        }
      }

      float f2;
      float f3;

      if (movingobjectposition != null) {
        if (movingobjectposition.entityHit != null) {
          f2 =
              MathHelper.sqrt_double(
                  this.motionX * this.motionX
                      + this.motionY * this.motionY
                      + this.motionZ * this.motionZ);
          int i1 = MathHelper.ceiling_double_int((double) f2 * this.damage);

          if (this.getIsCritical()) {
            i1 += this.rand.nextInt(i1 / 2 + 2);
          }

          DamageSource damagesource = null;

          if (this.shootingEntity == null) {
            damagesource = mod_Rediscovered.causeParrowDamage(this, this);
          } else {
            damagesource = mod_Rediscovered.causeParrowDamage(this, this.shootingEntity);
          }

          if (this.isBurning() && !(movingobjectposition.entityHit instanceof EntityEnderman)) {
            movingobjectposition.entityHit.setFire(5);
          }

          if (movingobjectposition.entityHit.attackEntityFrom(damagesource, (float) i1)) {
            if (movingobjectposition.entityHit instanceof EntityLivingBase) {
              EntityLivingBase entitylivingbase = (EntityLivingBase) movingobjectposition.entityHit;

              if (!this.worldObj.isRemote) {
                entitylivingbase.setArrowCountInEntity(
                    entitylivingbase.getArrowCountInEntity() + 1);
              }

              if (this.knockbackStrength > 0) {
                f3 =
                    MathHelper.sqrt_double(
                        this.motionX * this.motionX + this.motionZ * this.motionZ);

                if (f3 > 0.0F) {
                  movingobjectposition.entityHit.addVelocity(
                      this.motionX
                          * (double) this.knockbackStrength
                          * 0.6000000238418579D
                          / (double) f3,
                      0.1D,
                      this.motionZ
                          * (double) this.knockbackStrength
                          * 0.6000000238418579D
                          / (double) f3);
                }
              }
            }

            this.playSound("random.bowhit", 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));

            if (!(movingobjectposition.entityHit instanceof EntityEnderman)) {
              this.setDead();
            }
          } else {
            this.motionX *= -0.10000000149011612D;
            this.motionY *= -0.10000000149011612D;
            this.motionZ *= -0.10000000149011612D;
            this.rotationYaw += 180.0F;
            this.prevRotationYaw += 180.0F;
            this.ticksInAir = 0;
          }
        } else {
          this.xTile = movingobjectposition.blockX;
          this.yTile = movingobjectposition.blockY;
          this.zTile = movingobjectposition.blockZ;
          this.inTile = this.worldObj.getBlock(this.xTile, this.yTile, this.zTile);
          this.inData = this.worldObj.getBlockMetadata(this.xTile, this.yTile, this.zTile);
          this.motionX = (double) ((float) (movingobjectposition.hitVec.xCoord - this.posX));
          this.motionY = (double) ((float) (movingobjectposition.hitVec.yCoord - this.posY));
          this.motionZ = (double) ((float) (movingobjectposition.hitVec.zCoord - this.posZ));
          f2 =
              MathHelper.sqrt_double(
                  this.motionX * this.motionX
                      + this.motionY * this.motionY
                      + this.motionZ * this.motionZ);
          this.posX -= this.motionX / (double) f2 * 0.05000000074505806D;
          this.posY -= this.motionY / (double) f2 * 0.05000000074505806D;
          this.posZ -= this.motionZ / (double) f2 * 0.05000000074505806D;
          this.playSound("random.bowhit", 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
          this.inGround = true;
          this.arrowShake = 7;
          this.setIsCritical(false);

          if (!this.inTile.equals(Blocks.air)) {
            this.inTile.onEntityCollidedWithBlock(
                this.worldObj, this.xTile, this.yTile, this.zTile, this);
          }
        }
      }

      if (this.getIsCritical()) {
        for (l = 0; l < 4; ++l) {
          this.worldObj.spawnParticle(
              "crit",
              this.posX + this.motionX * (double) l / 4.0D,
              this.posY + this.motionY * (double) l / 4.0D,
              this.posZ + this.motionZ * (double) l / 4.0D,
              -this.motionX,
              -this.motionY + 0.2D,
              -this.motionZ);
        }
      }

      this.posX += this.motionX;
      this.posY += this.motionY;
      this.posZ += this.motionZ;
      f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
      this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);

      for (this.rotationPitch = (float) (Math.atan2(this.motionY, (double) f2) * 180.0D / Math.PI);
          this.rotationPitch - this.prevRotationPitch < -180.0F;
          this.prevRotationPitch -= 360.0F) {;
      }

      while (this.rotationPitch - this.prevRotationPitch >= 180.0F) {
        this.prevRotationPitch += 360.0F;
      }

      while (this.rotationYaw - this.prevRotationYaw < -180.0F) {
        this.prevRotationYaw -= 360.0F;
      }

      while (this.rotationYaw - this.prevRotationYaw >= 180.0F) {
        this.prevRotationYaw += 360.0F;
      }

      this.rotationPitch =
          this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
      this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
      float f4 = 0.99F;
      f1 = 0.05F;

      if (this.isInWater()) {
        for (int j1 = 0; j1 < 4; ++j1) {
          f3 = 0.25F;
          this.worldObj.spawnParticle(
              "bubble",
              this.posX - this.motionX * (double) f3,
              this.posY - this.motionY * (double) f3,
              this.posZ - this.motionZ * (double) f3,
              this.motionX,
              this.motionY,
              this.motionZ);
        }

        f4 = 0.8F;
      }

      this.motionX *= (double) f4;
      this.motionY *= (double) f4;
      this.motionZ *= (double) f4;
      this.motionY -= (double) f1;
      this.setPosition(this.posX, this.posY, this.posZ);
      //            this.doBlockCollisions();
    }
  }
Ejemplo n.º 5
0
  @Override
  @SuppressWarnings("unchecked")
  public void onUpdate() {
    super.onUpdate();

    if (this.ticksExisted > 400) {
      if (this.isHot) {
        this.isHot = false;
        this.setHot(this.isHot);
      }
    } else if (!this.worldObj.isRemote) {
      this.setHot(this.isHot);
    }

    if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) {
      float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
      this.prevRotationYaw =
          this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
      this.prevRotationPitch =
          this.rotationPitch = (float) (Math.atan2(this.motionY, f) * 180.0D / Math.PI);
    }

    BlockPos pos = new BlockPos(this.xTile, this.yTile, this.zTile);
    Block block = this.worldObj.getBlockState(pos).getBlock();

    if (!block.isAir(this.worldObj, pos)) {
      block.setBlockBoundsBasedOnState(this.worldObj, pos);
      AxisAlignedBB axisalignedbb =
          block.getCollisionBoundingBox(this.worldObj, pos, this.worldObj.getBlockState(pos));

      if (axisalignedbb != null
          && axisalignedbb.isVecInside(new Vec3(this.posX, this.posY, this.posZ))) {
        this.inGround = true;
      }
    }

    if (this.inGround) {
      Block j = this.worldObj.getBlockState(pos).getBlock();
      int k = j.getMetaFromState(this.worldObj.getBlockState(pos));

      if (j == this.inTile && k == this.inData) {
        ++this.ticksInGround;

        if (this.ticksInGround == 1200) {
          this.setDead();
        }
      } else {
        this.inGround = false;
        this.motionX *= this.rand.nextFloat() * 0.2F;
        this.motionY *= this.rand.nextFloat() * 0.2F;
        this.motionZ *= this.rand.nextFloat() * 0.2F;
        this.ticksInGround = 0;
        this.ticksInAir = 0;
      }
    } else {
      ++this.ticksInAir;
      Vec3 vec3 = new Vec3(this.posX, this.posY, this.posZ);
      Vec3 vec31 =
          new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
      MovingObjectPosition movingobjectposition =
          this.worldObj.rayTraceBlocks(vec3, vec31, false, true, false);
      vec3 = new Vec3(this.posX, this.posY, this.posZ);
      vec31 =
          new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);

      if (movingobjectposition != null) {
        vec31 =
            new Vec3(
                movingobjectposition.hitVec.xCoord,
                movingobjectposition.hitVec.yCoord,
                movingobjectposition.hitVec.zCoord);
      }

      this.rotationPitch += 1F;

      Entity entity = null;
      List<Entity> list =
          this.worldObj.getEntitiesWithinAABBExcludingEntity(
              this,
              this.getEntityBoundingBox()
                  .addCoord(this.motionX, this.motionY, this.motionZ)
                  .expand(1.0D, 1.0D, 1.0D));
      double d0 = 0.0D;
      int l;
      float f1;

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

        if (entity1.canBeCollidedWith()
            && (entity1 != this.shootingEntity || this.ticksInAir >= 5)) {
          f1 = 0.3F;
          AxisAlignedBB axisalignedbb1 = entity1.getEntityBoundingBox().expand(f1, f1, f1);
          MovingObjectPosition movingobjectposition1 =
              axisalignedbb1.calculateIntercept(vec3, vec31);

          if (movingobjectposition1 != null) {
            double d1 = vec3.distanceTo(movingobjectposition1.hitVec);

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

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

      if (movingobjectposition != null
          && movingobjectposition.entityHit != null
          && movingobjectposition.entityHit instanceof EntityPlayer) {
        EntityPlayer entityplayer = (EntityPlayer) movingobjectposition.entityHit;

        if (entityplayer.capabilities.disableDamage
            || this.shootingEntity instanceof EntityPlayer
                && !((EntityPlayer) this.shootingEntity).canAttackPlayer(entityplayer)) {
          movingobjectposition = null;
        }
      }

      float f2;
      float f3;
      double damage = ConfigManagerCore.hardMode ? 3.2D : 1.6D;

      if (movingobjectposition != null) {
        if (movingobjectposition.entityHit != null) {
          f2 =
              MathHelper.sqrt_double(
                  this.motionX * this.motionX
                      + this.motionY * this.motionY
                      + this.motionZ * this.motionZ);
          int i1 = MathHelper.ceiling_double_int(f2 * damage);

          DamageSource damagesource = null;

          if (this.shootingEntity == null) {
            damagesource =
                new EntityDamageSourceIndirect("meteorChunk", this, this).setProjectile();
          } else {
            damagesource =
                new EntityDamageSourceIndirect("meteorChunk", this, this.shootingEntity)
                    .setProjectile();
          }

          if (this.isBurning() && !(movingobjectposition.entityHit instanceof EntityEnderman)) {
            movingobjectposition.entityHit.setFire(2);
          }

          if (movingobjectposition.entityHit.attackEntityFrom(damagesource, i1)) {
            if (movingobjectposition.entityHit instanceof EntityLivingBase) {
              EntityLivingBase entitylivingbase = (EntityLivingBase) movingobjectposition.entityHit;

              if (!this.worldObj.isRemote) {
                entitylivingbase.setArrowCountInEntity(
                    entitylivingbase.getArrowCountInEntity() + 1);
              }

              if (this.knockbackStrength > 0) {
                f3 =
                    MathHelper.sqrt_double(
                        this.motionX * this.motionX + this.motionZ * this.motionZ);

                if (f3 > 0.0F) {
                  movingobjectposition.entityHit.addVelocity(
                      this.motionX * this.knockbackStrength * 0.6000000238418579D / f3,
                      0.1D,
                      this.motionZ * this.knockbackStrength * 0.6000000238418579D / f3);
                }
              }

              if (this.shootingEntity != null) {
                EnchantmentHelper.applyThornEnchantments(entitylivingbase, this.shootingEntity);
                EnchantmentHelper.applyArthropodEnchantments(
                    (EntityLivingBase) this.shootingEntity, entitylivingbase);
              }

              if (this.shootingEntity != null
                  && movingobjectposition.entityHit != this.shootingEntity
                  && movingobjectposition.entityHit instanceof EntityPlayer
                  && this.shootingEntity instanceof EntityPlayerMP) {
                ((EntityPlayerMP) this.shootingEntity)
                    .playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(6, 0.0F));
              }
            }

            if (!(movingobjectposition.entityHit instanceof EntityEnderman)) {
              this.setDead();
            }
          } else {
            this.motionX *= -0.10000000149011612D;
            this.motionY *= -0.10000000149011612D;
            this.motionZ *= -0.10000000149011612D;
            this.rotationYaw += 180.0F;
            this.prevRotationYaw += 180.0F;
            this.ticksInAir = 0;
          }
        } else {
          this.xTile = movingobjectposition.getBlockPos().getX();
          this.yTile = movingobjectposition.getBlockPos().getY();
          this.zTile = movingobjectposition.getBlockPos().getZ();
          IBlockState state = this.worldObj.getBlockState(movingobjectposition.getBlockPos());
          this.inTile = state.getBlock();
          this.inData = this.inTile.getMetaFromState(state);
          this.motionX = (float) (movingobjectposition.hitVec.xCoord - this.posX);
          this.motionY = (float) (movingobjectposition.hitVec.yCoord - this.posY);
          this.motionZ = (float) (movingobjectposition.hitVec.zCoord - this.posZ);
          f2 =
              MathHelper.sqrt_double(
                  this.motionX * this.motionX
                      + this.motionY * this.motionY
                      + this.motionZ * this.motionZ);
          this.posX -= this.motionX / f2 * 0.05000000074505806D;
          this.posY -= this.motionY / f2 * 0.05000000074505806D;
          this.posZ -= this.motionZ / f2 * 0.05000000074505806D;
          this.inGround = true;

          if (!this.inTile.isAir(this.worldObj, movingobjectposition.getBlockPos())) {
            this.inTile.onEntityCollidedWithBlock(
                this.worldObj, movingobjectposition.getBlockPos(), this);
          }
        }
      }

      this.posX += this.motionX;
      this.posY += this.motionY;
      this.posZ += this.motionZ;
      f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);

      if (!this.onGround) {
        this.rotationPitch += 10;
        this.rotationYaw += 2;
      }

      float f4 = 0.99F;
      f1 = 0.05F;

      if (this.isInWater()) {
        for (int j1 = 0; j1 < 4; ++j1) {
          f3 = 0.25F;
          this.worldObj.spawnParticle(
              EnumParticleTypes.WATER_BUBBLE,
              this.posX - this.motionX * f3,
              this.posY - this.motionY * f3,
              this.posZ - this.motionZ * f3,
              this.motionX,
              this.motionY,
              this.motionZ);
        }

        f4 = 0.8F;
      }

      this.motionX *= f4;
      this.motionY *= f4;
      this.motionZ *= f4;
      this.motionY -= WorldUtil.getGravityForEntity(this);
      this.setPosition(this.posX, this.posY, this.posZ);
      this.doBlockCollisions();
    }
  }
  /*
   * Tick毎に呼ばれる更新処理。
   * 速度の更新、衝突判定などをここで行う。
   */
  @Override
  public void onUpdate() {
    super.onUpdate();

    livingTimeCount++;

    // その1、爆発処理
    byte exp = this.isExploded();
    if (exp == 1) {
      this.setDead();
    } else if (exp > 1) {
      AMTLogger.debugInfo("current explode int :" + exp);
      this.worldObj.spawnParticle(
          "hugeexplosion",
          this.posX,
          this.posY + 1.0D,
          this.posZ,
          this.motionX,
          this.motionY,
          this.motionZ);
      exp--;
      this.setTimeCount(exp);
    }

    // その2、アクティブか否か
    if (livingTimeCount > 3 && !this.active) {
      this.active = true;
      this.setActive((byte) 1);
      this.playSound("defeatedcrow:knock", 0.5F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
    }

    boolean explode = false;

    // 以降、アクティブか否かで動作が変わる。
    if (this.active) {
      double dx = -(double) (MathHelper.sin(this.rotationYaw / 180.0F * (float) Math.PI));
      double dz = -(double) (MathHelper.cos(this.rotationYaw / 180.0F * (float) Math.PI));
      for (int i = 0; i < 4; ++i) {
        this.worldObj.spawnParticle(
            "crit",
            this.posX + dx,
            this.posY,
            this.posZ + dz,
            -this.motionX,
            -this.motionY + 0.2D,
            -this.motionZ);
      }
    }

    // 直前のパラメータと新パラメータを一致させているところ。
    // また、速度に応じてエンティティの向きを調整し、常に進行方向に前面が向くようにしている。
    if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) {
      float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
      this.prevRotationYaw =
          this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
      this.prevRotationPitch =
          this.rotationPitch = (float) (Math.atan2(this.motionY, f) * 180.0D / Math.PI);
    }

    // 激突したブロックを確認している
    Block i = this.worldObj.getBlock(this.xTile, this.yTile, this.zTile);
    boolean air = this.worldObj.isAirBlock(xTile, yTile, zTile);

    // 空気じゃないブロックに当たった&ブロック貫通エンティティでない時
    if (i != null && i.getMaterial() != Material.air) {
      i.setBlockBoundsBasedOnState(this.worldObj, this.xTile, this.yTile, this.zTile);
      AxisAlignedBB axisalignedbb =
          i.getCollisionBoundingBoxFromPool(this.worldObj, this.xTile, this.yTile, this.zTile);

      // 当たり判定に接触しているかどうか
      if (axisalignedbb != null
          && axisalignedbb.isVecInside(Vec3.createVectorHelper(this.posX, this.posY, this.posZ))) {
        this.inGround = true;
      }
    }

    // 空気じゃないブロックに当たった
    if (this.inGround) {
      Block j = this.worldObj.getBlock(this.xTile, this.yTile, this.zTile);
      int k = this.worldObj.getBlockMetadata(this.xTile, this.yTile, this.zTile);

      /*
       * 前のTickに確認した埋まりブロックのIDとメタを照合している。違ったら埋まり状態を解除、一致したら埋まり状態を継続。
       * /* 埋まり状態2tick継続でこのエンティティを消す
       */
      if (j == this.inTile && k == this.inData) {
        ++this.ticksInGround;
        // ブロック貫通の場合、20tick(1秒間)はブロック中にあっても消えないようになる。
        int limit = 2;

        if (this.ticksInGround > limit) {
          explode = true;
        }
      } else // 埋まり状態の解除処理
      {
        this.inGround = false;
        this.motionX *= this.rand.nextFloat() * 0.1F;
        this.motionY *= this.rand.nextFloat() * 0.1F;
        this.motionZ *= this.rand.nextFloat() * 0.1F;
        this.ticksInGround = 0;
        this.ticksInAir = 0;
      }
    } else // 埋まってない時。速度の更新。
    {
      ++this.ticksInAir;
      // ブロックとの衝突判定
      Vec3 vec3 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
      Vec3 vec31 =
          Vec3.createVectorHelper(
              this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
      MovingObjectPosition movingobjectposition =
          this.worldObj.func_147447_a(vec3, vec31, false, true, false);
      vec3 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
      vec31 =
          Vec3.createVectorHelper(
              this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);

      // ブロックに当たった
      if (movingobjectposition != null) {
        vec31 =
            Vec3.createVectorHelper(
                movingobjectposition.hitVec.xCoord,
                movingobjectposition.hitVec.yCoord,
                movingobjectposition.hitVec.zCoord);
      }

      // Entityとの衝突判定。
      List list =
          this.worldObj.getEntitiesWithinAABBExcludingEntity(
              this,
              this.boundingBox
                  .addCoord(this.motionX, this.motionY, this.motionZ)
                  .expand(1.0D, 1.0D, 1.0D));
      double d0 = 0.0D;
      int l;
      float f1;

      MovingObjectPosition entityTarget = null;

      // 1ブロック分の範囲内にいるエンティティ全てに対して繰り返す
      for (l = 0; l < list.size(); ++l) {
        Entity entity1 = (Entity) list.get(l);
        Entity entity = null;

        // ターゲットの場合
        if (entity1 instanceof EntityLivingBase || entity1 instanceof EntityDragonPart) {
          f1 = 0.3F;
          AxisAlignedBB axisalignedbb1 = entity1.boundingBox.expand(f1, f1, f1);
          MovingObjectPosition movingobjectposition1 =
              axisalignedbb1.calculateIntercept(vec3, vec31);

          if (movingobjectposition1 != null) {
            double d1 = vec3.distanceTo(movingobjectposition1.hitVec);

            if (d1 < d0 || d0 == 0.0D) {
              // arrowと異なり、あたったEntityすべてをリストに入れる
              entityTarget = new MovingObjectPosition(entity1);
              d0 = d1;
              break;
            }
          }
        }
      }

      /*
       * 当たったエンティティそれそれについての判定部分。
       * ここで特定の種類のエンティティに当たらないようにできる。
       */
      boolean canAttack = false;
      if (entityTarget != null) {
        Entity target = entityTarget.entityHit;

        if (target instanceof EntityPlayer) {
          // プレイヤーに当たった時
          EntityPlayer entityplayer = (EntityPlayer) target;

          if (entityplayer.capabilities.disableDamage
              || this.shootingEntity instanceof EntityPlayer
                  && !((EntityPlayer) this.shootingEntity).canAttackPlayer(entityplayer)) {
            // PvPが許可されていないと当たらない
            canAttack = false;
          } else if (entityplayer == this.shootingEntity) {
            // 対象が撃った本人の場合も当たらない
            canAttack = false;
          } else if (DCsConfig.PvPProhibitionMode && entityplayer instanceof EntityPlayer) {
            canAttack = false;
          }
        } else if (target instanceof EntityTameable || target instanceof EntityHorse) {
          // 事故防止の為、EntityTameable(犬や猫などのペット)、馬にも当たらないようにする
          canAttack = false;
        } else {
          canAttack = true;
        }
      }

      float f2;
      float f3;

      // 当たったあとの処理
      // まずはリストから
      if (canAttack) {
        Entity target = entityTarget.entityHit;

        int i1 = MathHelper.ceiling_double_int(1.0D * this.damage);
        // 0~2程度の乱数値を上乗せ
        i1 += this.rand.nextInt(3);

        DamageSource damagesource = null;

        // 別メソッドでダメージソースを確認
        damagesource = this.thisDamageSource(this.shootingEntity);

        // バニラ矢と同様、このエンティティが燃えているなら対象に着火することも出来る
        if (this.isBurning() && !(target instanceof EntityEnderman)) {
          target.setFire(5);
        } else if (target instanceof IProjectile) {
          // 対象が矢などの飛翔Entityの場合、打ち消すことが出来る
          target.setDead();
        } else {
          // ダメージを与える処理を呼ぶ
          if (target.attackEntityFrom(damagesource, i1)) {
            // ダメージを与えることに成功したら以下の処理を行う
            if (target instanceof EntityLivingBase) {
              EntityLivingBase entitylivingbase = (EntityLivingBase) target;

              // ノックバック
              if (this.knockbackStrength > 0) {
                f3 =
                    MathHelper.sqrt_double(
                        this.motionX * this.motionX + this.motionZ * this.motionZ);

                if (f3 > 0.0F) {
                  // Y方向に大きめに打ち上げる
                  target.addVelocity(
                      this.motionX * this.knockbackStrength * 0.2000000238418579D / f3,
                      0.3D,
                      this.motionZ * this.knockbackStrength * 0.2000000238418579D / f3);
                }
              }

              // 無敵時間はなし
              target.hurtResistantTime = 0;

              // マルチプレイ時に、両者がプレイヤーだった時のパケット送信処理
              if (this.shootingEntity != null
                  && target != this.shootingEntity
                  && target instanceof EntityPlayer
                  && this.shootingEntity instanceof EntityPlayerMP) {
                ((EntityPlayerMP) this.shootingEntity)
                    .playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(6, 0.0F));
              }
            }

            // ここでヒット時の効果音がなる
            this.playSound("random.bowhit", 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));

            // 当たったあと、弾を消去する。エンティティ貫通がONの弾種はそのまま残す。
            explode = true;
          }
        }
      }

      if (movingobjectposition != null) // blockのみ
      {
        this.xTile = movingobjectposition.blockX;
        this.yTile = movingobjectposition.blockY;
        this.zTile = movingobjectposition.blockZ;
        this.inTile = this.worldObj.getBlock(this.xTile, this.yTile, this.zTile);
        this.inData = this.worldObj.getBlockMetadata(this.xTile, this.yTile, this.zTile);
        this.motionX = ((float) (movingobjectposition.hitVec.xCoord - this.posX));
        this.motionY = ((float) (movingobjectposition.hitVec.yCoord - this.posY));
        this.motionZ = ((float) (movingobjectposition.hitVec.zCoord - this.posZ));
        f2 =
            MathHelper.sqrt_double(
                this.motionX * this.motionX
                    + this.motionY * this.motionY
                    + this.motionZ * this.motionZ);
        this.posX -= this.motionX / f2 * 0.05000000074505806D;
        this.posY -= this.motionY / f2 * 0.05000000074505806D;
        this.posZ -= this.motionZ / f2 * 0.05000000074505806D;
        this.playSound("random.bowhit", 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
        this.inGround = true;

        if (this.inTile != null) {
          // Block側に衝突を伝える
          this.inTile.onEntityCollidedWithBlock(
              this.worldObj, this.xTile, this.yTile, this.zTile, this);
        }
      }
    }

    // さいごに爆発処理
    int live = (targetEntity != null && targetEntity.isEntityAlive()) ? 10 : 600;

    if (explode || this.livingTimeCount > live) {
      if (this.isExploded() == 0) {
        AMTLogger.debugInfo("explosion");
        this.setExplosion();
        if (!DCsConfig.disableMissileExplosion && !worldObj.isRemote) {
          float f = 5.0F;
          CustomExplosion explosion =
              new CustomExplosion(
                  worldObj,
                  this,
                  shootingEntity,
                  this.posX,
                  this.posY,
                  this.posZ,
                  f,
                  CustomExplosion.Type.Anchor,
                  true);
          explosion.doExplosion();
        }
      }
    }

    // 追尾
    if (active) {
      if (targetEntity != null && targetEntity.isEntityAlive()) {
        double dx = targetEntity.posX - this.posX;
        double dy = targetEntity.boundingBox.minY + (targetEntity.height / 2.0D) - this.posY;
        double dz = targetEntity.posZ - this.posZ;
        double d3 = MathHelper.sqrt_double(dx * dx + dz * dz);

        if (d3 >= 1.0E-7D) {
          float f4 = (float) d3 * 0.2F;
          double dy2 = dy + f4;

          float ff = MathHelper.sqrt_double(dx * dx + dy2 * dy2 + dz * dz);
          dx /= ff;
          dy /= ff;
          dz /= ff;

          this.motionX = (this.motionX + dx) / 2;
          this.motionY = (this.motionY + dy) / 2;
          this.motionZ = (this.motionZ + dz) / 2;

          this.motionX *= 1.25D;
          this.motionY *= 1.25D;
          this.motionZ *= 1.25D;
        }
      }
    }

    // 直前のパラメータと新パラメータを一致させているところ。
    // また、速度に応じてエンティティの向きを調整し、常に進行方向に前面が向くようにしている。
    if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) {
      float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
      this.prevRotationYaw =
          this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
      this.prevRotationPitch =
          this.rotationPitch = (float) (Math.atan2(this.motionY, f) * 180.0D / Math.PI);
    }

    // 改めてポジションに速度を加算。向きも更新。
    this.posX += this.motionX;
    this.posY += this.motionY;
    this.posZ += this.motionZ;
    float f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
    this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
    this.rotationPitch = (float) (Math.atan2(this.motionY, f2) * 180.0D / Math.PI);

    while (this.rotationPitch - this.prevRotationPitch < -180.0F) {
      this.prevRotationPitch -= 360.0F;
    }

    while (this.rotationPitch - this.prevRotationPitch >= 180.0F) {
      this.prevRotationPitch += 360.0F;
    }

    while (this.rotationYaw - this.prevRotationYaw < -180.0F) {
      this.prevRotationYaw -= 360.0F;
    }

    while (this.rotationYaw - this.prevRotationYaw >= 180.0F) {
      this.prevRotationYaw += 360.0F;
    }

    this.rotationPitch =
        this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
    this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;

    // 水中に有る
    if (this.isInWater()) {
      // 泡パーティクルが出る
      for (int j1 = 0; j1 < 4; ++j1) {
        float f3 = 0.25F;
        this.worldObj.spawnParticle(
            "bubble",
            this.posX - this.motionX * f3,
            this.posY - this.motionY * f3,
            this.posZ - this.motionZ * f3,
            this.motionX,
            this.motionY,
            this.motionZ);
      }
    }

    this.setPosition(this.posX, this.posY, this.posZ);
    this.func_145775_I();
  }
Ejemplo n.º 7
0
  @Override
  public void onUpdate() {
    super.onEntityUpdate();

    if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F) {
      float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
      prevRotationYaw = rotationYaw = (float) (Math.atan2(motionX, motionZ) * 180.0D / Math.PI);
      prevRotationPitch = rotationPitch = (float) (Math.atan2(motionY, f) * 180.0D / Math.PI);
    }

    // TODO: worldObj.getBlock()
    Block block = worldObj.getBlock(xTile, yTile, zTile);

    // TODO: block.getMaterial()  Material.air
    if (block.getMaterial() != Material.air) {
      // TODO: setBlockBoundsBasedOnState
      block.setBlockBoundsBasedOnState(worldObj, xTile, yTile, zTile);
      // TODO:						        getCollisionBoundingBoxFromPool()
      AxisAlignedBB axisalignedbb =
          block.getCollisionBoundingBoxFromPool(worldObj, xTile, yTile, zTile);

      if (axisalignedbb != null
          && axisalignedbb.isVecInside(
              worldObj.getWorldVec3Pool().getVecFromPool(posX, posY, posZ))) {
        this.setDead();
      }
    }

    ++ticksInAir;
    Vec3 vec3 = worldObj.getWorldVec3Pool().getVecFromPool(posX, posY, posZ);
    Vec3 vec31 =
        worldObj.getWorldVec3Pool().getVecFromPool(posX + motionX, posY + motionY, posZ + motionZ);
    // TODO: 											 rayTraceBlocks_do_do()?
    MovingObjectPosition movingobjectposition =
        worldObj.func_147447_a(vec3, vec31, false, true, false);
    vec3 = worldObj.getWorldVec3Pool().getVecFromPool(posX, posY, posZ);
    vec31 =
        worldObj.getWorldVec3Pool().getVecFromPool(posX + motionX, posY + motionY, posZ + motionZ);

    if (movingobjectposition != null) {
      vec31 =
          worldObj
              .getWorldVec3Pool()
              .getVecFromPool(
                  movingobjectposition.hitVec.xCoord,
                  movingobjectposition.hitVec.yCoord,
                  movingobjectposition.hitVec.zCoord);
    }

    Entity entity = null;
    List list =
        worldObj.getEntitiesWithinAABBExcludingEntity(
            this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D));
    double d0 = 0.0D;
    int l;
    float f1;

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

      if (entity1.canBeCollidedWith() && (entity1 != shootingEntity || ticksInAir >= 5)) {
        f1 = 0.3F;
        AxisAlignedBB axisalignedbb1 = entity1.boundingBox.expand(f1, f1, f1);
        MovingObjectPosition movingobjectposition1 = axisalignedbb1.calculateIntercept(vec3, vec31);

        if (movingobjectposition1 != null) {
          double d1 = vec3.distanceTo(movingobjectposition1.hitVec);

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

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

    if (movingobjectposition != null
        && movingobjectposition.entityHit != null
        && movingobjectposition.entityHit instanceof EntityPlayer) {
      EntityPlayer entityplayer = (EntityPlayer) movingobjectposition.entityHit;

      if (entityplayer.capabilities.disableDamage
          || shootingEntity instanceof EntityPlayer
              && !((EntityPlayer) shootingEntity).canAttackPlayer(entityplayer)) {
        movingobjectposition = null;
      }
    }

    float f2;
    float f3;

    if (movingobjectposition != null) {
      if (movingobjectposition.entityHit != null) {
        f2 = MathHelper.sqrt_double(motionX * motionX + motionY * motionY + motionZ * motionZ);

        DamageSource damagesource = null;

        if (shootingEntity == null) {
          damagesource = DamageSource.causeArrowDamage(this, this);
        } else {
          damagesource = DamageSource.causeArrowDamage(this, shootingEntity);
        }

        if (type == DartType.POISON) {
          damage = 1;

          if (movingobjectposition.entityHit instanceof EntityLivingBase) {
            ((EntityLivingBase) movingobjectposition.entityHit)
                .addPotionEffect(new PotionEffect(BOPPotionHelper.get("paralysis").id, 100));
          }
        }

        if (movingobjectposition.entityHit.attackEntityFrom(damagesource, damage)) {
          if (movingobjectposition.entityHit instanceof EntityLivingBase) {
            if (shootingEntity != null
                && movingobjectposition.entityHit != shootingEntity
                && movingobjectposition.entityHit instanceof EntityPlayer
                && shootingEntity instanceof EntityPlayerMP) {
              // TODO:													sendPacketToPlayer()
              ((EntityPlayerMP) shootingEntity)
                  .playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(6, 0.0F));
            }
          }

          this.playSound("random.bowhit", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F));
          this.setDead();
        } else {
          motionX *= -0.10000000149011612D;
          motionY *= -0.10000000149011612D;
          motionZ *= -0.10000000149011612D;
          rotationYaw += 180.0F;
          prevRotationYaw += 180.0F;
          ticksInAir = 0;
        }
      } else {
        xTile = movingobjectposition.blockX;
        yTile = movingobjectposition.blockY;
        zTile = movingobjectposition.blockZ;
        motionX = ((float) (movingobjectposition.hitVec.xCoord - posX));
        motionY = ((float) (movingobjectposition.hitVec.yCoord - posY));
        motionZ = ((float) (movingobjectposition.hitVec.zCoord - posZ));
        f2 = MathHelper.sqrt_double(motionX * motionX + motionY * motionY + motionZ * motionZ);
        posX -= motionX / f2 * 0.05000000074505806D;
        posY -= motionY / f2 * 0.05000000074505806D;
        posZ -= motionZ / f2 * 0.05000000074505806D;

        for (int p = 0; p < 16; ++p) {
          if (isPoisonous()) {
            BiomesOPlenty.proxy.spawnParticle("poisondart", posX, posY, posZ);
          } else {
            BiomesOPlenty.proxy.spawnParticle("dart", posX, posY, posZ);
          }
        }

        this.playSound("random.bowhit", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F));
        this.setDead();
      }
    }

    posX += motionX;
    posY += motionY;
    posZ += motionZ;
    f2 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
    rotationYaw = (float) (Math.atan2(motionX, motionZ) * 180.0D / Math.PI);

    for (rotationPitch = (float) (Math.atan2(motionY, f2) * 180.0D / Math.PI);
        rotationPitch - prevRotationPitch < -180.0F;
        prevRotationPitch -= 360.0F) {;
    }

    while (rotationPitch - prevRotationPitch >= 180.0F) {
      prevRotationPitch += 360.0F;
    }

    while (rotationYaw - prevRotationYaw < -180.0F) {
      prevRotationYaw -= 360.0F;
    }

    while (rotationYaw - prevRotationYaw >= 180.0F) {
      prevRotationYaw += 360.0F;
    }

    rotationPitch = prevRotationPitch + (rotationPitch - prevRotationPitch) * 0.2F;
    rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.2F;
    float f4 = 0.99F;
    f1 = 0.05F;

    if (this.isInWater()) {
      for (int j1 = 0; j1 < 4; ++j1) {
        f3 = 0.25F;
        worldObj.spawnParticle(
            "bubble",
            posX - motionX * f3,
            posY - motionY * f3,
            posZ - motionZ * f3,
            motionX,
            motionY,
            motionZ);
      }

      f4 = 0.8F;
    }

    motionX *= f4;
    motionY *= f4;
    motionZ *= f4;
    motionY -= f1;
    this.setPosition(posX, posY, posZ);
    // TODO: doBlockCollisions()
    this.func_145775_I();
  }