コード例 #1
0
 /**
  * Gets the strength of the thunder storm, which is affected by the duration
  *
  * @param factor to apply to the changing states
  * @return the strength
  */
 public float getThunderStrength(float factor) {
   float currentThunderStrength =
       weather.getSky().getData().get(VanillaData.CURRENT_LIGHTNING_STRENGTH);
   float previousThunderStrength =
       weather.getSky().getData().get(VanillaData.PREVIOUS_LIGHTNING_STRENGTH);
   return (previousThunderStrength + factor * (currentThunderStrength - previousThunderStrength));
 }
コード例 #2
0
 public Intensity getIntensity() {
   int intensity = weather.getSky().getData().get(VanillaData.STORM_INTENSITY);
   if (intensity >= 0 && intensity < Intensity.values().length) {
     return Intensity.values()[intensity];
   }
   return null;
 }
コード例 #3
0
ファイル: NormalSky.java プロジェクト: Zarklord1/Vanilla
  /**
   * Updates the time as a celestial sky system
   *
   * @param time to use
   * @param timeFactor unknown factor, use 1.0f
   */
  public void updateCelestialTime(long time, float timeFactor) {
    float celestial = VanillaMathHelper.getRealCelestialAngle(time, timeFactor);
    WeatherSimulator weather = this.getWeatherSimulator();
    if (weather != null) {
      celestial =
          (float)
              ((double) celestial
                  * (1.0d - (double) (weather.getRainStrength(timeFactor) * 5f) / 16d));
      celestial =
          (float)
              ((double) celestial
                  * (1.0d - (double) (weather.getThunderStrength(timeFactor) * 5f) / 16d));
    }
    this.getWorld().setSkyLight((byte) (celestial * (float) SKY_LIGHT_RANGE + MIN_SKY_LIGHT));

    broadcastMessage(new TimeUpdateMessage(time));
  }
コード例 #4
0
 @Override
 public void onTick(float dt) {
   float currentThunderStrength =
       weather.getSky().getData().get(VanillaData.CURRENT_LIGHTNING_STRENGTH);
   weather.getSky().getData().put(VanillaData.PREVIOUS_LIGHTNING_STRENGTH, currentThunderStrength);
   if (this.weather.isThundering()) {
     currentThunderStrength = Math.min(1.0f, currentThunderStrength + 0.01f);
   } else {
     currentThunderStrength = Math.max(0.0f, currentThunderStrength - 0.01f);
   }
   weather.getSky().getData().put(VanillaData.CURRENT_LIGHTNING_STRENGTH, currentThunderStrength);
   try {
     updatePlayerTimers();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
コード例 #5
0
  public void strikePlayers(List<Player> toStrike) {
    for (Player player : toStrike) {
      Point playerPos = player.getScene().getPosition();
      final int posX = GenericMath.floor(playerPos.getX());
      final int posY = GenericMath.floor(playerPos.getY());
      final int posZ = GenericMath.floor(playerPos.getZ());
      for (int tries = 0; tries < 10; tries++) {
        // pick a random chunk between -4, -4, to 4, 4 relative to the player's position to strike
        // at
        int cx = (ra.nextBoolean() ? -1 : 1) * ra.nextInt(5);
        int cz = (ra.nextBoolean() ? -1 : 1) * ra.nextInt(5);

        // pick random coords to try to strike at inside the chunk (0, 0) to (15, 15)
        int rx = ra.nextInt(16);
        int rz = ra.nextInt(16);

        // pick a offset from the player's y position to strike at (-15 - +15) of their position
        int offsetY = (ra.nextBoolean() ? -1 : 1) * ra.nextInt(15);

        int x = posX + cx * 16 + rx;
        int y = posY + offsetY;
        int z = posZ + cz * 16 + rz;

        if (weather.isRainingAt(x, y, z, false)) {
          int lightning = 1;
          // 30% chance of extra lightning at the spot
          if (ra.nextInt(10) < 3) {
            lightning += ra.nextInt(MAX_LIGHTNING_BRANCHES);
          }
          for (int strikes = 0; strikes < lightning; strikes++) {
            float adjustX = 0.5F;
            float adjustY = 0.0F;
            float adjustZ = 0.5F;
            // if there are extra strikes, tweak their placement slightly
            if (strikes > 0) {
              adjustX += (ra.nextBoolean() ? -1 : 1) * ra.nextInt(2);
              adjustY += (ra.nextBoolean() ? -1 : 1) * ra.nextInt(8);
              adjustZ += (ra.nextBoolean() ? -1 : 1) * ra.nextInt(2);
            }
            World world = getWorld();
            Point point = new Point(world, x + adjustX, y + adjustY, z + adjustZ);
            world.createAndSpawnEntity(point, Lightning.class, LoadOption.NO_LOAD);
            for (Player p : GeneralEffects.LIGHTNING_THUNDER.getNearbyPlayers(point, null, 600)) {
              double dist = p.getScene().getPosition().distanceSquared(point);
              float volume = (float) (10000F - Math.pow(dist, 0.73));
              if (volume > 0) {
                GeneralEffects.LIGHTNING_THUNDER.adjust(volume, 0.7F).play(p, point);
              }
            }
          }
          // success, go to the next player
          break;
        }
      }
    }
  }
コード例 #6
0
 public void setIntensity(Intensity in) {
   weather.getSky().getData().put(VanillaData.STORM_INTENSITY, in != null ? in.ordinal() : -1);
 }