Search in sources :

Example 11 with Row

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

the class WorldFactory method createFancyWorld.

public static World2 createFancyWorld(final Configuration config, final long seed) {
    final HeightMapTileFactory tileFactory = TileFactoryFactory.createFancyTileFactory(seed, Terrain.GRASS, DEFAULT_MAX_HEIGHT_2, 58, 62, false, 20f, 1.0);
    final Dimension defaults = config.getDefaultTerrainAndLayerSettings();
    final World2 world = new World2(JAVA_ANVIL, World2.DEFAULT_OCEAN_SEED, tileFactory, tileFactory.getMaxHeight());
    world.addHistoryEntry(HistoryEntry.WORLD_CREATED);
    if (config.getDefaultMaxHeight() == DEFAULT_MAX_HEIGHT_2) {
        world.setGenerator(Generator.LARGE_BIOMES);
    }
    world.setMixedMaterial(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));
    world.setMixedMaterial(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));
    final ResourceBundle strings = ResourceBundle.getBundle("org.pepsoft.worldpainter.resources.strings");
    world.setName(strings.getString("generated.world"));
    final Dimension dim0 = world.getDimension(0);
    final boolean circularWorld = true;
    final int radius = 750;
    dim0.setEventsInhibited(true);
    try {
        if (circularWorld) {
            final int tileRadius = (radius + 127) / 128;
            for (int x = -tileRadius; x < tileRadius; x++) {
                for (int y = -tileRadius; y < tileRadius; y++) {
                    if (getSmallestDistanceFromOrigin(x, y) < radius) {
                        // At least one corner is inside the circle; include
                        // the tile. Note that this is always correct in
                        // this case only because the centre of the circle
                        // is always at a tile intersection so the circle
                        // can never "bulge" into a tile without any of the
                        // the tile's corners being inside the circle
                        final Tile tile = tileFactory.createTile(x, y);
                        dim0.addTile(tile);
                    // if (org.pepsoft.worldpainter.util.MathUtils.getLargestDistanceFromOrigin(x, y) >= radius) {
                    // // The tile is not completely inside the circle,
                    // // so use the Void layer to create the shape of
                    // // the edge
                    // for (int xx = 0; xx < TILE_SIZE; xx++) {
                    // for (int yy = 0; yy < TILE_SIZE; yy++) {
                    // float distance = MathUtils.getDistance(x * TILE_SIZE + xx + 0.5f, y * TILE_SIZE + yy + 0.5f);
                    // if (distance > radius) {
                    // tile.setBitLayerValue(org.pepsoft.worldpainter.layers.Void.INSTANCE, xx, yy, true);
                    // }
                    // }
                    // }
                    // }
                    }
                }
            }
        // Assume the user will want a void border by default; override
        // the preferences
        // dim0.setBorder(Dimension.Border.VOID);
        // dim0.setBorderSize(2);
        } else {
            final int width = config.getDefaultWidth(), height = config.getDefaultHeight();
            final int startX = -width / 2;
            final int startY = -height / 2;
            for (int x = startX; x < startX + width; x++) {
                for (int y = startY; y < startY + height; y++) {
                    final Tile tile = tileFactory.createTile(x, y);
                    dim0.addTile(tile);
                }
            }
            dim0.setBorder(defaults.getBorder());
            dim0.setBorderSize(defaults.getBorderSize());
            dim0.setBedrockWall(defaults.isBedrockWall());
        }
        dim0.setBorderLevel(defaults.getBorderLevel());
        dim0.setSubsurfaceMaterial(defaults.getSubsurfaceMaterial());
        dim0.setPopulate(defaults.isPopulate());
        for (Map.Entry<Layer, ExporterSettings> entry : defaults.getAllLayerSettings().entrySet()) {
            dim0.setLayerSettings(entry.getKey(), entry.getValue().clone());
        }
        FrostExporter.FrostSettings frostSettings = (FrostExporter.FrostSettings) dim0.getLayerSettings(Frost.INSTANCE);
        if (frostSettings == null) {
            frostSettings = new FrostExporter.FrostSettings();
        }
        frostSettings.setMode(frostSettings.MODE_SMOOTH_AT_ALL_ELEVATIONS);
        dim0.setLayerSettings(Frost.INSTANCE, frostSettings);
        dim0.setGridEnabled(config.isDefaultGridEnabled());
        dim0.setGridSize(config.getDefaultGridSize());
        dim0.setContoursEnabled(config.isDefaultContoursEnabled());
        dim0.setContourSeparation(config.getDefaultContourSeparation());
        dim0.setTopLayerMinDepth(defaults.getTopLayerMinDepth());
        dim0.setTopLayerVariation(defaults.getTopLayerVariation());
        dim0.setBottomless(defaults.isBottomless());
    } finally {
        dim0.setEventsInhibited(false);
    }
    // final RiverGenerator riverGenerator = new RiverGenerator(dim0);
    // riverGenerator.generateRivers();
    world.setDirty(false);
    return world;
}
Also used : FrostExporter(org.pepsoft.worldpainter.layers.exporters.FrostExporter) ExporterSettings(org.pepsoft.worldpainter.layers.exporters.ExporterSettings) Layer(org.pepsoft.worldpainter.layers.Layer) ResourceBundle(java.util.ResourceBundle) Row(org.pepsoft.worldpainter.MixedMaterial.Row) TreeMap(java.util.TreeMap) Map(java.util.Map)

Aggregations

Row (org.pepsoft.worldpainter.MixedMaterial.Row)11 TableModelEvent (javax.swing.event.TableModelEvent)5 Map (java.util.Map)2 Point (java.awt.Point)1 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1 ResourceBundle (java.util.ResourceBundle)1 TreeMap (java.util.TreeMap)1 JFrame (javax.swing.JFrame)1 Test (org.junit.Test)1 Material (org.pepsoft.minecraft.Material)1 TiledImageViewer (org.pepsoft.util.swing.TiledImageViewer)1 HeightMapTileFactory (org.pepsoft.worldpainter.HeightMapTileFactory)1 MixedMaterial (org.pepsoft.worldpainter.MixedMaterial)1 Mode (org.pepsoft.worldpainter.MixedMaterial.Mode)1 MixedMaterialTableModel (org.pepsoft.worldpainter.MixedMaterialTableModel)1 Tile (org.pepsoft.worldpainter.Tile)1