private void placeCactuses(World world, int rx, int rz, Random random) {
    for (int i = 0; i < random.nextInt(32); i++) {
      int x = random.nextInt(15);
      int z = random.nextInt(15);

      int ran = 0;

      Biome biome = world.getBiome(rx + x, rz + z);

      if (biome.equals(Biome.EXTREME_HILLS)) {
        ran = random.nextInt(16);
      } else if (biome.equals(Biome.FOREST) || biome.equals(Biome.FOREST_HILLS)) {
        ran = random.nextInt(3);
      } else if (biome.equals(Biome.PLAINS)) {
        ran = random.nextInt(10);
      } else if (biome.equals(Biome.JUNGLE) || biome.equals(Biome.JUNGLE_HILLS)) {
        ran = random.nextInt(2);
      } else if (biome.equals(Biome.SWAMPLAND)) {
        ran = random.nextInt(8);
      } else if (biome.equals(Biome.TAIGA) || biome.equals(Biome.TAIGA_HILLS)) {
        ran = random.nextInt(20);
      } else if (biome.equals(Biome.ROOFED_FOREST) || biome.equals(Biome.MUTATED_ROOFED_FOREST)) {
        ran = random.nextInt(6);
      } else if (biome.equals(Biome.DESERT)) {
        ran = random.nextInt(100);
      }

      if (ran == 1) {
        Block block = world.getHighestBlockAt(rx + x, rz + z);
        block = world.getBlockAt(rx + x, block.getY() - 1, rz + z);
        if (block.getType().equals(Material.SAND)) {
          int y = block.getY();
          for (int j = 1; j < 2 + random.nextInt(4); j++) {
            block = world.getBlockAt(rx + x, y + j, rz + z);
            block.setType(Material.CACTUS);
          }
        }
      }
    }
  }
  private void placeShrubs(World world, int rx, int rz, Random random) {
    for (int i = 0; i < random.nextInt(32); i++) {
      int x = random.nextInt(15);
      int z = random.nextInt(15);

      int ran = 0;

      Biome biome = world.getBiome(rx + x, rz + z);

      if (biome.equals(Biome.EXTREME_HILLS)) {
        ran = random.nextInt(16);
      } else if (biome.equals(Biome.FOREST) || biome.equals(Biome.FOREST_HILLS)) {
        ran = random.nextInt(6);
      } else if (biome.equals(Biome.PLAINS)) {
        ran = random.nextInt(20);
      } else if (biome.equals(Biome.JUNGLE) || biome.equals(Biome.JUNGLE_HILLS)) {
        ran = random.nextInt(3);
      } else if (biome.equals(Biome.SWAMPLAND)) {
        ran = random.nextInt(14);
      } else if (biome.equals(Biome.TAIGA) || biome.equals(Biome.TAIGA_HILLS)) {
        ran = random.nextInt(12);
      } else if (biome.equals(Biome.ROOFED_FOREST) || biome.equals(Biome.MUTATED_ROOFED_FOREST)) {
        ran = random.nextInt(7);
      } else if (biome.equals(Biome.DESERT)) {
        ran = random.nextInt(3);
      } else {
        ran = random.nextInt(5);
      }

      if (ran == 1) {
        Block block = world.getHighestBlockAt(rx + x, rz + z);
        block.setType(Material.DEAD_BUSH);
      }
    }
  }
