Search in sources :

Example 6 with MixedMaterial

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

the class TunnelLayerDialog method saveSettingsTo.

private void saveSettingsTo(TunnelLayer layer, boolean registerMaterials) {
    layer.setFloorLevel((Integer) spinnerFloorLevel.getValue());
    layer.setFloorMin((Integer) spinnerFloorMin.getValue());
    layer.setFloorMax((Integer) spinnerFloorMax.getValue());
    MixedMaterial floorMaterial = mixedMaterialSelectorFloor.getMaterial();
    if ((floorMaterial != null) && registerMaterials) {
        // Make sure the material is registered, in case it's new
        floorMaterial = MixedMaterialManager.getInstance().register(floorMaterial);
    }
    layer.setFloorMaterial(floorMaterial);
    if (radioButtonFloorFixedDepth.isSelected()) {
        layer.setFloorMode(Mode.CONSTANT_DEPTH);
    } else if (radioButtonFloorFixedLevel.isSelected()) {
        layer.setFloorMode(Mode.FIXED_HEIGHT);
    } else {
        layer.setFloorMode(Mode.INVERTED_DEPTH);
    }
    NoiseSettings floorNoiseSettings = noiseSettingsEditorFloor.getNoiseSettings();
    if (floorNoiseSettings.getRange() == 0) {
        layer.setFloorNoise(null);
    } else {
        layer.setFloorNoise(floorNoiseSettings);
    }
    layer.setRoofLevel((Integer) spinnerRoofLevel.getValue());
    layer.setRoofMin((Integer) spinnerRoofMin.getValue());
    layer.setRoofMax((Integer) spinnerRoofMax.getValue());
    MixedMaterial roofMaterial = mixedMaterialSelectorRoof.getMaterial();
    if ((roofMaterial != null) && registerMaterials) {
        // Make sure the material is registered, in case it's new
        roofMaterial = MixedMaterialManager.getInstance().register(roofMaterial);
    }
    layer.setRoofMaterial(roofMaterial);
    if (radioButtonRoofFixedDepth.isSelected()) {
        layer.setRoofMode(Mode.CONSTANT_DEPTH);
    } else if (radioButtonRoofFixedLevel.isSelected()) {
        layer.setRoofMode(Mode.FIXED_HEIGHT);
    } else {
        layer.setRoofMode(Mode.INVERTED_DEPTH);
    }
    NoiseSettings roofNoiseSettings = noiseSettingsEditorRoof.getNoiseSettings();
    if (roofNoiseSettings.getRange() == 0) {
        layer.setRoofNoise(null);
    } else {
        layer.setRoofNoise(roofNoiseSettings);
    }
    layer.setFloorWallDepth((Integer) spinnerWallFloorDepth.getValue());
    layer.setRoofWallDepth((Integer) spinnerWallRoofDepth.getValue());
    MixedMaterial wallMaterial = mixedMaterialSelectorWall.getMaterial();
    if ((wallMaterial != null) && registerMaterials) {
        // Make sure the material is registered, in case it's new
        wallMaterial = MixedMaterialManager.getInstance().register(wallMaterial);
    }
    layer.setWallMaterial(wallMaterial);
    layer.setName(textFieldName.getText().trim());
    layer.setColour(colourEditor1.getColour());
    layer.setRemoveWater(checkBoxRemoveWater.isSelected());
    layer.setFloodLevel(checkBoxFlood.isSelected() ? (Integer) spinnerFloodLevel.getValue() : 0);
    layer.setFloodWithLava(checkBoxFloodWithLava.isSelected());
    Map<Layer, TunnelLayer.LayerSettings> floorLayers = floorLayersTableModel.getLayers();
    layer.setFloorLayers(((floorLayers != null) && (!floorLayers.isEmpty())) ? floorLayers : null);
}
Also used : NoiseSettings(org.pepsoft.worldpainter.NoiseSettings) Bo2Layer(org.pepsoft.worldpainter.layers.Bo2Layer) CustomLayer(org.pepsoft.worldpainter.layers.CustomLayer) PlantLayer(org.pepsoft.worldpainter.layers.plants.PlantLayer) Layer(org.pepsoft.worldpainter.layers.Layer) GroundCoverLayer(org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer) MixedMaterial(org.pepsoft.worldpainter.MixedMaterial)

