Search in sources :

Example 1 with GardenExporter

use of org.pepsoft.worldpainter.gardenofeden.GardenExporter 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)

Aggregations

java.awt (java.awt)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 java.util (java.util)1 List (java.util.List)1 java.util.concurrent (java.util.concurrent)1 NotNull (org.jetbrains.annotations.NotNull)1 org.pepsoft.minecraft (org.pepsoft.minecraft)1 BLOCKS (org.pepsoft.minecraft.Block.BLOCKS)1 Constants (org.pepsoft.minecraft.Constants)1 Box (org.pepsoft.util.Box)1 ParallelProgressManager (org.pepsoft.util.ParallelProgressManager)1 ProgressReceiver (org.pepsoft.util.ProgressReceiver)1 OperationCancelled (org.pepsoft.util.ProgressReceiver.OperationCancelled)1 SubProgressReceiver (org.pepsoft.util.SubProgressReceiver)1 Constants (org.pepsoft.worldpainter.Constants)1