Beispiel #3
0
  // Generate a chunk
  @Override
  public byte[] generate(World world, Random rand, int chunkx, int chunkz) {
    // Create a byte variable to write the chunk inside and return this variable
    byte[] result = new byte[32768];

    // This will set the whole floor to stone (the floor of each chunk)
    for (int y = 30 + 3; y > 0; y--)
      for (int x = 0; x < 16; x++)
        for (int z = 0; z < 16; z++) result[xyzToByte(x, y, z)] = (byte) Material.STONE.getId();

    // Set the lowest layer to bedrock
    for (int x = 0; x < 16; x++)
      for (int z = 0; z < 16; z++) result[xyzToByte(x, 0, z)] = (byte) Material.BEDROCK.getId();

    // The layers for each 5 rooms in the variable y
    for (int y = 30; y < 30 + (7 * 6); y += 6) {

      // The 4 rooms on each layer saved in the variables x and z
      for (int x = 0; x < 16; x += 8) {
        for (int z = 0; z < 16; z += 8) {

          int xr = (rand.nextInt(3) - 1) * (x + 7);
          int zr = (rand.nextInt(3) - 1) * (z + 7);

          int yfloor = rand.nextInt(2);

          // All the y of the room in the variable y2
          for (int y2 = y + yfloor; y2 < y + 8; y2++) {

            // All the x of the room in the variable x2
            for (int x2 = x; x2 < x + 8; x2++) {

              // All the z of the room in the variable z2
              for (int z2 = z; z2 < z + 8; z2++) {

                // Make the bottom of the room
                if (y2 == y + yfloor)
                  for (int xb = x; xb < x + 8; xb++)
                    for (int zb = z; zb < z + 8; zb++)
                      result[xyzToByte(xb, y2, zb)] = (byte) Material.COBBLESTONE.getId();

                // Fill the walls of the place with cobblestone
                if ((x2 == x || x2 == x + 7) && (z2 == z || z2 == z + 7))
                  result[xyzToByte(x2, y2, z2)] = (byte) 98;
                else if (xr == x2) result[xyzToByte(x2, y2, z2)] = (byte) 98;
                else if (zr == z2) result[xyzToByte(x2, y2, z2)] = (byte) 98;
                else result[xyzToByte(x2, y2, z2)] = (byte) Material.AIR.getId();
              }
            }
          }
        }
      }
    }

    // Create the nose generator which generates wave formes to use for the surface.
    Random random = new Random(world.getSeed());
    SimplexOctaveGenerator octave = new SimplexOctaveGenerator(random, 8);
    octave.setScale(1 / 48.0);

    // Generate the ceiling and the grass land
    for (int x = 0; x < 16; x++) {
      for (int z = 0; z < 16; z++) {
        /*int height = getHeight(world, chunkx + x * 0.0625, chunkz + z * 0.0625, 2) + 30+(7*6) + 7;*/
        double height = octave.noise(x + chunkx * 16, z + chunkz * 16, 0.5, 0.5) * 4 + 9;

        result[xyzToByte(x, 30 + (7 * 6), z)] = (byte) Material.COBBLESTONE.getId();
        for (int y = 30 + (7 * 6) + 1; y < 30 + (7 * 6) + 4; y++)
          result[xyzToByte(x, y, z)] = (byte) Material.STONE.getId();

        // Get the current biome
        Biome biome = world.getBiome((chunkx * 16) + x, (chunkz * 16) + z);

        if (biome.equals(Biome.DESERT) || biome.equals(Biome.DESERT_HILLS)) {
          for (int y = 30 + (7 * 6) + 4; y < 30 + (7 * 6) + 2 + height; y++)
            result[xyzToByte(x, y, z)] = (byte) Material.SAND.getId();

        } else if (biome.equals(Biome.MUSHROOM_ISLAND) || biome.equals(Biome.MUSHROOM_ISLAND)) {
          for (int y = 30 + (7 * 6) + 4; y < 30 + (7 * 6) + 2 + height; y++)
            result[xyzToByte(x, y, z)] = (byte) Material.DIRT.getId();
          result[xyzToByte(x, (int) (30 + (7 * 6) + 2 + height), z)] =
              (byte) Material.MYCEL.getId();

        } else {
          for (int y = 30 + (7 * 6) + 4; y < 30 + (7 * 6) + 2 + height; y++)
            result[xyzToByte(x, y, z)] = (byte) Material.DIRT.getId();
          result[xyzToByte(x, (int) (30 + (7 * 6) + 2 + height), z)] =
              (byte) Material.GRASS.getId();
        }
      }
    }

    return result;
  }