Search in sources :

Example 6 with Row

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

the class CustomMaterialDialog method getNewMaterial.

private MixedMaterial getNewMaterial() {
    switch(jTabbedPane1.getSelectedIndex()) {
        case 0:
            // Simple
            return new MixedMaterial(fieldName.getText(), new Row(Material.get(comboBoxSimpleBlockID.getSelectedIndex(), (Integer) spinnerSimpleDataValue.getValue()), 1000, 1.0f), biome, checkBoxColour.isSelected() ? selectedColour : null);
        case 1:
            // Complex
            MixedMaterialTableModel tableModelClone = tableModel.clone();
            tableModelClone.normalise();
            Row[] rows = tableModelClone.getRows();
            if (rows.length == 1) {
                return new MixedMaterial(fieldName.getText(), rows[0], biome, checkBoxColour.isSelected() ? selectedColour : null);
            } else if (radioButtonNoise.isSelected()) {
                return new MixedMaterial(fieldName.getText(), rows, biome, checkBoxColour.isSelected() ? selectedColour : null);
            } else if (radioButtonBlobs.isSelected()) {
                return new MixedMaterial(fieldName.getText(), rows, biome, checkBoxColour.isSelected() ? selectedColour : null, ((Integer) spinnerScale.getValue()) / 100.0f);
            } else {
                NoiseSettings variation = noiseSettingsEditorLayeredVariation.getNoiseSettings().clone();
                boolean repeat = checkBoxLayeredRepeat.isSelected();
                return new MixedMaterial(fieldName.getText(), rows, biome, checkBoxColour.isSelected() ? selectedColour : null, (variation.getRange() != 0) ? variation : null, repeat ? Math.tan((-(Integer) spinnerLayeredXAngle.getValue()) / DEGREES_TO_RADIANS) : 0.0, repeat ? Math.tan((-(Integer) spinnerLayeredYAngle.getValue()) / DEGREES_TO_RADIANS) : 0.0, repeat);
            }
        default:
            throw new InternalError();
    }
}
Also used : MixedMaterialTableModel(org.pepsoft.worldpainter.MixedMaterialTableModel) Row(org.pepsoft.worldpainter.MixedMaterial.Row)

Example 7 with Row

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

the class CustomMaterialDialog method createName.

private String createName() {
    switch(jTabbedPane1.getSelectedIndex()) {
        case 0:
            // Simple
            int blockId = comboBoxSimpleBlockID.getSelectedIndex();
            int dataValue = (Integer) spinnerSimpleDataValue.getValue();
            return Material.get(blockId, dataValue).toString();
        case 1:
            // Complex
            Row[] rows = tableModel.getRows();
            rows = Arrays.copyOf(rows, rows.length);
            Arrays.sort(rows, (r1, r2) -> r2.occurrence - r1.occurrence);
            StringBuilder sb = new StringBuilder();
            for (Row row : rows) {
                if (sb.length() > 0) {
                    sb.append('/');
                }
                sb.append(row.material.toString());
            }
            return sb.toString();
        default:
            throw new InternalError();
    }
}
Also used : Row(org.pepsoft.worldpainter.MixedMaterial.Row)

Example 8 with Row

use of org.pepsoft.worldpainter.MixedMaterial.Row 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 Row

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

the class CustomMaterialDialog method saveSettings.