Example 7 with MixedMaterial

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

the class CustomItemsTreeModel method getSelectedItems.

public List<Object> getSelectedItems(TreePath[] selectedTreePaths) {
    ArrayList<Object> selectedItems = new ArrayList<>();
    for (TreePath selectedPath : selectedTreePaths) {
        Object object = selectedPath.getLastPathComponent();
        if (object == ROOT) {
            selectedItems.addAll(customTerrains);
            selectedItems.addAll(customLayers);
            selectedItems.addAll(customBiomes);
        } else if (object == TERRAINS) {
            selectedItems.addAll(customTerrains);
        } else if (object == LAYERS) {
            selectedItems.addAll(customLayers);
        } else if (object == BIOMES) {
            selectedItems.addAll(customBiomes);
        } else if ((object instanceof CustomLayer) || (object instanceof MixedMaterial) || (object instanceof CustomBiome)) {
            selectedItems.add(object);
        } else {
            throw new InternalError("Unknown node type " + object.getClass() + " (\"" + object + "\") encountered");
        }
    }
    return selectedItems;
}
Also used : CustomLayer(org.pepsoft.worldpainter.layers.CustomLayer) TreePath(javax.swing.tree.TreePath) CustomBiome(org.pepsoft.worldpainter.biomeschemes.CustomBiome) ArrayList(java.util.ArrayList) MixedMaterial(org.pepsoft.worldpainter.MixedMaterial)

Example 8 with MixedMaterial

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

the class TileFactoryPreviewer method main.

