Search in sources :

Example 16 with Terrain

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

the class FancyPostGenerationTheme method install.

public void install() {
    snowLayer = null;
    for (CustomLayer layer : dimension.getCustomLayers()) {
        if ((layer instanceof GroundCoverLayer) && layer.getName().equals("Mountain Snow")) {
            snowLayer = (GroundCoverLayer) layer;
            break;
        }
    }
    if (snowLayer == null) {
        snowLayer = new GroundCoverLayer("Mountain Snow", MixedMaterial.create("Deep Snow", SNOW_BLOCK), 0xffffff);
        snowLayer.setThickness(5);
        snowLayer.setEdgeWidth(15);
        snowLayer.setEdgeShape(GroundCoverLayer.EdgeShape.SMOOTH);
        dimension.getCustomLayers().add(snowLayer);
    }
    terrainDirtAndGravel = null;
    for (Terrain terrain : Terrain.getConfiguredValues()) {
        if (terrain.getName().equals("Mountain Dirt/Gravel")) {
            terrainDirtAndGravel = terrain;
            break;
        }
    }
    if (terrainDirtAndGravel == null) {
        MixedMaterial material = new MixedMaterial("Mountain Dirt/Gravel", new MixedMaterial.Row[] { new MixedMaterial.Row(Material.DIRT, 750, 1.0f), new MixedMaterial.Row(Material.GRAVEL, 250, 1.0f) }, Minecraft1_2BiomeScheme.BIOME_PLAINS, null, 1.0f);
        for (int i = 0; i < Terrain.CUSTOM_TERRAIN_COUNT; i++) {
            if (!Terrain.isCustomMaterialConfigured(i)) {
                Terrain.setCustomMaterial(i, material);
                terrainDirtAndGravel = Terrain.getCustomTerrain(i);
                break;
            }
        }
        if (terrainDirtAndGravel == null) {
            throw new IllegalStateException("No empty custom terrain slots available");
        }
    }
    terrainStoneAndGravel = null;
    for (Terrain terrain : Terrain.getConfiguredValues()) {
        if (terrain.getName().equals("Mountain Stone/Gravel")) {
            terrainStoneAndGravel = terrain;
            break;
        }
    }
    if (terrainStoneAndGravel == null) {
        MixedMaterial material = new MixedMaterial("Mountain Stone/Gravel", new MixedMaterial.Row[] { new MixedMaterial.Row(Material.STONE, 750, 1.0f), new MixedMaterial.Row(Material.GRAVEL, 250, 1.0f) }, Minecraft1_2BiomeScheme.BIOME_PLAINS, null, 1.0f);
        for (int i = 0; i < Terrain.CUSTOM_TERRAIN_COUNT; i++) {
            if (!Terrain.isCustomMaterialConfigured(i)) {
                Terrain.setCustomMaterial(i, material);
                terrainStoneAndGravel = Terrain.getCustomTerrain(i);
                break;
            }
        }
        if (terrainStoneAndGravel == null) {
            throw new IllegalStateException("No empty custom terrain slots available");
        }
    }
}
Also used : CustomLayer(org.pepsoft.worldpainter.layers.CustomLayer) Terrain(org.pepsoft.worldpainter.Terrain) GroundCoverLayer(org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer) MixedMaterial(org.pepsoft.worldpainter.MixedMaterial)

Example 17 with Terrain

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

the class App method removeCustomMaterial.

private void removeCustomMaterial(int index) {
    Terrain customTerrain = Terrain.getCustomTerrain(index);
    MixedMaterial mixedMaterial = getCustomMaterial(index);
    String name = mixedMaterial.getName();
    Set<Terrain> allTerrains = ProgressDialog.executeTask(this, "Checking whether terrain is in use", () -> Arrays.stream(world.getDimensions()).parallel().flatMap(dim -> dim.getAllTerrains().parallelStream()).collect(toSet()), NOT_CANCELABLE);
    if (allTerrains.contains(customTerrain)) {
        Toolkit.getDefaultToolkit().beep();
        JOptionPane.showMessageDialog(this, "Custom terrain \"" + name + "\" is still in use.\nUse the Global Operations tool to replace it.", "Terrain In Use", ERROR_MESSAGE);
        return;
    }
    if (JOptionPane.showConfirmDialog(this, "Are you sure you want to delete custom terrain \"" + name + "\"?\nThis operation cannot be undone.", "Confirm Deletion", YES_NO_OPTION) == YES_OPTION) {
        // Clear all the undo managers, because we don't know which of them may have a version in their history
        // which is still using the terrain
        undoManagers.values().forEach(UndoManager::clear);
        MixedMaterialManager.getInstance().clear(mixedMaterial);
        setCustomMaterial(index, null);
        if (customMaterialButtons[index].isSelected()) {
            deselectPaint();
        }
        customTerrainPanel.remove(customMaterialButtons[index]);
        customTerrainPanel.validate();
        JOptionPane.showMessageDialog(this, "Custom terrain \"" + name + "\" was successfully deleted.", "Custom Terrain Deleted", INFORMATION_MESSAGE);
    }
}
Also used : UndoManager(org.pepsoft.util.undo.UndoManager) Terrain(org.pepsoft.worldpainter.Terrain)

