Search in sources :

Example 1 with HeightMapTileFactory

use of org.pepsoft.worldpainter.HeightMapTileFactory 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 HeightMapTileFactory

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

the class TileFactoryPreviewer method main.

public static void main(String[] args) {
    final long seed;
    if (args.length > 0) {
        seed = Long.parseLong(args[0]);
    } else {
        seed = new Random().nextLong();
    }
    // final ExperimentalTileFactory tileFactory = new ExperimentalTileFactory(DEFAULT_MAX_HEIGHT_2);
    // final HeightMapTileFactory tileFactory = TileFactoryFactory.createNoiseTileFactory(Terrain.GRASS, World2.DEFAULT_MAX_HEIGHT, 58, 62, false, true, 20.0f, 1.0);
    // HeightMap oceanFloor = new ConstantHeightMap(40f);
    // HeightMap continent;
    // //        continent = new NinePatchHeightMap(200, 100, 50, 58f);
    // continent = new NinePatchHeightMap(0, 1000, 50, 22f);
    // HeightMap hills = new ProductHeightMap(
    // new NoiseHeightMap(1.0f, 10f, 1),
    // new SumHeightMap(
    // new NoiseHeightMap(20.0f, 1.0f, 2),
    // new ConstantHeightMap(-5f)));
    // continent = new SumHeightMap(
    // new SumHeightMap(
    // oceanFloor,
    // continent),
    // hills);
    // HeightMap mountainsLimit = new NinePatchHeightMap(0, 1000, 200, 1f);
    // HeightMap mountains = new ProductHeightMap(
    // new ProductHeightMap(
    // new NoiseHeightMap(1.0f, 10f, 1),
    // mountainsLimit),
    // new NoiseHeightMap(256f, 5f, 4));
    // HeightMap heightMap = new MaximisingHeightMap(continent, mountains);
    // final HeightMapTileFactory tileFactory = new HeightMapTileFactory(seed, heightMap, 256, false, new FancyTheme(256, 62, heightMap));
    final HeightMapTileFactory tileFactory = TileFactoryFactory.createFancyTileFactory(seed, Terrain.GRASS, Constants.DEFAULT_MAX_HEIGHT_2, 62, 58, false, 20f, 1.0);
    // SortedMap<Integer, Terrain> terrainRanges = tileFactory.getTerrainRanges();
    // terrainRanges.clear();
    // terrainRanges.put( -1, Terrain.DIRT);
    // terrainRanges.put( 64, Terrain.GRASS);
    // terrainRanges.put(128, Terrain.ROCK);
    // terrainRanges.put(192, Terrain.DEEP_SNOW);
    // tileFactory.setTerrainRanges(terrainRanges);
    final org.pepsoft.worldpainter.TileProvider tileProvider = new org.pepsoft.worldpainter.TileProvider() {

        @Override
        public Rectangle getExtent() {
            // Tile factories are endless
            return null;
        }

        @Override
        public boolean isTilePresent(int x, int y) {
            // Tile factories are endless and have no holes
            return true;
        }

        @Override
        public Tile getTile(int x, int y) {
            Point coords = new Point(x, y);
            synchronized (cache) {
                Tile tile = cache.get(coords);
                if (tile == null) {
                    tile = tileFactory.createTile(x, y);
                    cache.put(coords, tile);
                }
                return tile;
            }
        }

        private final Map<Point, Tile> cache = new HashMap<>();
    };
    Terrain.setCustomMaterial(0, new MixedMaterial("Dirt/Gravel", new Row[] { new Row(Material.DIRT, 750, 1.0f), new Row(Material.GRAVEL, 250, 1.0f) }, Minecraft1_2BiomeScheme.BIOME_PLAINS, null, 1.0f));
    Terrain.setCustomMaterial(1, new MixedMaterial("Stone/Gravel", new Row[] { new Row(Material.STONE, 750, 1.0f), new Row(Material.GRAVEL, 250, 1.0f) }, Minecraft1_2BiomeScheme.BIOME_PLAINS, null, 1.0f));
    TiledImageViewer viewer = new TiledImageViewer();
    JFrame frame = new JFrame("TileFactory Previewer");
    viewer.setTileProvider(new WPTileProvider(tileProvider, new DynMapColourScheme("default", true), new AutoBiomeScheme(null), null, Collections.singleton((Layer) Biome.INSTANCE), true, 10, TileRenderer.LightOrigin.NORTHWEST, false, null));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(viewer, BorderLayout.CENTER);
    frame.setSize(1000, 800);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
Also used : AutoBiomeScheme(org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme) TiledImageViewer(org.pepsoft.util.swing.TiledImageViewer) Tile(org.pepsoft.worldpainter.Tile) Point(java.awt.Point) DynMapColourScheme(org.pepsoft.worldpainter.colourschemes.DynMapColourScheme) WPTileProvider(org.pepsoft.worldpainter.WPTileProvider) Random(java.util.Random) JFrame(javax.swing.JFrame) HeightMapTileFactory(org.pepsoft.worldpainter.HeightMapTileFactory) Row(org.pepsoft.worldpainter.MixedMaterial.Row) WPTileProvider(org.pepsoft.worldpainter.WPTileProvider) HashMap(java.util.HashMap) Map(java.util.Map) MixedMaterial(org.pepsoft.worldpainter.MixedMaterial)

Example 3 with HeightMapTileFactory

use of org.pepsoft.worldpainter.HeightMapTileFactory 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)3 TileFactory (org.pepsoft.worldpainter.TileFactory)2 Point (java.awt.Point)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Random (java.util.Random)1 JFrame (javax.swing.JFrame)1 TiledImageViewer (org.pepsoft.util.swing.TiledImageViewer)1 Dimension (org.pepsoft.worldpainter.Dimension)1 HeightMap (org.pepsoft.worldpainter.HeightMap)1 MixedMaterial (org.pepsoft.worldpainter.MixedMaterial)1 Row (org.pepsoft.worldpainter.MixedMaterial.Row)1 Tile (org.pepsoft.worldpainter.Tile)1 WPTileProvider (org.pepsoft.worldpainter.WPTileProvider)1 AutoBiomeScheme (org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme)1 DynMapColourScheme (org.pepsoft.worldpainter.colourschemes.DynMapColourScheme)1 ConstantHeightMap (org.pepsoft.worldpainter.heightMaps.ConstantHeightMap)1 SumHeightMap (org.pepsoft.worldpainter.heightMaps.SumHeightMap)1