示例#1
0
 /**
  * Returns a boundingBox used to collide the entity with other entities and blocks. This enables
  * the entity to be pushable on contact, like boats or minecarts.
  */
 public AxisAlignedBB getCollisionBox(Entity entityIn) {
   return entityIn.canBePushed() ? entityIn.getEntityBoundingBox() : null;
 }
示例#2
0
  /** Called to update the entity's position/logic. */
  public void onUpdate() {
    if (this.getRollingAmplitude() > 0) {
      this.setRollingAmplitude(this.getRollingAmplitude() - 1);
    }

    if (this.getDamage() > 0.0F) {
      this.setDamage(this.getDamage() - 1.0F);
    }

    if (this.posY < -64.0D) {
      this.kill();
    }

    if (!this.worldObj.isRemote && this.worldObj instanceof WorldServer) {
      this.worldObj.theProfiler.startSection("portal");
      MinecraftServer minecraftserver = ((WorldServer) this.worldObj).getMinecraftServer();
      int i = this.getMaxInPortalTime();

      if (this.inPortal) {
        if (minecraftserver.getAllowNether()) {
          if (this.ridingEntity == null && this.portalCounter++ >= i) {
            this.portalCounter = i;
            this.timeUntilPortal = this.getPortalCooldown();
            int j;

            if (this.worldObj.provider.getDimensionId() == -1) {
              j = 0;
            } else {
              j = -1;
            }

            this.travelToDimension(j);
          }

          this.inPortal = false;
        }
      } else {
        if (this.portalCounter > 0) {
          this.portalCounter -= 4;
        }

        if (this.portalCounter < 0) {
          this.portalCounter = 0;
        }
      }

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

      this.worldObj.theProfiler.endSection();
    }

    if (this.worldObj.isRemote) {
      if (this.turnProgress > 0) {
        double d4 = this.posX + (this.minecartX - this.posX) / (double) this.turnProgress;
        double d5 = this.posY + (this.minecartY - this.posY) / (double) this.turnProgress;
        double d6 = this.posZ + (this.minecartZ - this.posZ) / (double) this.turnProgress;
        double d1 = MathHelper.wrapAngleTo180_double(this.minecartYaw - (double) this.rotationYaw);
        this.rotationYaw = (float) ((double) this.rotationYaw + d1 / (double) this.turnProgress);
        this.rotationPitch =
            (float)
                ((double) this.rotationPitch
                    + (this.minecartPitch - (double) this.rotationPitch)
                        / (double) this.turnProgress);
        --this.turnProgress;
        this.setPosition(d4, d5, d6);
        this.setRotation(this.rotationYaw, this.rotationPitch);
      } else {
        this.setPosition(this.posX, this.posY, this.posZ);
        this.setRotation(this.rotationYaw, this.rotationPitch);
      }
    } else {
      this.prevPosX = this.posX;
      this.prevPosY = this.posY;
      this.prevPosZ = this.posZ;
      this.motionY -= 0.03999999910593033D;
      int k = MathHelper.floor_double(this.posX);
      int l = MathHelper.floor_double(this.posY);
      int i1 = MathHelper.floor_double(this.posZ);

      if (BlockRailBase.isRailBlock(this.worldObj, new BlockPos(k, l - 1, i1))) {
        --l;
      }

      BlockPos blockpos = new BlockPos(k, l, i1);
      IBlockState iblockstate = this.worldObj.getBlockState(blockpos);

      if (BlockRailBase.isRailBlock(iblockstate)) {
        this.func_180460_a(blockpos, iblockstate);

        if (iblockstate.getBlock() == Blocks.activator_rail) {
          this.onActivatorRailPass(
              k, l, i1, ((Boolean) iblockstate.getValue(BlockRailPowered.POWERED)).booleanValue());
        }
      } else {
        this.moveDerailedMinecart();
      }

      this.doBlockCollisions();
      this.rotationPitch = 0.0F;
      double d0 = this.prevPosX - this.posX;
      double d2 = this.prevPosZ - this.posZ;

      if (d0 * d0 + d2 * d2 > 0.001D) {
        this.rotationYaw = (float) (MathHelper.func_181159_b(d2, d0) * 180.0D / Math.PI);

        if (this.isInReverse) {
          this.rotationYaw += 180.0F;
        }
      }

      double d3 = (double) MathHelper.wrapAngleTo180_float(this.rotationYaw - this.prevRotationYaw);

      if (d3 < -170.0D || d3 >= 170.0D) {
        this.rotationYaw += 180.0F;
        this.isInReverse = !this.isInReverse;
      }

      this.setRotation(this.rotationYaw, this.rotationPitch);

      for (Entity entity :
          this.worldObj.getEntitiesWithinAABBExcludingEntity(
              this,
              this.getEntityBoundingBox()
                  .expand(0.20000000298023224D, 0.0D, 0.20000000298023224D))) {
        if (entity != this.riddenByEntity
            && entity.canBePushed()
            && entity instanceof EntityMinecart) {
          entity.applyEntityCollision(this);
        }
      }

      if (this.riddenByEntity != null && this.riddenByEntity.isDead) {
        if (this.riddenByEntity.ridingEntity == this) {
          this.riddenByEntity.ridingEntity = null;
        }

        this.riddenByEntity = null;
      }

      this.handleWaterMovement();
    }
  }
  public void onUpdate() {
    super.onUpdate();
    HandleHatching();
    super.onUpdate();

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

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

    prevPosX = posX;
    prevPosY = posY;
    prevPosZ = posZ;
    int i = 5;
    double d = 0.0D;

    for (int j = 0; j < i; j++) {
      double d5 =
          (boundingBox.minY
                  + ((boundingBox.maxY - boundingBox.minY) * (double) (j + 0)) / (double) i)
              - 0.125D;
      double d9 =
          (boundingBox.minY
                  + ((boundingBox.maxY - boundingBox.minY) * (double) (j + 1)) / (double) i)
              - 0.125D;
      AxisAlignedBB axisalignedbb =
          AxisAlignedBB.getAABBPool()
              .addOrModifyAABBInPool(
                  boundingBox.minX, d5, boundingBox.minZ, boundingBox.maxX, d9, boundingBox.maxZ);
    }

    if (d < 1.0D) {
      double d3 = d * 2D - 1.0D;
      motionY += 0.039999999105930328D * d3;
    } else {
      if (motionY < 0.0D) {
        motionY /= 2D;
      }

      motionY += 0.0070000002160668373D;
    }

    if (riddenByEntity != null) {
      motionX += riddenByEntity.motionX * 0.20000000000000001D;
      motionZ += riddenByEntity.motionZ * 0.20000000000000001D;
    }

    double d4 = 0.40000000000000002D;

    if (motionX < -d4) {
      motionX = -d4;
    }

    if (motionX > d4) {
      motionX = d4;
    }

    if (motionZ < -d4) {
      motionZ = -d4;
    }

    if (motionZ > d4) {
      motionZ = d4;
    }

    if (onGround) {
      motionX *= 0.5D;
      motionY *= 0.5D;
      motionZ *= 0.5D;
    }

    moveEntity(motionX, motionY, motionZ);
    double d8 = Math.sqrt(motionX * motionX + motionZ * motionZ);

    if (d8 > 0.14999999999999999D) {
      double d12 = Math.cos(((double) rotationYaw * Math.PI) / 180D);
      double d15 = Math.sin(((double) rotationYaw * Math.PI) / 180D);

      for (int i1 = 0; (double) i1 < 1.0D + d8 * 60D; i1++) {
        double d18 = rand.nextFloat() * 2.0F - 1.0F;
        double d20 = (double) (rand.nextInt(2) * 2 - 1) * 0.69999999999999996D;

        if (rand.nextBoolean()) {
          double d21 = (posX - d12 * d18 * 0.80000000000000004D) + d15 * d20;
          double d23 = posZ - d15 * d18 * 0.80000000000000004D - d12 * d20;
          // worldObj.spawnParticle("splash", d21, posY - 0.125D, d23, motionX, motionY, motionZ);
        } else {
          double d22 = posX + d12 + d15 * d18 * 0.69999999999999996D;
          double d24 = (posZ + d15) - d12 * d18 * 0.69999999999999996D;
          // worldObj.spawnParticle("splash", d22, posY - 0.125D, d24, motionX, motionY, motionZ);
        }
      }
    }

    if (isCollidedHorizontally && d8 > 0.14999999999999999D) {
      if (!worldObj.isRemote) {
        setDead();
      }
    } else {
      motionX *= 0.99000000953674316D;
      motionY *= 0.94999998807907104D;
      motionZ *= 0.99000000953674316D;
    }

    rotationPitch = 0.0F;
    double d13 = rotationYaw;
    double d16 = prevPosX - posX;
    double d17 = prevPosZ - posZ;

    if (d16 * d16 + d17 * d17 > 0.001D) {
      d13 = (float) ((Math.atan2(d17, d16) * 180D) / Math.PI);
    }

    double d19;

    for (d19 = d13 - (double) rotationYaw; d19 >= 180D; d19 -= 360D) {}

    for (; d19 < -180D; d19 += 360D) {}

    if (d19 > 20D) {
      d19 = 20D;
    }

    if (d19 < -20D) {
      d19 = -20D;
    }

    rotationYaw += d19;
    setRotation(rotationYaw, rotationPitch);
    // List list = worldObj.getEntitiesWithinAABBExcludingEntity(this,
    // boundingBox.expand(0.20000000298023224D, 0.0D, 0.20000000298023224D));
    List list =
        worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(0.0D, 0.0D, 0.0D));

    if (list != null && list.size() > 0) {
      for (int j1 = 0; j1 < list.size(); j1++) {
        Entity entity = (Entity) list.get(j1);

        if (entity != riddenByEntity && entity.canBePushed() && (entity instanceof EntityBoat)) {
          entity.applyEntityCollision(this);
        }
      }
    }

    for (int k1 = 0; k1 < 4; k1++) {
      int l1 = MathHelper.floor_double(posX + ((double) (k1 % 2) - 0.5D) * 0.80000000000000004D);
      int i2 = MathHelper.floor_double(posY);
      int j2 = MathHelper.floor_double(posZ + ((double) (k1 / 2) - 0.5D) * 0.80000000000000004D);

      if (worldObj.getBlockId(l1, i2, j2) == Block.snow.blockID) {
        worldObj.setBlockWithNotify(l1, i2, j2, 0);
      }
    }

    if (riddenByEntity != null && riddenByEntity.isDead) {
      riddenByEntity = null;
    }
  }