Search in sources :

Example 1 with TileFactory

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

the class Sponge method tick.

@Override
protected void tick(int centreX, int centreY, boolean inverse, boolean first, float dynamicLevel) {
    final int waterHeight;
    final Dimension dimension = getDimension();
    final TileFactory tileFactory = dimension.getTileFactory();
    if (tileFactory instanceof HeightMapTileFactory) {
        waterHeight = ((HeightMapTileFactory) tileFactory).getWaterHeight();
    } else {
        // If we can't determine the water height disable the inverse
        // functionality, which resets to the default water height
        waterHeight = -1;
    }
    dimension.setEventsInhibited(true);
    try {
        final int radius = getEffectiveRadius();
        for (int dx = -radius; dx <= radius; dx++) {
            for (int dy = -radius; dy <= radius; dy++) {
                if (getStrength(centreX, centreY, centreX + dx, centreY + dy) != 0f) {
                    if (inverse) {
                        if (waterHeight != -1) {
                            dimension.setWaterLevelAt(centreX + dx, centreY + dy, waterHeight);
                            dimension.setBitLayerValueAt(FloodWithLava.INSTANCE, centreX + dx, centreY + dy, false);
                        }
                    } else {
                        dimension.setWaterLevelAt(centreX + dx, centreY + dy, 0);
                    }
                }
            }
        }
    } finally {
        dimension.setEventsInhibited(false);
    }
}
Also used : HeightMapTileFactory(org.pepsoft.worldpainter.HeightMapTileFactory) Dimension(org.pepsoft.worldpainter.Dimension) TileFactory(org.pepsoft.worldpainter.TileFactory) HeightMapTileFactory(org.pepsoft.worldpainter.HeightMapTileFactory)

Example 2 with TileFactory

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

the class RepairHeightMap method repairDimension.

private static final boolean repairDimension(Dimension dimension) {
    TileFactory tileFactory = dimension.getTileFactory();
    if (tileFactory instanceof HeightMapTileFactory) {
        HeightMap heightMap = ((HeightMapTileFactory) tileFactory).getHeightMap();
        if ((heightMap instanceof SumHeightMap) && ((((SumHeightMap) heightMap).getHeightMap1() == null) || (((SumHeightMap) heightMap).getHeightMap2() == null))) {
            System.out.println("Broken height map found in dimension " + dimension.getName() + "; replacing with default height map");
            heightMap = new ConstantHeightMap(46);
            // heightMap = new SumHeightMap(new ConstantHeightMap(58), new NoiseHeightMap(20, 1.0, 1));
            ((HeightMapTileFactory) tileFactory).setHeightMap(heightMap);
            return true;
        }
    }
    return false;
}
Also used : SumHeightMap(org.pepsoft.worldpainter.heightMaps.SumHeightMap) ConstantHeightMap(org.pepsoft.worldpainter.heightMaps.ConstantHeightMap) HeightMap(org.pepsoft.worldpainter.HeightMap) SumHeightMap(org.pepsoft.worldpainter.heightMaps.SumHeightMap) HeightMapTileFactory(org.pepsoft.worldpainter.HeightMapTileFactory) ConstantHeightMap(org.pepsoft.worldpainter.heightMaps.ConstantHeightMap) TileFactory(org.pepsoft.worldpainter.TileFactory) HeightMapTileFactory(org.pepsoft.worldpainter.HeightMapTileFactory)

Aggregations

HeightMapTileFactory (org.pepsoft.worldpainter.HeightMapTileFactory)2 TileFactory (org.pepsoft.worldpainter.TileFactory)2 Dimension (org.pepsoft.worldpainter.Dimension)1 HeightMap (org.pepsoft.worldpainter.HeightMap)1 ConstantHeightMap (org.pepsoft.worldpainter.heightMaps.ConstantHeightMap)1 SumHeightMap (org.pepsoft.worldpainter.heightMaps.SumHeightMap)1