Search in sources :

Example 1 with Seed

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

the class AbstractWorldExporter method secondPass.

protected List<Fixup> secondPass(List<Layer> secondaryPassLayers, Dimension dimension, MinecraftWorld minecraftWorld, Map<Layer, LayerExporter> exporters, Collection<Tile> tiles, Point regionCoords, ProgressReceiver progressReceiver) throws OperationCancelled {
    // Apply other secondary pass layers
    if (logger.isDebugEnabled()) {
        logger.debug("Start of second pass for region {},{}", regionCoords.x, regionCoords.y);
    }
    int layerCount = secondaryPassLayers.size(), counter = 0;
    Rectangle area = new Rectangle((regionCoords.x << 9) - 16, (regionCoords.y << 9) - 16, 544, 544);
    Rectangle exportedArea = new Rectangle((regionCoords.x << 9), (regionCoords.y << 9), 512, 512);
    List<Fixup> fixups = new ArrayList<>();
    // boolean frost = false;
    for (Layer layer : secondaryPassLayers) {
        // if (layer instanceof Frost) {
        // frost = true;
        // continue;
        // }
        @SuppressWarnings("unchecked") SecondPassLayerExporter exporter = (SecondPassLayerExporter) exporters.get(layer);
        if (logger.isDebugEnabled()) {
            logger.debug("Exporting layer {} for region {},{}", layer, regionCoords.x, regionCoords.y);
        }
        if (progressReceiver != null) {
            if (minecraftWorld instanceof InvertedWorld) {
                progressReceiver.setMessage("Exporting layer " + layer + " for ceiling");
            } else {
                progressReceiver.setMessage("Exporting layer " + layer);
            }
        }
        List<Fixup> layerFixups = exporter.render(dimension, area, exportedArea, minecraftWorld);
        if (layerFixups != null) {
            fixups.addAll(layerFixups);
        }
        if (progressReceiver != null) {
            counter++;
            progressReceiver.setProgress((float) counter / layerCount);
        }
    }
    // Garden / seeds first and second pass
    GardenExporter gardenExporter = new GardenExporter();
    Set<Seed> firstPassProcessedSeeds = new HashSet<>();
    Set<Seed> secondPassProcessedSeeds = new HashSet<>();
    tiles.stream().filter(tile -> tile.getLayers().contains(GardenCategory.INSTANCE)).forEach(tile -> {
        gardenExporter.firstPass(dimension, tile, minecraftWorld, firstPassProcessedSeeds);
        gardenExporter.secondPass(dimension, tile, minecraftWorld, secondPassProcessedSeeds);
    });
    // elegant
    if ((dimension.getDim() == 0) && world.isCreateGoodiesChest()) {
        Point goodiesPoint = (Point) world.getSpawnPoint().clone();
        goodiesPoint.translate(3, 3);
        int height = Math.min(dimension.getIntHeightAt(goodiesPoint) + 1, dimension.getMaxHeight() - 1);
        minecraftWorld.setMaterialAt(goodiesPoint.x, goodiesPoint.y, height, Material.CHEST_NORTH);
        Chunk chunk = minecraftWorld.getChunk(goodiesPoint.x >> 4, goodiesPoint.y >> 4);
        if ((chunk != null) && (chunk.getTileEntities() != null)) {
            Chest goodiesChest = createGoodiesChest();
            goodiesChest.setX(goodiesPoint.x);
            goodiesChest.setY(height);
            goodiesChest.setZ(goodiesPoint.y);
            chunk.getTileEntities().add(goodiesChest);
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("End of second pass for region {},{}", regionCoords.x, regionCoords.y);
    }
    return fixups;
}
Also used : java.util(java.util) org.pepsoft.minecraft(org.pepsoft.minecraft) BLOCKS(org.pepsoft.minecraft.Block.BLOCKS) EventVO(org.pepsoft.worldpainter.vo.EventVO) LoggerFactory(org.slf4j.LoggerFactory) ParallelProgressManager(org.pepsoft.util.ParallelProgressManager) PlatformProvider(org.pepsoft.worldpainter.plugins.PlatformProvider) SimpleDateFormat(java.text.SimpleDateFormat) SubProgressReceiver(org.pepsoft.util.SubProgressReceiver) CustomLayer(org.pepsoft.worldpainter.layers.CustomLayer) Platform(org.pepsoft.worldpainter.Platform) PlatformManager(org.pepsoft.worldpainter.plugins.PlatformManager) CombinedLayer(org.pepsoft.worldpainter.layers.CombinedLayer) DateFormat(java.text.DateFormat) PrintWriter(java.io.PrintWriter) Constants(org.pepsoft.worldpainter.Constants) Box(org.pepsoft.util.Box) AttributeKeyVO(org.pepsoft.worldpainter.vo.AttributeKeyVO) Logger(org.slf4j.Logger) Seed(org.pepsoft.worldpainter.gardenofeden.Seed) java.util.concurrent(java.util.concurrent) GardenExporter(org.pepsoft.worldpainter.gardenofeden.GardenExporter) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) GardenCategory(org.pepsoft.worldpainter.layers.GardenCategory) File(java.io.File) Layer(org.pepsoft.worldpainter.layers.Layer) Dimension(org.pepsoft.worldpainter.Dimension) java.awt(java.awt) List(java.util.List) Constants(org.pepsoft.minecraft.Constants) ProgressReceiver(org.pepsoft.util.ProgressReceiver) OperationCancelled(org.pepsoft.util.ProgressReceiver.OperationCancelled) Tile(org.pepsoft.worldpainter.Tile) World2(org.pepsoft.worldpainter.World2) NotNull(org.jetbrains.annotations.NotNull) CustomLayer(org.pepsoft.worldpainter.layers.CustomLayer) CombinedLayer(org.pepsoft.worldpainter.layers.CombinedLayer) Layer(org.pepsoft.worldpainter.layers.Layer) Seed(org.pepsoft.worldpainter.gardenofeden.Seed) GardenExporter(org.pepsoft.worldpainter.gardenofeden.GardenExporter)

