Search in sources :

Example 1 with Garden

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

the class Dimension method init.

private void init() {
    listeners = new ArrayList<>();
    dirtyTiles = new HashSet<>();
    addedTiles = new HashSet<>();
    removedTiles = new HashSet<>();
    propertyChangeSupport = new PropertyChangeSupport(this);
    garden = new WPGarden();
    topLayerDepthNoise = new PerlinNoise(seed + TOP_LAYER_DEPTH_SEED_OFFSET);
    for (Tile tile : tiles.values()) {
        tile.addListener(this);
        Set<Seed> seeds = tile.getSeeds();
        if (seeds != null) {
            for (Seed gardenSeed : seeds) {
                gardenSeed.garden = garden;
            }
        }
    }
    // Legacy support
    if (wpVersion < 1) {
        if (borderSize == 0) {
            borderSize = 2;
        }
        if (overlayScale == 0.0f) {
            overlayScale = 1.0f;
        }
        if (overlayTransparency == 0.0f) {
            overlayTransparency = 0.5f;
        }
        if (gridSize == 0) {
            gridSize = 128;
        }
        if (!biomesConverted) {
            // Convert the nibble sized biomes data from a legacy map (by
            // deleting it so that it will be recalculated
            tiles.values().forEach(org.pepsoft.worldpainter.Tile::convertBiomeData);
            biomesConverted = true;
        }
        if (maxHeight == 0) {
            maxHeight = 128;
        }
        if (subsurfaceMaterial == Terrain.RESOURCES) {
            subsurfaceMaterial = Terrain.STONE;
            // Load legacy settings
            ResourcesExporterSettings settings = new ResourcesExporterSettings(maxHeight);
            settings.setChance(BLK_GOLD_ORE, 1);
            settings.setChance(BLK_IRON_ORE, 5);
            settings.setChance(BLK_COAL, 9);
            settings.setChance(BLK_LAPIS_LAZULI_ORE, 1);
            settings.setChance(BLK_DIAMOND_ORE, 1);
            settings.setChance(BLK_REDSTONE_ORE, 6);
            settings.setChance(BLK_WATER, 1);
            settings.setChance(BLK_LAVA, 1);
            settings.setChance(BLK_DIRT, 9);
            settings.setChance(BLK_GRAVEL, 9);
            settings.setMaxLevel(BLK_GOLD_ORE, Terrain.GOLD_LEVEL);
            settings.setMaxLevel(BLK_IRON_ORE, Terrain.IRON_LEVEL);
            settings.setMaxLevel(BLK_COAL, Terrain.COAL_LEVEL);
            settings.setMaxLevel(BLK_LAPIS_LAZULI_ORE, Terrain.LAPIS_LAZULI_LEVEL);
            settings.setMaxLevel(BLK_DIAMOND_ORE, Terrain.DIAMOND_LEVEL);
            settings.setMaxLevel(BLK_REDSTONE_ORE, Terrain.REDSTONE_LEVEL);
            settings.setMaxLevel(BLK_WATER, Terrain.WATER_LEVEL);
            settings.setMaxLevel(BLK_LAVA, Terrain.LAVA_LEVEL);
            settings.setMaxLevel(BLK_DIRT, Terrain.DIRT_LEVEL);
            settings.setMaxLevel(BLK_GRAVEL, Terrain.GRAVEL_LEVEL);
            layerSettings.put(Resources.INSTANCE, settings);
        }
        if (contourSeparation == 0) {
            contourSeparation = 10;
        }
        if (topLayerMinDepth == 0) {
            topLayerMinDepth = 3;
            topLayerVariation = 4;
        }
        if (lastViewPosition == null) {
            lastViewPosition = new Point();
        }
        if ((customLayers == null) || customLayers.isEmpty()) {
            // The customLayers.isEmpty() is to fix a bug which escaped in a beta
            customLayers = new ArrayList<>();
            customLayers.addAll(getAllLayers(false).stream().filter(layer -> layer instanceof CustomLayer).map(layer -> (CustomLayer) layer).collect(Collectors.toList()));
        }
    }
    if (wpVersion < 2) {
        if (overlay != null) {
            fixOverlayCoords = true;
        }
    }
    if (wpVersion < 3) {
        ceilingHeight = maxHeight;
    }
    wpVersion = CURRENT_WP_VERSION;
    // Make sure that any custom layers which somehow ended up in the world
    // are on the custom layer list so they will be added to a palette in
    // the GUI. TODO: fix this properly
    // Make sure customLayers isn't some weird read-only list
    getAllLayers(false).stream().filter(layer -> (layer instanceof CustomLayer) && (!customLayers.contains(layer))).forEach(layer -> {
        if ((!(customLayers instanceof ArrayList)) && (!(customLayers instanceof LinkedList))) {
            // Make sure customLayers isn't some weird read-only list
            customLayers = new ArrayList<>(customLayers);
        }
        customLayers.add((CustomLayer) layer);
    });
}
Also used : java.util(java.util) CustomBiome(org.pepsoft.worldpainter.biomeschemes.CustomBiome) ExporterSettings(org.pepsoft.worldpainter.layers.exporters.ExporterSettings) ObjectInputStream(java.io.ObjectInputStream) org.pepsoft.worldpainter.layers(org.pepsoft.worldpainter.layers) UndoManager(org.pepsoft.util.undo.UndoManager) ResourcesExporterSettings(org.pepsoft.worldpainter.layers.exporters.ResourcesExporter.ResourcesExporterSettings) Point3i(javax.vecmath.Point3i) AttributeKey(org.pepsoft.util.AttributeKey) ImageIO(javax.imageio.ImageIO) SelectionChunk(org.pepsoft.worldpainter.selection.SelectionChunk) MathUtils(org.pepsoft.util.MathUtils) Garden(org.pepsoft.worldpainter.gardenofeden.Garden) Constants(org.pepsoft.worldpainter.Constants) PerlinNoise(org.pepsoft.util.PerlinNoise) ImageReader(javax.imageio.ImageReader) Seed(org.pepsoft.worldpainter.gardenofeden.Seed) DefaultFilter(org.pepsoft.worldpainter.panels.DefaultFilter) IOException(java.io.IOException) FileImageInputStream(javax.imageio.stream.FileImageInputStream) Collectors(java.util.stream.Collectors) File(java.io.File) ImageInputStream(javax.imageio.stream.ImageInputStream) Serializable(java.io.Serializable) java.awt(java.awt) List(java.util.List) Brush(org.pepsoft.worldpainter.brushes.Brush) PropertyChangeListener(java.beans.PropertyChangeListener) Constants(org.pepsoft.minecraft.Constants) ProgressReceiver(org.pepsoft.util.ProgressReceiver) SelectionBlock(org.pepsoft.worldpainter.selection.SelectionBlock) OperationCancelled(org.pepsoft.util.ProgressReceiver.OperationCancelled) PropertyChangeSupport(java.beans.PropertyChangeSupport) Filter(org.pepsoft.worldpainter.operations.Filter) javax.swing(javax.swing) Minecraft1_7Biomes(org.pepsoft.worldpainter.biomeschemes.Minecraft1_7Biomes) PropertyChangeSupport(java.beans.PropertyChangeSupport) PerlinNoise(org.pepsoft.util.PerlinNoise) ResourcesExporterSettings(org.pepsoft.worldpainter.layers.exporters.ResourcesExporter.ResourcesExporterSettings) Seed(org.pepsoft.worldpainter.gardenofeden.Seed)

