Search in sources :

Example 1 with Fixup

use of org.pepsoft.worldpainter.exporting.Fixup in project WorldPainter by Captain-Chaos.

the class SwampLandExporter method render.

@Override
public List<Fixup> render(Dimension dimension, Rectangle area, Rectangle exportedArea, MinecraftWorld world) {
    List<Fixup> fixups = super.render(dimension, area, exportedArea, world);
    // Render lily pads
    TreeLayerSettings<TreeLayer> settings = (TreeLayerSettings<TreeLayer>) getSettings();
    int minimumLevel = settings.getMinimumLevel();
    int maxZ = dimension.getMaxHeight() - 1;
    for (int chunkX = area.x; chunkX < area.x + area.width; chunkX += 16) {
        for (int chunkY = area.y; chunkY < area.y + area.height; chunkY += 16) {
            // Set the seed and randomizer according to the chunk
            // coordinates to make sure the chunk is always rendered the
            // same, no matter how often it is rendererd
            long seed = dimension.getSeed() + (chunkX >> 4) * 65537 + (chunkY >> 4) * 4099 + layer.hashCode() + 1;
            Random random = new Random(seed);
            for (int x = chunkX; x < chunkX + 16; x++) {
                for (int y = chunkY; y < chunkY + 16; y++) {
                    int terrainLevel = dimension.getIntHeightAt(x, y);
                    if (terrainLevel == -1) {
                        // height == -1 means there is no tile there
                        continue;
                    }
                    int waterLevel = dimension.getWaterLevelAt(x, y);
                    if ((waterLevel > terrainLevel) && (waterLevel < maxZ)) {
                        int strength = Math.max(minimumLevel, dimension.getLayerValueAt(layer, x, y));
                        if ((strength > 0) && (random.nextInt(3840) <= (strength * strength))) {
                            int blockType = world.getBlockTypeAt(x, y, waterLevel);
                            int blockTypeAbove = world.getBlockTypeAt(x, y, waterLevel + 1);
                            if (((blockType == BLK_WATER) || (blockType == BLK_STATIONARY_WATER)) && (blockTypeAbove == BLK_AIR)) {
                                world.setMaterialAt(x, y, waterLevel + 1, Material.LILY_PAD);
                            }
                        }
                    }
                }
            }
        }
    }
    return fixups;
}
Also used : Random(java.util.Random) TreeLayer(org.pepsoft.worldpainter.layers.TreeLayer) Fixup(org.pepsoft.worldpainter.exporting.Fixup)

Example 2 with Fixup

use of org.pepsoft.worldpainter.exporting.Fixup in project WorldPainter by Captain-Chaos.

the class Bo2LayerExporter method render.

@Override
public List<Fixup> render(final Dimension dimension, Rectangle area, Rectangle exportedArea, MinecraftWorld minecraftWorld) {
    final Bo2ObjectProvider objectProvider = layer.getObjectProvider();
    final int maxHeight = dimension.getMaxHeight();
    final int maxZ = maxHeight - 1;
    final List<Fixup> fixups = new ArrayList<>();
    final int density = layer.getDensity() * 64;
    for (int chunkX = area.x; chunkX < area.x + area.width; chunkX += 16) {
        for (int chunkY = area.y; chunkY < area.y + area.height; chunkY += 16) {
            // Set the seed and randomizer according to the chunk
            // coordinates to make sure the chunk is always rendered the
            // same, no matter how often it is rendered
            final long seed = dimension.getSeed() + (chunkX >> 4) * 65537 + (chunkY >> 4) * 4099;
            final Random random = new Random(seed);
            objectProvider.setSeed(seed);
            for (int x = chunkX; x < chunkX + 16; x++) {
                for (int y = chunkY; y < chunkY + 16; y++) {
                    final int height = dimension.getIntHeightAt(x, y);
                    if ((height == -1) || (height >= maxZ)) {
                        // height == -1 means no tile present
                        continue;
                    }
                    final int strength = dimension.getLayerValueAt(layer, x, y);
                    if ((strength > 0) && (random.nextInt(density) <= strength * strength)) {
                        WPObject object = objectProvider.getObject();
                        final Placement placement = getPlacement(minecraftWorld, dimension, x, y, height + 1, object, random);
                        if (placement == Placement.NONE) {
                            continue;
                        }
                        if (object.getAttribute(ATTRIBUTE_RANDOM_ROTATION)) {
                            if (random.nextBoolean()) {
                                object = new MirroredObject(object, false);
                            }
                            int rotateSteps = random.nextInt(4);
                            if (rotateSteps > 0) {
                                object = new RotatedObject(object, rotateSteps);
                            }
                        }
                        final int z = (placement == Placement.ON_LAND) ? height + 1 : dimension.getWaterLevelAt(x, y) + 1;
                        if (!isSane(object, x, y, z, maxHeight)) {
                            continue;
                        }
                        prepareForExport(object, dimension);
                        if (!isRoom(minecraftWorld, dimension, object, x, y, z, placement)) {
                            continue;
                        }
                        if (!fitsInExportedArea(exportedArea, object, x, y)) {
                            // There is room on our side of the border, but
                            // the object extends outside the exported area,
                            // so it might clash with an object from another
                            // area. Schedule a fixup to retest whether
                            // there is room after all the objects have been
                            // placed on both sides of the border
                            fixups.add(new WPObjectFixup(object, x, y, z, placement));
                            continue;
                        }
                        renderObject(minecraftWorld, dimension, object, x, y, z);
                    }
                }
            }
        }
    }
    return fixups;
}
Also used : Random(java.util.Random) WPObject(org.pepsoft.worldpainter.objects.WPObject) ArrayList(java.util.ArrayList) RotatedObject(org.pepsoft.worldpainter.objects.RotatedObject) Fixup(org.pepsoft.worldpainter.exporting.Fixup) MirroredObject(org.pepsoft.worldpainter.objects.MirroredObject)

Aggregations

Random (java.util.Random)2 Fixup (org.pepsoft.worldpainter.exporting.Fixup)2 ArrayList (java.util.ArrayList)1 TreeLayer (org.pepsoft.worldpainter.layers.TreeLayer)1 MirroredObject (org.pepsoft.worldpainter.objects.MirroredObject)1 RotatedObject (org.pepsoft.worldpainter.objects.RotatedObject)1 WPObject (org.pepsoft.worldpainter.objects.WPObject)1