@Override
  public void onUpdate() {
    super.onUpdate();

    int i;

    if (this.timeUntilLaunch >= 100) {
      i = Math.abs(this.timeUntilLaunch / 100);
    } else {
      i = 1;
    }

    if ((this.getLaunched()
            || this.launchPhase == EnumLaunchPhase.IGNITED.getPhase() && this.rand.nextInt(i) == 0)
        && !GCCoreConfigManager.disableSpaceshipParticles
        && this.hasValidFuel()) {
      if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
        this.spawnParticles(this.getLaunched());
      }
    }

    if (this.rocketSoundUpdater != null
        && (this.launchPhase == EnumLaunchPhase.IGNITED.getPhase() || this.getLaunched())) {
      this.rocketSoundUpdater.update();
    }

    if (this.launchPhase == EnumLaunchPhase.LAUNCHED.getPhase() && this.hasValidFuel()) {
      double d = this.timeSinceLaunch / 250;

      d = Math.min(d, 1);

      if (d != 0.0) {
        this.motionY = -d * Math.cos((this.rotationPitch - 180) * Math.PI / 180.0D);
      }

      double multiplier = 1.0D;

      if (this.worldObj.provider instanceof IGalacticraftWorldProvider) {
        multiplier = ((IGalacticraftWorldProvider) this.worldObj.provider).getFuelUsageMultiplier();

        if (multiplier <= 0) {
          multiplier = 1;
        }
      }

      if (this.timeSinceLaunch % MathHelper.floor_double(3 * (1 / multiplier)) == 0) {
        this.removeFuel(1);
      }
    } else if (!this.hasValidFuel() && this.getLaunched() && !this.worldObj.isRemote) {
      if (Math.abs(Math.sin(this.timeSinceLaunch / 1000)) / 10 != 0.0) {
        this.motionY -= Math.abs(Math.sin(this.timeSinceLaunch / 1000)) / 20;
      }
    }
  }
Ejemplo n.º 2
0
  @Override
  public void onUpdate() {
    super.onUpdate();

    if (!this.worldObj.isRemote) {
      if (this.statusMessageCooldown > 0) {
        this.statusMessageCooldown--;
      }

      if (this.statusMessageCooldown == 0
          && this.lastStatusMessageCooldown > 0
          && this.statusValid) {
        this.autoLaunch();
      }

      if (this.autoLaunchCountdown > 0
          && (!(this instanceof EntityTieredRocket) || this.riddenByEntity != null)) {
        this.autoLaunchCountdown--;

        if (this.autoLaunchCountdown <= 0) {
          this.autoLaunch();
        }
      }

      if (this.autoLaunchSetting == EnumAutoLaunch.ROCKET_IS_FUELED
          && this.fuelTank.getFluidAmount() == this.fuelTank.getCapacity()
          && (!(this instanceof EntityTieredRocket) || this.riddenByEntity != null)) {
        this.autoLaunch();
      }

      if (this.autoLaunchSetting == EnumAutoLaunch.INSTANT) {
        if (this.autoLaunchCountdown == 0
            && (!(this instanceof EntityTieredRocket) || this.riddenByEntity != null)) {
          this.autoLaunch();
        }
      }

      if (this.autoLaunchSetting == EnumAutoLaunch.REDSTONE_SIGNAL) {
        if (this.ticks % 25 == 0) {
          if (this.getLandingPad() != null && this.getLandingPad().getConnectedTiles() != null) {
            for (ILandingPadAttachable tile : this.getLandingPad().getConnectedTiles()) {
              if (this.worldObj.getTileEntity(((TileEntity) tile).getPos()) != null) {
                try {
                  Class<?> controllerClass =
                      Class.forName(
                          "micdoodle8.mods.galacticraft.planets.mars.tile.TileEntityLaunchController");

                  try {
                    controllerClass.cast(this.worldObj.getTileEntity(((TileEntity) tile).getPos()));
                  } catch (ClassCastException e) {
                    continue;
                  }

                  if (this.worldObj.isBlockIndirectlyGettingPowered(((TileEntity) tile).getPos())
                      > 0) {
                    this.autoLaunch();
                  }
                } catch (Exception e) {
                  e.printStackTrace();
                }
              }
            }
          }
        }
      }

      if (this.launchPhase == EnumLaunchPhase.LAUNCHED.ordinal() && this.hasValidFuel()) {
        if (this.landing
            && this.targetVec != null
            && this.worldObj.getTileEntity(this.targetVec) instanceof IFuelDock) {
          this.motionY =
              Math.max(
                  -2.0F,
                  (this.posY - this.getOnPadYOffset() - 0.4D - this.targetVec.getY()) / -70.0D);

          if (this.getEntityBoundingBox().minY - this.targetVec.getY() < 0.5F) {
            for (int x = MathHelper.floor_double(this.posX) - 1;
                x <= MathHelper.floor_double(this.posX) + 1;
                x++) {
              for (int y =
                      MathHelper.floor_double(
                              this.getEntityBoundingBox().minY - this.getOnPadYOffset() - 0.45D)
                          - 1;
                  y <= MathHelper.floor_double(this.getEntityBoundingBox().maxY) + 1;
                  y++) {
                for (int z = MathHelper.floor_double(this.posZ) - 1;
                    z <= MathHelper.floor_double(this.posZ) + 1;
                    z++) {
                  TileEntity tile = this.worldObj.getTileEntity(new BlockPos(x, y, z));

                  if (tile instanceof IFuelDock) {
                    this.failRocket();
                  }
                }
              }
            }
          }
        }
      }

      if (this.getLandingPad() != null && this.getLandingPad().getConnectedTiles() != null) {
        for (ILandingPadAttachable tile : this.getLandingPad().getConnectedTiles()) {
          if (this.worldObj.getTileEntity(((TileEntity) tile).getPos()) != null
              && this.worldObj.getTileEntity(((TileEntity) tile).getPos())
                  instanceof TileEntityFuelLoader) {
            if (tile instanceof TileEntityFuelLoader
                && ((TileEntityFuelLoader) tile).getEnergyStoredGC() > 0) {
              if (this.launchPhase == EnumLaunchPhase.LAUNCHED.ordinal()) {
                this.setPad(null);
              }
            }
          }
        }
      }

      this.lastStatusMessageCooldown = this.statusMessageCooldown;
    }

    if (this.launchPhase == EnumLaunchPhase.IGNITED.ordinal() || this.getLaunched()) {
      if (this.rocketSoundUpdater != null) {
        this.rocketSoundUpdater.update();
        this.rocketSoundToStop = true;
      }
    } else {
      // Not ignited - either because not yet launched, or because it has landed
      if (this.rocketSoundToStop) this.stopRocketSound();
    }
  }