Example 18 with Terrain

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

the class App method updateStatusBar.

public void updateStatusBar(int x, int y) {
    setTextIfDifferent(locationLabel, MessageFormat.format(strings.getString("location.0.1"), x, y));
    if (dimension == null) {
        setTextIfDifferent(heightLabel, " ");
        setTextIfDifferent(waterLabel, " ");
        setTextIfDifferent(materialLabel, " ");
        setTextIfDifferent(biomeLabel, " ");
        return;
    }
    Tile tile = dimension.getTile(x >> TILE_SIZE_BITS, y >> TILE_SIZE_BITS);
    if (tile == null) {
        // Not on a tile
        setTextIfDifferent(heightLabel, " ");
        setTextIfDifferent(slopeLabel, " ");
        setTextIfDifferent(waterLabel, " ");
        if (dimension.isBorderTile(x >> TILE_SIZE_BITS, y >> TILE_SIZE_BITS)) {
            setTextIfDifferent(materialLabel, "Border");
        } else {
            setTextIfDifferent(materialLabel, "Minecraft Generated");
        }
        setTextIfDifferent(biomeLabel, " ");
        return;
    }
    final int xInTile = x & TILE_SIZE_MASK, yInTile = y & TILE_SIZE_MASK;
    if (tile.getBitLayerValue(NotPresent.INSTANCE, xInTile, yInTile)) {
        // Marked as not present
        setTextIfDifferent(heightLabel, " ");
        setTextIfDifferent(slopeLabel, " ");
        setTextIfDifferent(waterLabel, " ");
        setTextIfDifferent(materialLabel, "Minecraft Generated");
        setTextIfDifferent(biomeLabel, " ");
        return;
    }
    int height = tile.getIntHeight(xInTile, yInTile);
    setTextIfDifferent(heightLabel, MessageFormat.format(strings.getString("height.0.of.1"), height, dimension.getMaxHeight() - 1));
    setTextIfDifferent(slopeLabel, MessageFormat.format("Slope: {0}°", (int) Math.round(Math.atan(dimension.getSlope(x, y)) * 180 / Math.PI)));
    if ((activeOperation instanceof PaintOperation) && (paint instanceof LayerPaint)) {
        Layer layer = ((LayerPaint) paint).getLayer();
        switch(layer.getDataSize()) {
            case BIT:
            case BIT_PER_CHUNK:
                setTextIfDifferent(waterLabel, MessageFormat.format(strings.getString("layer.0.on.off"), layer.getName(), (tile.getBitLayerValue(layer, xInTile, yInTile) ? 1 : 0)));
                break;
            case NIBBLE:
                int value, strength;
                if (!layer.equals(Annotations.INSTANCE)) {
                    value = tile.getLayerValue(layer, xInTile, yInTile);
                    strength = (value > 0) ? ((value - 1) * 100 / 14 + 1) : 0;
                    if ((strength == 51) || (strength == 101)) {
                        strength--;
                    }
                    setTextIfDifferent(waterLabel, MessageFormat.format(strings.getString("layer.0.level.1"), layer.getName(), strength));
                } else {
                    setTextIfDifferent(waterLabel, " ");
                }
                break;
            case BYTE:
                if (!layer.equals(Biome.INSTANCE)) {
                    value = tile.getLayerValue(layer, xInTile, yInTile);
                    strength = (value > 0) ? ((value - 1) * 100 / 254 + 1) : 0;
                    setTextIfDifferent(waterLabel, MessageFormat.format(strings.getString("layer.0.level.1"), layer.getName(), strength));
                } else {
                    setTextIfDifferent(waterLabel, " ");
                }
                break;
            default:
                // Do nothing
                break;
        }
    } else if (activeOperation instanceof GardenOfEdenOperation) {
        setTextIfDifferent(waterLabel, strings.getString("structure") + ": " + GardenCategory.getLabel(strings, tile.getLayerValue(GardenCategory.INSTANCE, xInTile, yInTile)));
    } else {
        int waterLevel = tile.getWaterLevel(xInTile, yInTile);
        if (waterLevel > height) {
            setTextIfDifferent(waterLabel, MessageFormat.format(strings.getString("fluid.level.1.depth.2"), tile.getBitLayerValue(FloodWithLava.INSTANCE, xInTile, yInTile) ? 1 : 0, waterLevel, waterLevel - height));
        } else {
            setTextIfDifferent(waterLabel, " ");
        }
    }
    Terrain terrain = tile.getTerrain(xInTile, yInTile);
    if (terrain.isCustom()) {
        int index = terrain.getCustomTerrainIndex();
        setTextIfDifferent(materialLabel, MessageFormat.format(strings.getString("material.custom.1.0"), getCustomMaterial(index), index + 1));
    } else {
        setTextIfDifferent(materialLabel, MessageFormat.format(strings.getString("material.0"), terrain.getName()));
    }
    // TODO: apparently this was sometimes invoked at or soon after startup,
    // with biomeNames being null, causing a NPE. How is this possible?
    int biome = tile.getLayerValue(Biome.INSTANCE, xInTile, yInTile);
    // TODO: is this too slow?
    if (biome == 255) {
        biome = dimension.getAutoBiome(x, y);
        if (biome != -1) {
            setTextIfDifferent(biomeLabel, "Auto biome: " + biomeHelper.getBiomeName(biome));
        }
    } else if (biome != -1) {
        setTextIfDifferent(biomeLabel, MessageFormat.format(strings.getString("biome.0"), biomeHelper.getBiomeName(biome)));
    }
}
Also used : Terrain(org.pepsoft.worldpainter.Terrain) GardenOfEdenOperation(org.pepsoft.worldpainter.gardenofeden.GardenOfEdenOperation) TunnelLayer(org.pepsoft.worldpainter.layers.tunnel.TunnelLayer) UndergroundPocketsLayer(org.pepsoft.worldpainter.layers.pockets.UndergroundPocketsLayer) GroundCoverLayer(org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer) PlantLayer(org.pepsoft.worldpainter.layers.plants.PlantLayer) Paint(org.pepsoft.worldpainter.painting.Paint)