public static void main(String[] args) {
    final long seed;
    if (args.length > 0) {
        seed = Long.parseLong(args[0]);
    } else {
        seed = new Random().nextLong();
    }
    // final ExperimentalTileFactory tileFactory = new ExperimentalTileFactory(DEFAULT_MAX_HEIGHT_2);
    // final HeightMapTileFactory tileFactory = TileFactoryFactory.createNoiseTileFactory(Terrain.GRASS, World2.DEFAULT_MAX_HEIGHT, 58, 62, false, true, 20.0f, 1.0);
    // HeightMap oceanFloor = new ConstantHeightMap(40f);
    // HeightMap continent;
    // //        continent = new NinePatchHeightMap(200, 100, 50, 58f);
    // continent = new NinePatchHeightMap(0, 1000, 50, 22f);
    // HeightMap hills = new ProductHeightMap(
    // new NoiseHeightMap(1.0f, 10f, 1),
    // new SumHeightMap(
    // new NoiseHeightMap(20.0f, 1.0f, 2),
    // new ConstantHeightMap(-5f)));
    // continent = new SumHeightMap(
    // new SumHeightMap(
    // oceanFloor,
    // continent),
    // hills);
    // HeightMap mountainsLimit = new NinePatchHeightMap(0, 1000, 200, 1f);
    // HeightMap mountains = new ProductHeightMap(
    // new ProductHeightMap(
    // new NoiseHeightMap(1.0f, 10f, 1),
    // mountainsLimit),
    // new NoiseHeightMap(256f, 5f, 4));
    // HeightMap heightMap = new MaximisingHeightMap(continent, mountains);
    // final HeightMapTileFactory tileFactory = new HeightMapTileFactory(seed, heightMap, 256, false, new FancyTheme(256, 62, heightMap));
    final HeightMapTileFactory tileFactory = TileFactoryFactory.createFancyTileFactory(seed, Terrain.GRASS, Constants.DEFAULT_MAX_HEIGHT_2, 62, 58, false, 20f, 1.0);
    // SortedMap<Integer, Terrain> terrainRanges = tileFactory.getTerrainRanges();
    // terrainRanges.clear();
    // terrainRanges.put( -1, Terrain.DIRT);
    // terrainRanges.put( 64, Terrain.GRASS);
    // terrainRanges.put(128, Terrain.ROCK);
    // terrainRanges.put(192, Terrain.DEEP_SNOW);
    // tileFactory.setTerrainRanges(terrainRanges);
    final org.pepsoft.worldpainter.TileProvider tileProvider = new org.pepsoft.worldpainter.TileProvider() {

        @Override
        public Rectangle getExtent() {
            // Tile factories are endless
            return null;
        }

        @Override
        public boolean isTilePresent(int x, int y) {
            // Tile factories are endless and have no holes
            return true;
        }

        @Override
        public Tile getTile(int x, int y) {
            Point coords = new Point(x, y);
            synchronized (cache) {
                Tile tile = cache.get(coords);
                if (tile == null) {
                    tile = tileFactory.createTile(x, y);
                    cache.put(coords, tile);
                }
                return tile;
            }
        }

        private final Map<Point, Tile> cache = new HashMap<>();
    };
    Terrain.setCustomMaterial(0, new MixedMaterial("Dirt/Gravel", new Row[] { new Row(Material.DIRT, 750, 1.0f), new Row(Material.GRAVEL, 250, 1.0f) }, Minecraft1_2BiomeScheme.BIOME_PLAINS, null, 1.0f));
    Terrain.setCustomMaterial(1, new MixedMaterial("Stone/Gravel", new Row[] { new Row(Material.STONE, 750, 1.0f), new Row(Material.GRAVEL, 250, 1.0f) }, Minecraft1_2BiomeScheme.BIOME_PLAINS, null, 1.0f));
    TiledImageViewer viewer = new TiledImageViewer();
    JFrame frame = new JFrame("TileFactory Previewer");
    viewer.setTileProvider(new WPTileProvider(tileProvider, new DynMapColourScheme("default", true), new AutoBiomeScheme(null), null, Collections.singleton((Layer) Biome.INSTANCE), true, 10, TileRenderer.LightOrigin.NORTHWEST, false, null));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(viewer, BorderLayout.CENTER);
    frame.setSize(1000, 800);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
Also used : AutoBiomeScheme(org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme) TiledImageViewer(org.pepsoft.util.swing.TiledImageViewer) Tile(org.pepsoft.worldpainter.Tile) Point(java.awt.Point) DynMapColourScheme(org.pepsoft.worldpainter.colourschemes.DynMapColourScheme) WPTileProvider(org.pepsoft.worldpainter.WPTileProvider) Random(java.util.Random) JFrame(javax.swing.JFrame) HeightMapTileFactory(org.pepsoft.worldpainter.HeightMapTileFactory) Row(org.pepsoft.worldpainter.MixedMaterial.Row) WPTileProvider(org.pepsoft.worldpainter.WPTileProvider) HashMap(java.util.HashMap) Map(java.util.Map) MixedMaterial(org.pepsoft.worldpainter.MixedMaterial)

Example 9 with MixedMaterial

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

the class GroundCoverLayerExporter method apply.

@Override
public Fixup apply(Dimension dimension, Point3i location, int intensity, Rectangle exportedArea, MinecraftWorld minecraftWorld) {
    if (intensity > 0) {
        final int blockBelow = minecraftWorld.getBlockTypeAt(location.x, location.y, location.z - 1);
        if ((blockBelow != BLK_AIR) && (!Block.BLOCKS[blockBelow].insubstantial)) {
            final int thickness = layer.getThickness();
            final MixedMaterial mixedMaterial = layer.getMaterial();
            final long seed = dimension.getSeed();
            int effectiveThickness = Math.abs(thickness);
            if (noiseHeightMap != null) {
                noiseHeightMap.setSeed(seed);
                effectiveThickness += noiseHeightMap.getHeight(location.x, location.y) - noiseOffset;
            }
            if (thickness > 0) {
                final int maxZ = dimension.getMaxHeight() - 1;
                for (int dz = 0; dz < effectiveThickness; dz++) {
                    final int z = location.z + dz;
                    if (z > maxZ) {
                        break;
                    }
                    final int existingBlockType = minecraftWorld.getBlockTypeAt(location.x, location.y, z);
                    final Material material = mixedMaterial.getMaterial(seed, location.x, location.y, z);
                    if ((material != Material.AIR) && ((!material.block.veryInsubstantial) || (existingBlockType == BLK_AIR) || Block.BLOCKS[existingBlockType].insubstantial)) {
                        minecraftWorld.setMaterialAt(location.x, location.y, z, material);
                    }
                }
            } else {
                final int minZ = dimension.isBottomless() ? 0 : 1;
                for (int dz = 0; dz < effectiveThickness; dz++) {
                    final int z = location.z - 1 - dz;
                    if (z < minZ) {
                        break;
                    }
                    int existingBlockType = minecraftWorld.getBlockTypeAt(location.x, location.y, z);
                    if (existingBlockType != BLK_AIR) {
                        minecraftWorld.setMaterialAt(location.x, location.y, z, mixedMaterial.getMaterial(seed, location.x, location.y, z));
                    }
                }
            }
        }
    }
    return null;
}
Also used : Material(org.pepsoft.minecraft.Material) MixedMaterial(org.pepsoft.worldpainter.MixedMaterial) MixedMaterial(org.pepsoft.worldpainter.MixedMaterial)

Example 10 with MixedMaterial

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

the class TunnelLayerExporter method render.

@Override
public List<Fixup> render(Dimension dimension, Rectangle area, Rectangle exportedArea, MinecraftWorld world) {
    final TunnelLayer.Mode floorMode = layer.getFloorMode(), roofMode = layer.getRoofMode();
    final int floorWallDepth = layer.getFloorWallDepth(), roofWallDepth = layer.getRoofWallDepth(), floorLevel = layer.getFloorLevel(), roofLevel = layer.getRoofLevel(), maxWallDepth = Math.max(floorWallDepth, roofWallDepth) + 1, floorMin = layer.getFloorMin(), floorMax = layer.getFloorMax(), roofMin = layer.getRoofMin(), roofMax = layer.getRoofMax(), floodLevel = layer.getFloodLevel();
    final int minZ = dimension.isBottomless() ? 0 : 1, maxZ = dimension.getMaxHeight() - 1;
    final boolean removeWater = layer.isRemoveWater(), floodWithLava = layer.isFloodWithLava();
    final MixedMaterial floorMaterial = layer.getFloorMaterial(), wallMaterial = layer.getWallMaterial(), roofMaterial = layer.getRoofMaterial();
    if (floorNoise != null) {
        floorNoise.setSeed(dimension.getSeed());
    }
    if (roofNoise != null) {
        roofNoise.setSeed(dimension.getSeed());
    }
    if ((floorMaterial == null) && (wallMaterial == null) && (roofMaterial == null)) {
        // One pass: just remove blocks
        for (int x = area.x; x < area.x + area.width; x++) {
            for (int y = area.y; y < area.y + area.height; y++) {
                if (dimension.getBitLayerValueAt(layer, x, y)) {
                    final int terrainHeight = dimension.getIntHeightAt(x, y);
                    int actualFloorLevel = calculateLevel(floorMode, floorLevel, terrainHeight, floorMin, floorMax, minZ, maxZ, (floorNoise != null) ? ((int) floorNoise.getHeight(x, y) - floorNoiseOffset) : 0);
                    int actualRoofLevel = calculateLevel(roofMode, roofLevel, terrainHeight, roofMin, roofMax, minZ, maxZ, (roofNoise != null) ? ((int) roofNoise.getHeight(x, y) - roofNoiseOffset) : 0);
                    if (actualRoofLevel <= actualFloorLevel) {
                        continue;
                    }
                    final float distanceToWall = dimension.getDistanceToEdge(layer, x, y, maxWallDepth) - 1;
                    final int floorLedgeHeight = calculateLedgeHeight(floorWallDepth, distanceToWall);
                    final int roofLedgeHeight = calculateLedgeHeight(roofWallDepth, distanceToWall);
                    actualFloorLevel += floorLedgeHeight;
                    actualRoofLevel -= roofLedgeHeight;
                    if (actualRoofLevel <= actualFloorLevel) {
                        continue;
                    }
                    final int waterLevel = dimension.getWaterLevelAt(x, y);
                    for (int z = Math.min(removeWater ? Math.max(terrainHeight, waterLevel) : terrainHeight, actualRoofLevel); z > actualFloorLevel; z--) {
                        if (removeWater || (z <= terrainHeight) || (z > waterLevel)) {
                            if (z <= floodLevel) {
                                world.setMaterialAt(x, y, z, floodWithLava ? Material.LAVA : Material.WATER);
                            } else {
                                world.setMaterialAt(x, y, z, Material.AIR);
                            }
                        }
                    }
                    if (actualFloorLevel == 0) {
                        // probably what the user wants
                        if ((floodLevel > 0) && (0 <= floodLevel)) {
                            world.setMaterialAt(x, y, 0, floodWithLava ? Material.STATIONARY_LAVA : Material.STATIONARY_WATER);
                        } else {
                            world.setMaterialAt(x, y, 0, Material.AIR);
                        }
                    }
                }
            }
        }
    } else {
        // excavate the interior
        for (int x = area.x; x < area.x + area.width; x++) {
            for (int y = area.y; y < area.y + area.height; y++) {
                if (dimension.getBitLayerValueAt(layer, x, y)) {
                    int terrainHeight = dimension.getIntHeightAt(x, y);
                    int actualFloorLevel = calculateLevel(floorMode, floorLevel, terrainHeight, floorMin, floorMax, minZ, maxZ, (floorNoise != null) ? ((int) floorNoise.getHeight(x, y) - floorNoiseOffset) : 0);
                    int actualRoofLevel = calculateLevel(roofMode, roofLevel, terrainHeight, roofMin, roofMax, minZ, maxZ, (roofNoise != null) ? ((int) roofNoise.getHeight(x, y) - roofNoiseOffset) : 0);
                    if (actualRoofLevel <= actualFloorLevel) {
                        continue;
                    }
                    final float distanceToWall = dimension.getDistanceToEdge(layer, x, y, maxWallDepth) - 1;
                    final int floorLedgeHeight = calculateLedgeHeight(floorWallDepth, distanceToWall);
                    final int roofLedgeHeight = calculateLedgeHeight(roofWallDepth, distanceToWall);
                    actualFloorLevel += floorLedgeHeight;
                    actualRoofLevel -= roofLedgeHeight;
                    if (actualRoofLevel <= actualFloorLevel) {
                        continue;
                    }
                    int waterLevel = dimension.getWaterLevelAt(x, y);
                    boolean flooded = waterLevel > terrainHeight;
                    final int startZ = Math.min(removeWater ? Math.max(terrainHeight, waterLevel) : terrainHeight, actualRoofLevel);
                    for (int z = startZ; z > actualFloorLevel; z--) {
                        if ((floorLedgeHeight == 0) && (floorMaterial != null)) {
                            setIfSolid(world, x, y, z - 1, minZ, maxZ, floorMaterial, flooded, terrainHeight, waterLevel, removeWater);
                        }
                        if (wallMaterial != null) {
                            if (floorLedgeHeight > 0) {
                                setIfSolid(world, x, y, z - 1, minZ, maxZ, wallMaterial, flooded, terrainHeight, waterLevel, removeWater);
                            }
                            if (roofLedgeHeight > 0) {
                                setIfSolid(world, x, y, z + 1, minZ, maxZ, wallMaterial, flooded, terrainHeight, waterLevel, removeWater);
                            }
                        }
                        if ((roofLedgeHeight == 0) && (roofMaterial != null)) {
                            setIfSolid(world, x, y, z + 1, minZ, maxZ, roofMaterial, flooded, terrainHeight, waterLevel, removeWater);
                        }
                    }
                    if (wallMaterial != null) {
                        terrainHeight = dimension.getIntHeightAt(x - 1, y);
                        waterLevel = dimension.getWaterLevelAt(x - 1, y);
                        flooded = waterLevel > terrainHeight;
                        for (int z = startZ; z > actualFloorLevel; z--) {
                            setIfSolid(world, x - 1, y, z, minZ, maxZ, wallMaterial, flooded, terrainHeight, waterLevel, removeWater);
                        }
                        terrainHeight = dimension.getIntHeightAt(x, y - 1);
                        waterLevel = dimension.getWaterLevelAt(x, y - 1);
                        flooded = waterLevel > terrainHeight;
                        for (int z = startZ; z > actualFloorLevel; z--) {
                            setIfSolid(world, x, y - 1, z, minZ, maxZ, wallMaterial, flooded, terrainHeight, waterLevel, removeWater);
                        }
                        terrainHeight = dimension.getIntHeightAt(x + 1, y);
                        waterLevel = dimension.getWaterLevelAt(x + 1, y);
                        flooded = waterLevel > terrainHeight;
                        for (int z = startZ; z > actualFloorLevel; z--) {
                            setIfSolid(world, x + 1, y, z, minZ, maxZ, wallMaterial, flooded, terrainHeight, waterLevel, removeWater);
                        }
                        terrainHeight = dimension.getIntHeightAt(x, y + 1);
                        waterLevel = dimension.getWaterLevelAt(x, y + 1);
                        flooded = waterLevel > terrainHeight;
                        for (int z = startZ; z > actualFloorLevel; z--) {
                            setIfSolid(world, x, y + 1, z, minZ, maxZ, wallMaterial, flooded, terrainHeight, waterLevel, removeWater);
                        }
                    }
                }
            }
        }
        // Second pass: excavate interior
        for (int x = area.x; x < area.x + area.width; x++) {
            for (int y = area.y; y < area.y + area.height; y++) {
                if (dimension.getBitLayerValueAt(layer, x, y)) {
                    final int terrainHeight = dimension.getIntHeightAt(x, y);
                    int actualFloorLevel = calculateLevel(floorMode, floorLevel, terrainHeight, floorMin, floorMax, minZ, maxZ, (floorNoise != null) ? ((int) floorNoise.getHeight(x, y) - floorNoiseOffset) : 0);
                    int actualRoofLevel = calculateLevel(roofMode, roofLevel, terrainHeight, roofMin, roofMax, minZ, maxZ, (roofNoise != null) ? ((int) roofNoise.getHeight(x, y) - roofNoiseOffset) : 0);
                    if (actualRoofLevel <= actualFloorLevel) {
                        continue;
                    }
                    final float distanceToWall = dimension.getDistanceToEdge(layer, x, y, maxWallDepth) - 1;
                    final int floorLedgeHeight = calculateLedgeHeight(floorWallDepth, distanceToWall);
                    final int roofLedgeHeight = calculateLedgeHeight(roofWallDepth, distanceToWall);
                    actualFloorLevel += floorLedgeHeight;
                    actualRoofLevel -= roofLedgeHeight;
                    if (actualRoofLevel <= actualFloorLevel) {
                        continue;
                    }
                    final int waterLevel = dimension.getWaterLevelAt(x, y);
                    for (int z = actualRoofLevel; z > actualFloorLevel; z--) {
                        if (removeWater || (z <= terrainHeight) || (z > waterLevel)) {
                            if (z <= floodLevel) {
                                world.setMaterialAt(x, y, z, floodWithLava ? Material.LAVA : Material.WATER);
                            } else {
                                world.setMaterialAt(x, y, z, Material.AIR);
                            }
                        }
                    }
                    if (actualFloorLevel == 0) {
                        // probably what the user wants
                        if ((floodLevel > 0) && (0 <= floodLevel)) {
                            world.setMaterialAt(x, y, 0, floodWithLava ? Material.LAVA : Material.WATER);
                        } else {
                            world.setMaterialAt(x, y, 0, Material.AIR);
                        }
                    }
                }
            }
        }
    }
    // Second/third pass: render floor layers
    List<Fixup> fixups = new ArrayList<>();
    final Map<Layer, TunnelLayer.LayerSettings> floorLayers = layer.getFloorLayers();
    if ((floorLayers != null) && (!floorLayers.isEmpty())) {
        final IncidentalLayerExporter[] floorExporters = new IncidentalLayerExporter[floorLayers.size()];
        final TunnelLayer.LayerSettings[] floorLayerSettings = new TunnelLayer.LayerSettings[floorLayers.size()];
        final NoiseHeightMap[] floorLayerNoise = new NoiseHeightMap[floorLayers.size()];
        int index = 0;
        for (Layer floorLayer : floorLayers.keySet()) {
            floorExporters[index] = (IncidentalLayerExporter) floorLayer.getExporter();
            TunnelLayer.LayerSettings layerSettings = floorLayers.get(floorLayer);
            floorLayerSettings[index] = layerSettings;
            if (layerSettings.getVariation() != null) {
                floorLayerNoise[index] = new NoiseHeightMap(layerSettings.getVariation(), index);
                floorLayerNoise[index].setSeed(dimension.getSeed());
            }
            index++;
        }
        final TunnelFloorDimension floorDimension = new TunnelFloorDimension(dimension, layer);
        for (int x = area.x; x < area.x + area.width; x++) {
            for (int y = area.y; y < area.y + area.height; y++) {
                if (dimension.getBitLayerValueAt(layer, x, y)) {
                    final int terrainHeight = dimension.getIntHeightAt(x, y);
                    int actualFloorLevel = calculateLevel(floorMode, floorLevel, terrainHeight, floorMin, floorMax, minZ, maxZ, (floorNoise != null) ? ((int) floorNoise.getHeight(x, y) - floorNoiseOffset) : 0);
                    int actualRoofLevel = calculateLevel(roofMode, roofLevel, terrainHeight, roofMin, roofMax, minZ, maxZ, (roofNoise != null) ? ((int) roofNoise.getHeight(x, y) - roofNoiseOffset) : 0);
                    if (actualRoofLevel <= actualFloorLevel) {
                        continue;
                    }
                    final float distanceToWall = dimension.getDistanceToEdge(layer, x, y, maxWallDepth) - 1;
                    final int floorLedgeHeight = calculateLedgeHeight(floorWallDepth, distanceToWall);
                    final int roofLedgeHeight = calculateLedgeHeight(roofWallDepth, distanceToWall);
                    actualFloorLevel += floorLedgeHeight;
                    actualRoofLevel -= roofLedgeHeight;
                    if ((actualRoofLevel <= actualFloorLevel) || (actualFloorLevel == 0)) {
                        continue;
                    }
                    final int z = actualFloorLevel + 1;
                    final Point3i location = new Point3i(x, y, z);
                    for (int i = 0; i < floorExporters.length; i++) {
                        if ((z >= floorLayerSettings[i].getMinLevel()) && (z <= floorLayerSettings[i].getMaxLevel())) {
                            final int intensity = floorLayerNoise[i] != null ? MathUtils.clamp(0, (int) (floorLayerSettings[i].getIntensity() + floorLayerNoise[i].getValue(x, y, z) + 0.5f), 100) : floorLayerSettings[i].getIntensity();
                            if (intensity > 0) {
                                Fixup fixup = floorExporters[i].apply(floorDimension, location, intensity, exportedArea, world);
                                if (fixup != null) {
                                    fixups.add(fixup);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return fixups.isEmpty() ? null : fixups;
}
Also used : ArrayList(java.util.ArrayList) Layer(org.pepsoft.worldpainter.layers.Layer) Point3i(javax.vecmath.Point3i) NoiseHeightMap(org.pepsoft.worldpainter.heightMaps.NoiseHeightMap) MixedMaterial(org.pepsoft.worldpainter.MixedMaterial)

Aggregations

MixedMaterial (org.pepsoft.worldpainter.MixedMaterial)13 Terrain (org.pepsoft.worldpainter.Terrain)3 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Material (org.pepsoft.minecraft.Material)2 CustomLayer (org.pepsoft.worldpainter.layers.CustomLayer)2 Layer (org.pepsoft.worldpainter.layers.Layer)2 Point (java.awt.Point)1 FileInputStream (java.io.FileInputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Random (java.util.Random)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 JFrame (javax.swing.JFrame)1 TreePath (javax.swing.tree.TreePath)1 Point3i (javax.vecmath.Point3i)1 ProgressReceiver (org.pepsoft.util.ProgressReceiver)1 TiledImageViewer (org.pepsoft.util.swing.TiledImageViewer)1