Example 2 with Garden

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

the class TestTool method main.

public static void main(String[] args) throws IOException, OperationCancelled {
    Random random = new Random();
    long seed = random.nextLong();
    // TileFactory tileFactory = new NoiseTileFactory(Terrain.GRASS, DEFAULT_MAX_HEIGHT_2, 58, 62, false, false);
    TileFactory tileFactory = TileFactoryFactory.createFlatTileFactory(seed, Terrain.GRASS, DEFAULT_MAX_HEIGHT_2, 62, 0, false, false);
    World2 world = new World2(JAVA_ANVIL, seed, tileFactory, DEFAULT_MAX_HEIGHT_2);
    world.setName("TestWorld");
    world.setSpawnPoint(new Point(64, 64));
    world.setGameType(GameType.CREATIVE);
    Dimension dimension = world.getDimension(0);
    dimension.addTile(tileFactory.createTile(0, 0));
    Garden garden = dimension.getGarden();
    // garden.plantSeed(inn);
    while (!garden.tick()) ;
    JavaWorldExporter worldExporter = new JavaWorldExporter(world);
    File exportDir = new File(args[0]);
    worldExporter.export(exportDir, "TestWorld", worldExporter.selectBackupDir(new File(exportDir, "TestWorld")), null);
}
Also used : Garden(org.pepsoft.worldpainter.gardenofeden.Garden) Random(java.util.Random) JavaWorldExporter(org.pepsoft.worldpainter.exporting.JavaWorldExporter) Dimension(org.pepsoft.worldpainter.Dimension) File(java.io.File)

Example 3 with Garden

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

the class RiverGenerator method generateRivers.

public void generateRivers() {
    dimension.setEventsInhibited(true);
    UndoManager undoManager = new UndoManager(2);
    dimension.register(undoManager);
    snapshot = dimension.getSnapshot();
    dimension.armSavePoint();
    garden = dimension.getGarden();
    try {
        dimension.getTiles().forEach(this::generateRivers);
        // Grow seeds until all activity has ceased
        while (!garden.tick()) ;
        // Apply the river nodes to the landscape
        // A river source
        dimension.getGarden().getSeeds().stream().filter(seed -> (seed instanceof RiverNode) && (seed.getParent() == null)).forEach(seed -> {
            // A river source
            ((RiverNode) seed).apply(dimension, snapshot, new HashSet<>());
        });
    } finally {
        garden = null;
        snapshot = null;
        dimension.unregister();
        dimension.setEventsInhibited(false);
    }
}
Also used : HashSet(java.util.HashSet) Dimension(org.pepsoft.worldpainter.Dimension) Constants(org.pepsoft.worldpainter.Constants) UndoManager(org.pepsoft.util.undo.UndoManager) Point3i(javax.vecmath.Point3i) Tile(org.pepsoft.worldpainter.Tile) Random(java.util.Random) Garden(org.pepsoft.worldpainter.gardenofeden.Garden) UndoManager(org.pepsoft.util.undo.UndoManager)

Aggregations

Garden (org.pepsoft.worldpainter.gardenofeden.Garden)3 File (java.io.File)2 Random (java.util.Random)2 Point3i (javax.vecmath.Point3i)2 UndoManager (org.pepsoft.util.undo.UndoManager)2 Constants (org.pepsoft.worldpainter.Constants)2 Dimension (org.pepsoft.worldpainter.Dimension)2 java.awt (java.awt)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 PropertyChangeSupport (java.beans.PropertyChangeSupport)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 Serializable (java.io.Serializable)1 java.util (java.util)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ImageIO (javax.imageio.ImageIO)1 ImageReader (javax.imageio.ImageReader)1 FileImageInputStream (javax.imageio.stream.FileImageInputStream)1