Example 2 with Seed

use of org.pepsoft.worldpainter.gardenofeden.Seed 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 3 with Seed

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

the class Tile method transform.

/**
 * Create a new tile based on this one but horizontally transformed according to some transformation.
 *
 * @param transform The transform to apply.
 * @return A new tile with the same contents, except transformed according to the specified transform (including the
 * X and Y coordinates).
 */
public synchronized Tile transform(CoordinateTransform transform) {
    Point transformedCoords = transform.transform(x << TILE_SIZE_BITS, y << TILE_SIZE_BITS);
    Tile transformedTile;
    boolean transformContents = ((transformedCoords.x & TILE_SIZE_MASK) != 0) || ((transformedCoords.y & TILE_SIZE_MASK) != 0);
    if (transformContents) {
        transformedTile = new Tile(transformedCoords.x >> TILE_SIZE_BITS, transformedCoords.y >> TILE_SIZE_BITS, maxHeight);
        for (int x = 0; x < TILE_SIZE; x++) {
            for (int y = 0; y < TILE_SIZE; y++) {
                transformedCoords.x = x;
                transformedCoords.y = y;
                transform.transformInPlace(transformedCoords);
                transformedCoords.x &= TILE_SIZE_MASK;
                transformedCoords.y &= TILE_SIZE_MASK;
                transformedTile.setTerrain(transformedCoords.x, transformedCoords.y, getTerrain(x, y));
                transformedTile.setRawHeight(transformedCoords.x, transformedCoords.y, getRawHeight(x, y));
                transformedTile.setWaterLevel(transformedCoords.x, transformedCoords.y, getWaterLevel(x, y));
            }
        }
        for (Layer layer : getLayers()) {
            if ((layer.getDataSize() == Layer.DataSize.BIT) || (layer.getDataSize() == Layer.DataSize.BIT_PER_CHUNK)) {
                for (int x = 0; x < TILE_SIZE; x++) {
                    for (int y = 0; y < TILE_SIZE; y++) {
                        if (getBitLayerValue(layer, x, y)) {
                            transformedCoords.x = x;
                            transformedCoords.y = y;
                            transform.transformInPlace(transformedCoords);
                            transformedCoords.x &= TILE_SIZE_MASK;
                            transformedCoords.y &= TILE_SIZE_MASK;
                            transformedTile.setBitLayerValue(layer, transformedCoords.x, transformedCoords.y, true);
                        }
                    }
                }
            } else if (layer.getDataSize() != Layer.DataSize.NONE) {
                for (int x = 0; x < TILE_SIZE; x++) {
                    for (int y = 0; y < TILE_SIZE; y++) {
                        int value = getLayerValue(layer, x, y);
                        if (value > 0) {
                            transformedCoords.x = x;
                            transformedCoords.y = y;
                            transform.transformInPlace(transformedCoords);
                            transformedCoords.x &= TILE_SIZE_MASK;
                            transformedCoords.y &= TILE_SIZE_MASK;
                            transformedTile.setLayerValue(layer, transformedCoords.x, transformedCoords.y, value);
                        }
                    }
                }
            }
        }
    } else {
        // The transformation does not affect intra-tile coordinates, so just copy the buffers without transforming them
        transformedTile = new Tile(transformedCoords.x >> TILE_SIZE_BITS, transformedCoords.y >> TILE_SIZE_BITS, maxHeight, false);
        transformedTile.heightMap = copyObject(heightMap);
        transformedTile.tallHeightMap = copyObject(tallHeightMap);
        transformedTile.terrain = terrain.clone();
        transformedTile.waterLevel = copyObject(waterLevel);
        transformedTile.tallWaterLevel = copyObject(tallWaterLevel);
        transformedTile.layerData = copyObject(layerData);
        transformedTile.bitLayerData = copyObject(bitLayerData);
        transformedTile.init();
    }
    if (seeds != null) {
        transformedTile.seeds = new HashSet<>();
        transformedTile.seeds.addAll(seeds);
        for (Seed seed : transformedTile.seeds) {
            seed.transform(transform);
        }
    }
    return transformedTile;
}
Also used : Seed(org.pepsoft.worldpainter.gardenofeden.Seed) Point(java.awt.Point) Layer(org.pepsoft.worldpainter.layers.Layer) Point(java.awt.Point)

Aggregations

Seed (org.pepsoft.worldpainter.gardenofeden.Seed)3 java.awt (java.awt)2 File (java.io.File)2 IOException (java.io.IOException)2 java.util (java.util)2 List (java.util.List)2 Constants (org.pepsoft.minecraft.Constants)2 ProgressReceiver (org.pepsoft.util.ProgressReceiver)2 OperationCancelled (org.pepsoft.util.ProgressReceiver.OperationCancelled)2 Constants (org.pepsoft.worldpainter.Constants)2 Point (java.awt.Point)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 PropertyChangeSupport (java.beans.PropertyChangeSupport)1 FileOutputStream (java.io.FileOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 PrintWriter (java.io.PrintWriter)1 Serializable (java.io.Serializable)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 java.util.concurrent (java.util.concurrent)1