示例#1
0
  /** Called to update the entity's position/logic. */
  public void onUpdate() {
    this.lastTickPosX = this.posX;
    this.lastTickPosY = this.posY;
    this.lastTickPosZ = this.posZ;
    super.onUpdate();
    this.motionX *= 1.15D;
    this.motionZ *= 1.15D;
    this.motionY += 0.04D;
    this.moveEntity(this.motionX, this.motionY, this.motionZ);
    float var1 = 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) var1) * 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;

    if (this.fireworkAge == 0) {
      this.worldObj.playSoundAtEntity(this, "fireworks.launch", 3.0F, 1.0F);
    }

    ++this.fireworkAge;

    if (this.worldObj.isRemote && this.fireworkAge % 2 < 2) {
      this.worldObj.spawnParticle(
          "fireworksSpark",
          this.posX,
          this.posY - 0.3D,
          this.posZ,
          this.rand.nextGaussian() * 0.05D,
          -this.motionY * 0.5D,
          this.rand.nextGaussian() * 0.05D);
    }

    if (!this.worldObj.isRemote && this.fireworkAge > this.lifetime) {
      this.worldObj.setEntityState(this, (byte) 17);
      this.setDead();
    }
  }
  @Override
  public void onUpdate() {
    boolean sorted = true;
    int lastDepth = Integer.MAX_VALUE;
    for (Entity entity : entities) {
      entity.onUpdate();

      if (lastDepth < entity.getDepth()) {
        sorted = false;
      }
      lastDepth = entity.getDepth();
    }

    if (!sorted) {
      Collections.sort(entities);
    }
  }
  /** Called to update the entity's position/logic. */
  public void onUpdate() {
    lastTickPosX = posX;
    lastTickPosY = posY;
    lastTickPosZ = posZ;
    super.onUpdate();

    if (throwableShake > 0) {
      throwableShake--;
    }

    if (inGround) {
      int i = worldObj.getBlockId(xTile, yTile, zTile);

      if (i != inTile) {
        inGround = false;
        motionX *= rand.nextFloat() * 0.2F;
        motionY *= rand.nextFloat() * 0.2F;
        motionZ *= rand.nextFloat() * 0.2F;
        ticksInGround = 0;
        ticksInAir = 0;
      } else {
        ticksInGround++;

        if (ticksInGround == 1200) {
          setDead();
        }

        return;
      }
    } else {
      ticksInAir++;
    }

    Vec3D vec3d = Vec3D.createVector(posX, posY, posZ);
    Vec3D vec3d1 = Vec3D.createVector(posX + motionX, posY + motionY, posZ + motionZ);
    MovingObjectPosition movingobjectposition = worldObj.rayTraceBlocks(vec3d, vec3d1);
    vec3d = Vec3D.createVector(posX, posY, posZ);
    vec3d1 = Vec3D.createVector(posX + motionX, posY + motionY, posZ + motionZ);

    if (movingobjectposition != null) {
      vec3d1 =
          Vec3D.createVector(
              movingobjectposition.hitVec.xCoord,
              movingobjectposition.hitVec.yCoord,
              movingobjectposition.hitVec.zCoord);
    }

    if (!worldObj.isRemote) {
      Entity entity = null;
      List list =
          worldObj.getEntitiesWithinAABBExcludingEntity(
              this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D));
      double d = 0.0D;

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

        if (!entity1.canBeCollidedWith() || entity1 == thrower && ticksInAir < 5) {
          continue;
        }

        float f4 = 0.3F;
        AxisAlignedBB axisalignedbb = entity1.boundingBox.expand(f4, f4, f4);
        MovingObjectPosition movingobjectposition1 =
            axisalignedbb.calculateIntercept(vec3d, vec3d1);

        if (movingobjectposition1 == null) {
          continue;
        }

        double d1 = vec3d.distanceTo(movingobjectposition1.hitVec);

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

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

    if (movingobjectposition != null) {
      onImpact(movingobjectposition);
    }

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

    for (rotationPitch = (float) ((Math.atan2(motionY, f) * 180D) / Math.PI);
        rotationPitch - prevRotationPitch < -180F;
        prevRotationPitch -= 360F) {}

    for (; rotationPitch - prevRotationPitch >= 180F; prevRotationPitch += 360F) {}

    for (; rotationYaw - prevRotationYaw < -180F; prevRotationYaw -= 360F) {}

    for (; rotationYaw - prevRotationYaw >= 180F; prevRotationYaw += 360F) {}

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

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

      f1 = 0.8F;
    }

    motionX *= f1;
    motionY *= f1;
    motionZ *= f1;
    motionY -= f2;
    setPosition(posX, posY, posZ);
  }
示例#4
0
  /** Called to update the entity's position/logic. */
  public void onUpdate() {
    super.onUpdate();

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

    this.prevPosX = this.posX;
    this.prevPosY = this.posY;
    this.prevPosZ = this.posZ;
    this.motionY -= 0.029999999329447746D;

    if (this.worldObj.getBlockMaterial(
            MathHelper.floor_double(this.posX),
            MathHelper.floor_double(this.posY),
            MathHelper.floor_double(this.posZ))
        == Material.lava) {
      this.motionY = 0.20000000298023224D;
      this.motionX = (double) ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F);
      this.motionZ = (double) ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F);
      this.worldObj.playSoundAtEntity(
          this, "random.fizz", 0.4F, 2.0F + this.rand.nextFloat() * 0.4F);
    }

    this.pushOutOfBlocks(
        this.posX, (this.boundingBox.minY + this.boundingBox.maxY) / 2.0D, this.posZ);
    double var1 = 8.0D;

    if (this.field_80002_g < this.xpColor - 20 + this.entityId % 100) {
      if ((this.closestPlayer == null
              || this.closestPlayer.getDistanceSqToEntity(this) > var1 * var1)
          && !this.m_bNotPlayerOwned) {
        this.closestPlayer = this.worldObj.getClosestPlayerToEntity(this, var1);
      }

      this.field_80002_g = this.xpColor;
    }

    if (this.closestPlayer != null) {
      double var3 = (this.closestPlayer.posX - this.posX) / var1;
      double var5 =
          (this.closestPlayer.posY + (double) this.closestPlayer.getEyeHeight() - this.posY) / var1;
      double var7 = (this.closestPlayer.posZ - this.posZ) / var1;
      double var9 = var3 * var3 + var5 * var5 + var7 * var7;

      if (var9 < 1.0D) {
        double var11 = Math.sqrt(var9);
        double var13 = 1.0D - var11;
        var13 *= var13;
        this.motionX += var3 / var11 * var13 * 0.1D;
        this.motionY += var5 / var11 * var13 * 0.1D;
        this.motionZ += var7 / var11 * var13 * 0.1D;
      }
    }

    this.moveEntity(this.motionX, this.motionY, this.motionZ);
    float var15 = 0.98F;

    if (this.onGround) {
      var15 = 0.5880001F;
      int var4 =
          this.worldObj.getBlockId(
              MathHelper.floor_double(this.posX),
              MathHelper.floor_double(this.boundingBox.minY) - 1,
              MathHelper.floor_double(this.posZ));

      if (var4 > 0) {
        var15 = Block.blocksList[var4].slipperiness * 0.98F;
      }
    }

    this.motionX *= (double) var15;
    this.motionY *= 0.9800000190734863D;
    this.motionZ *= (double) var15;

    if (this.onGround) {
      this.motionY *= -0.8999999761581421D;
    }

    ++this.xpColor;
    ++this.xpOrbAge;

    if (this.xpOrbAge >= 6000) {
      this.setDead();
    }
  }