Search in sources :

Example 1 with PlatformProvider

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

the class AbstractWorldExporter method firstPass.

protected ExportResults firstPass(MinecraftWorld minecraftWorld, Dimension dimension, Point regionCoords, Map<Point, Tile> tiles, boolean tileSelection, Map<Layer, LayerExporter> exporters, ChunkFactory chunkFactory, boolean ceiling, ProgressReceiver progressReceiver) throws OperationCancelled, IOException {
    if (logger.isDebugEnabled()) {
        logger.debug("Start of first pass for region {},{}", regionCoords.x, regionCoords.y);
    }
    if (progressReceiver != null) {
        if (ceiling) {
            progressReceiver.setMessage("Generating ceiling");
        } else {
            progressReceiver.setMessage("Generating landscape");
        }
    }
    int lowestChunkX = (regionCoords.x << 5) - 1;
    int highestChunkX = (regionCoords.x << 5) + 32;
    int lowestChunkY = (regionCoords.y << 5) - 1;
    int highestChunkY = (regionCoords.y << 5) + 32;
    int lowestRegionChunkX = lowestChunkX + 1;
    int highestRegionChunkX = highestChunkX - 1;
    int lowestRegionChunkY = lowestChunkY + 1;
    int highestRegionChunkY = highestChunkY - 1;
    ExportResults exportResults = new ExportResults();
    int chunkNo = 0;
    int ceilingDelta = dimension.getMaxHeight() - dimension.getCeilingHeight();
    Platform platform = world.getPlatform();
    PlatformProvider platformProvider = PlatformManager.getInstance().getPlatformProvider(platform);
    for (int chunkX = lowestChunkX; chunkX <= highestChunkX; chunkX++) {
        for (int chunkY = lowestChunkY; chunkY <= highestChunkY; chunkY++) {
            ChunkFactory.ChunkCreationResult chunkCreationResult = createChunk(dimension, chunkFactory, tiles, chunkX, chunkY, tileSelection, exporters, ceiling);
            if (chunkCreationResult != null) {
                if ((chunkX >= lowestRegionChunkX) && (chunkX <= highestRegionChunkX) && (chunkY >= lowestRegionChunkY) && (chunkY <= highestRegionChunkY)) {
                    exportResults.chunksGenerated = true;
                    exportResults.stats.landArea += chunkCreationResult.stats.landArea;
                    exportResults.stats.surfaceArea += chunkCreationResult.stats.surfaceArea;
                    exportResults.stats.waterArea += chunkCreationResult.stats.waterArea;
                }
                if (ceiling) {
                    Chunk invertedChunk = new InvertedChunk(chunkCreationResult.chunk, ceilingDelta);
                    Chunk existingChunk = minecraftWorld.getChunkForEditing(chunkX, chunkY);
                    if (existingChunk == null) {
                        existingChunk = platformProvider.createChunk(platform, chunkX, chunkY, world.getMaxHeight());
                        minecraftWorld.addChunk(existingChunk);
                    }
                    mergeChunks(invertedChunk, existingChunk);
                } else {
                    minecraftWorld.addChunk(chunkCreationResult.chunk);
                }
            }
            chunkNo++;
            if (progressReceiver != null) {
                progressReceiver.setProgress((float) chunkNo / 1156);
            }
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("End of first pass for region {},{}", regionCoords.x, regionCoords.y);
    }
    return exportResults;
}
Also used : PlatformProvider(org.pepsoft.worldpainter.plugins.PlatformProvider) Platform(org.pepsoft.worldpainter.Platform)

Aggregations

Platform (org.pepsoft.worldpainter.Platform)1 PlatformProvider (org.pepsoft.worldpainter.plugins.PlatformProvider)1