コード例 #1
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;
        }
      }
    }
  }
コード例 #2
0
ファイル: SpoutWorld.java プロジェクト: nightslashs/Spout
 @Override
 public SpoutBlock getBlock(float x, float y, float z) {
   return this.getBlock(GenericMath.floor(x), GenericMath.floor(y), GenericMath.floor(z));
 }