Search in sources :

Example 1 with TreeLayer

use of org.pepsoft.worldpainter.layers.TreeLayer in project WorldPainter by Captain-Chaos.

the class SwampLandExporter method render.

@Override
public List<Fixup> render(Dimension dimension, Rectangle area, Rectangle exportedArea, MinecraftWorld world) {
    List<Fixup> fixups = super.render(dimension, area, exportedArea, world);
    // Render lily pads
    TreeLayerSettings<TreeLayer> settings = (TreeLayerSettings<TreeLayer>) getSettings();
    int minimumLevel = settings.getMinimumLevel();
    int maxZ = dimension.getMaxHeight() - 1;
    for (int chunkX = area.x; chunkX < area.x + area.width; chunkX += 16) {
        for (int chunkY = area.y; chunkY < area.y + area.height; chunkY += 16) {
            // Set the seed and randomizer according to the chunk
            // coordinates to make sure the chunk is always rendered the
            // same, no matter how often it is rendererd
            long seed = dimension.getSeed() + (chunkX >> 4) * 65537 + (chunkY >> 4) * 4099 + layer.hashCode() + 1;
            Random random = new Random(seed);
            for (int x = chunkX; x < chunkX + 16; x++) {
                for (int y = chunkY; y < chunkY + 16; y++) {
                    int terrainLevel = dimension.getIntHeightAt(x, y);
                    if (terrainLevel == -1) {
                        // height == -1 means there is no tile there
                        continue;
                    }
                    int waterLevel = dimension.getWaterLevelAt(x, y);
                    if ((waterLevel > terrainLevel) && (waterLevel < maxZ)) {
                        int strength = Math.max(minimumLevel, dimension.getLayerValueAt(layer, x, y));
                        if ((strength > 0) && (random.nextInt(3840) <= (strength * strength))) {
                            int blockType = world.getBlockTypeAt(x, y, waterLevel);
                            int blockTypeAbove = world.getBlockTypeAt(x, y, waterLevel + 1);
                            if (((blockType == BLK_WATER) || (blockType == BLK_STATIONARY_WATER)) && (blockTypeAbove == BLK_AIR)) {
                                world.setMaterialAt(x, y, waterLevel + 1, Material.LILY_PAD);
                            }
                        }
                    }
                }
            }
        }
    }
    return fixups;
}
Also used : Random(java.util.Random) TreeLayer(org.pepsoft.worldpainter.layers.TreeLayer) Fixup(org.pepsoft.worldpainter.exporting.Fixup)

Aggregations

Random (java.util.Random)1 Fixup (org.pepsoft.worldpainter.exporting.Fixup)1 TreeLayer (org.pepsoft.worldpainter.layers.TreeLayer)1