private void saveSettings() {
    switch(jTabbedPane1.getSelectedIndex()) {
        case 0:
            // Simple
            material.edit(fieldName.getText(), new Row[] { new Row(Material.get(comboBoxSimpleBlockID.getSelectedIndex(), (Integer) spinnerSimpleDataValue.getValue()), 1000, 1.0f) }, biome, MixedMaterial.Mode.SIMPLE, 1.0f, checkBoxColour.isSelected() ? selectedColour : null, null, 0.0, 0.0, false);
            break;
        case 1:
            // Complex
            tableModel.normalise();
            Row[] rows = tableModel.getRows();
            if (rows.length == 1) {
                material.edit(fieldName.getText(), rows, biome, MixedMaterial.Mode.SIMPLE, 1.0f, checkBoxColour.isSelected() ? selectedColour : null, null, 0.0, 0.0, false);
            } else if (radioButtonNoise.isSelected()) {
                material.edit(fieldName.getText(), rows, biome, MixedMaterial.Mode.NOISE, 1.0f, checkBoxColour.isSelected() ? selectedColour : null, null, 0.0, 0.0, false);
            } else if (radioButtonBlobs.isSelected()) {
                material.edit(fieldName.getText(), rows, biome, MixedMaterial.Mode.BLOBS, ((Integer) spinnerScale.getValue()) / 100.0f, checkBoxColour.isSelected() ? selectedColour : null, null, 0.0, 0.0, false);
            } else {
                NoiseSettings variation = noiseSettingsEditorLayeredVariation.getNoiseSettings();
                boolean repeat = checkBoxLayeredRepeat.isSelected();
                material.edit(fieldName.getText(), rows, biome, MixedMaterial.Mode.LAYERED, ((Integer) spinnerScale.getValue()) / 100.0f, checkBoxColour.isSelected() ? selectedColour : null, (variation.getRange() != 0) ? variation : null, repeat ? Math.tan((-(Integer) spinnerLayeredXAngle.getValue()) / DEGREES_TO_RADIANS) : 0.0, repeat ? Math.tan((-(Integer) spinnerLayeredYAngle.getValue()) / DEGREES_TO_RADIANS) : 0.0, repeat);
            }
            break;
    }
}
Also used : Row(org.pepsoft.worldpainter.MixedMaterial.Row)

Example 10 with Row

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

the class MixedMaterialTableModel method addMaterial.

public void addMaterial(Row row) {
    rows = Arrays.copyOf(rows, rows.length + 1);
    rows[rows.length - 1] = row;
    if (mode != Mode.LAYERED) {
        int remaining = 1000 - row.occurrence;
        float factor = (float) remaining / 1000;
        for (int i = 0; i < rows.length - 1; i++) {
            if (i < rows.length - 2) {
                int newOccurrence = MathUtils.clamp(1, (int) (rows[i].occurrence * factor + 0.5f), 999);
                rows[i] = new Row(rows[i].material, newOccurrence, rows[i].scale);
                remaining -= newOccurrence;
            } else {
                rows[i] = new Row(rows[i].material, remaining, rows[i].scale);
            }
        }
    }
    TableModelEvent event = new TableModelEvent(this, 0, 0, COLUMN_OCCURRENCE);
    fireEvent(event);
    event = new TableModelEvent(this, rows.length - 1, rows.length - 1, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT);
    fireEvent(event);
}
Also used : TableModelEvent(javax.swing.event.TableModelEvent) Row(org.pepsoft.worldpainter.MixedMaterial.Row)

Aggregations

Row (org.pepsoft.worldpainter.MixedMaterial.Row)11 TableModelEvent (javax.swing.event.TableModelEvent)5 Map (java.util.Map)2 Point (java.awt.Point)1 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1 ResourceBundle (java.util.ResourceBundle)1 TreeMap (java.util.TreeMap)1 JFrame (javax.swing.JFrame)1 Test (org.junit.Test)1 Material (org.pepsoft.minecraft.Material)1 TiledImageViewer (org.pepsoft.util.swing.TiledImageViewer)1 HeightMapTileFactory (org.pepsoft.worldpainter.HeightMapTileFactory)1 MixedMaterial (org.pepsoft.worldpainter.MixedMaterial)1 Mode (org.pepsoft.worldpainter.MixedMaterial.Mode)1 MixedMaterialTableModel (org.pepsoft.worldpainter.MixedMaterialTableModel)1 Tile (org.pepsoft.worldpainter.Tile)1