Example 19 with Terrain

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

the class CombinedLayerPaint method applyPixel.

@Override
public void applyPixel(Dimension dimension, int x, int y) {
    final Tile tile = dimension.getTileForEditing(x >> TILE_SIZE_BITS, y >> TILE_SIZE_BITS);
    if (tile != null) {
        final int xInTile = x & TILE_SIZE_MASK, yInTile = y & TILE_SIZE_MASK;
        final int value = 1 + Math.round(brush.getLevel() * 14);
        if (tile.getLayerValue(layer, xInTile, yInTile) < value) {
            tile.setLayerValue(layer, xInTile, yInTile, value);
        }
        final Terrain terrain = ((CombinedLayer) layer).getTerrain();
        if (terrain != null) {
            tile.setTerrain(xInTile, yInTile, terrain);
        }
        final int biome = ((CombinedLayer) layer).getBiome();
        if (biome != -1) {
            tile.setLayerValue(Biome.INSTANCE, xInTile, yInTile, biome);
        }
    }
}
Also used : CombinedLayer(org.pepsoft.worldpainter.layers.CombinedLayer) Terrain(org.pepsoft.worldpainter.Terrain) Tile(org.pepsoft.worldpainter.Tile)

Aggregations

Terrain (org.pepsoft.worldpainter.Terrain)19 MixedMaterial (org.pepsoft.worldpainter.MixedMaterial)4 Tile (org.pepsoft.worldpainter.Tile)4 Layer (org.pepsoft.worldpainter.layers.Layer)4 GroundCoverLayer (org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer)4 PlantLayer (org.pepsoft.worldpainter.layers.plants.PlantLayer)3 UndergroundPocketsLayer (org.pepsoft.worldpainter.layers.pockets.UndergroundPocketsLayer)3 TunnelLayer (org.pepsoft.worldpainter.layers.tunnel.TunnelLayer)3 Map (java.util.Map)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 TableModelEvent (javax.swing.event.TableModelEvent)2 TableModelListener (javax.swing.event.TableModelListener)2 ChunkFactory (org.pepsoft.minecraft.ChunkFactory)2 PerlinNoise (org.pepsoft.util.PerlinNoise)2 UndoManager (org.pepsoft.util.undo.UndoManager)2 Border (org.pepsoft.worldpainter.Dimension.Border)2 CombinedLayer (org.pepsoft.worldpainter.layers.CombinedLayer)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 GZIPInputStream (java.util.zip.GZIPInputStream)1