Пример #1
0
  @Override
  public void populate(World world, Random random, Chunk source) {
    ChunkSnapshot snapshot = source.getChunkSnapshot();

    if (random.nextInt(100) < CHANCE_OF_1) {
      {
        int x, z, x2, z2;
        if (random.nextBoolean()) {
          x = random.nextBoolean() ? 0 : 15;
          x2 = x == 0 ? 1 : 14;
          z2 = z = random.nextInt(14) + 1;
        } else {
          x2 = x = random.nextInt(14) + 1;
          z = random.nextBoolean() ? 0 : 15;
          z2 = z == 0 ? 1 : 14;
        }
        if (snapshot.getHighestBlockYAt(x, z) > FLOOR_HEIGHT + MAX_HEIGHT
            && snapshot.getHighestBlockYAt(x2, z2) <= FLOOR_HEIGHT + MIN_HEIGHT) {
          Material type =
              random.nextInt(100) < LIT_CHANCE ? Material.JACK_O_LANTERN : Material.PUMPKIN;
          source
              .getBlock(
                  x,
                  snapshot.getHighestBlockYAt(x2, z2)
                      + random.nextInt(MAX_HEIGHT - MIN_HEIGHT + 1)
                      + MIN_HEIGHT,
                  z)
              .setTypeIdAndData(type.getId(), getData(x, z, x2, z2, type), true);
        }
      }

      if (random.nextInt(100) < CHANCE_OF_2) {
        int x, z, x2, z2;
        if (random.nextBoolean()) {
          x = random.nextBoolean() ? 0 : 15;
          x2 = x == 0 ? 1 : 14;
          z2 = z = random.nextInt(14) + 1;
        } else {
          x2 = x = random.nextInt(14) + 1;
          z = random.nextBoolean() ? 0 : 15;
          z2 = z == 0 ? 1 : 14;
        }
        if (snapshot.getHighestBlockYAt(x, z) > FLOOR_HEIGHT + MAX_HEIGHT
            && snapshot.getHighestBlockYAt(x2, z2) <= FLOOR_HEIGHT + MIN_HEIGHT) {
          Material type =
              random.nextInt(100) < LIT_CHANCE ? Material.JACK_O_LANTERN : Material.PUMPKIN;
          source
              .getBlock(
                  x,
                  snapshot.getHighestBlockYAt(x2, z2)
                      + random.nextInt(MAX_HEIGHT - MIN_HEIGHT + 1)
                      + MIN_HEIGHT,
                  z)
              .setTypeIdAndData(type.getId(), getData(x, z, x2, z2, type), true);
        }
      }
    }
  }
  @Override
  public void render(ChunkSnapshot chunkSnapshot) {
    BufferedImage image = ImageProvider.createImage(Coordinate.SIZE_CHUNK);
    Graphics2D g = (Graphics2D) image.getGraphics();
    for (int x = 0; x < 16; x++) {
      for (int z = 0; z < 16; z++) {
        // TODO: Handle cases where we can start at an opaque non-terrain block
        for (int y = TerrainHelper.getTerrainHeight(x, z, chunkSnapshot);
            y <= chunkSnapshot.getHighestBlockYAt(x, z);
            y++) {
          Material material = Material.getMaterial(chunkSnapshot.getBlockTypeId(x, y, z));
          Color color = getMaterialColor(material, chunkSnapshot, x, y, z);

          if (TerrainHelper.isTerrain(material)) {
            double shading = computeDiffuseShading(chunkSnapshot, x, z, this.normalMap);
            if (shading >= 0) {
              color = tintOrShadeColor(color, shading, 1.0);
            }
          } else if (TerrainHelper.isStructure(material)) {
            double shading = computeDiffuseShading(chunkSnapshot, x, z, this.structureMap);
            if (shading >= 0) {
              if (material.equals(Material.LEAVES)) {
                color = tintOrShadeColor(color, shading, 0.3);
              } else {
                color = tintOrShadeColor(color, shading, 1.0);
              }
            }
          }

          g.setColor(color);
          g.fillRect(x, z, 1, 1);
        }
      }
    }
    imageProvider.setImage(Coordinate.fromSnapshot(chunkSnapshot), image);
  }
Пример #3
0
 public final int getHighestBlockYAt(int x, int z) {
   return chunk.getHighestBlockYAt(x, z);
 }