Search in sources :

Example 1 with TILE_SIZE

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

the class FillDialog method clearLayer.

private void clearLayer(ProgressReceiver progressReceiver) throws OperationCancelled {
    Layer layer = (Layer) comboBoxClearLayer.getSelectedItem();
    if (filter == null) {
        dimension.clearLayerData(layer);
    } else {
        if (layer.getDataSize() == Layer.DataSize.NIBBLE) {
            dimension.visitTiles().forFilter(filter).andDo(tile -> {
                final int worldTileX = tile.getX() << TILE_SIZE_BITS;
                final int worldTileY = tile.getY() << TILE_SIZE_BITS;
                for (int x = 0; x < TILE_SIZE; x++) {
                    for (int y = 0; y < TILE_SIZE; y++) {
                        int oldLayervalue = tile.getLayerValue(layer, x, y);
                        int layerValue;
                        if (filter == null) {
                            layerValue = 0;
                        } else {
                            layerValue = Math.min(oldLayervalue, 15 - (int) (filter.modifyStrength(worldTileX | x, worldTileY | y, 1.0f) * 15));
                        }
                        if (oldLayervalue != layerValue) {
                            tile.setLayerValue(layer, x, y, layerValue);
                        }
                    }
                }
            }, progressReceiver);
        } else if (layer.getDataSize() == Layer.DataSize.BIT) {
            dimension.visitTiles().forFilter(filter).andDo(tile -> {
                final int worldTileX = tile.getX() << TILE_SIZE_BITS;
                final int worldTileY = tile.getY() << TILE_SIZE_BITS;
                for (int x = 0; x < TILE_SIZE; x++) {
                    for (int y = 0; y < TILE_SIZE; y++) {
                        boolean set;
                        if (filter == null) {
                            set = true;
                        } else {
                            float strength = filter.modifyStrength(worldTileX | x, worldTileY | y, 1.0f);
                            set = (strength > 0.95f) || (Math.random() < strength);
                        }
                        if (set && tile.getBitLayerValue(layer, x, y)) {
                            tile.setBitLayerValue(layer, x, y, false);
                        }
                    }
                }
            }, progressReceiver);
        } else if (layer.getDataSize() == Layer.DataSize.BIT_PER_CHUNK) {
            dimension.visitTiles().forFilter(filter).andDo(tile -> {
                final int worldTileX = tile.getX() << TILE_SIZE_BITS;
                final int worldTileY = tile.getY() << TILE_SIZE_BITS;
                for (int x = 0; x < TILE_SIZE; x += 16) {
                    for (int y = 0; y < TILE_SIZE; y += 16) {
                        boolean set;
                        if (filter == null) {
                            set = true;
                        } else {
                            float strength = filter.modifyStrength(worldTileX | x, worldTileY | y, 1.0f);
                            set = (strength > 0.95f) || (Math.random() < strength);
                        }
                        if (set && tile.getBitLayerValue(layer, x, y)) {
                            tile.setBitLayerValue(layer, x, y, false);
                        }
                    }
                }
            }, progressReceiver);
        } else {
            throw new UnsupportedOperationException();
        }
    }
}
Also used : CustomBiomeManager(org.pepsoft.worldpainter.biomeschemes.CustomBiomeManager) BiomeHelper(org.pepsoft.worldpainter.biomeschemes.BiomeHelper) Arrays(java.util.Arrays) AutoBiomeScheme(org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme) Collection(java.util.Collection) Biome(org.pepsoft.worldpainter.layers.Biome) ProgressDialog(org.pepsoft.util.swing.ProgressDialog) Listener(org.pepsoft.worldpainter.panels.BrushOptions.Listener) Set(java.util.Set) DefaultFilter(org.pepsoft.worldpainter.panels.DefaultFilter) TILE_SIZE(org.pepsoft.worldpainter.Constants.TILE_SIZE) Layer(org.pepsoft.worldpainter.layers.Layer) TerrainListCellRenderer(org.pepsoft.worldpainter.themes.TerrainListCellRenderer) ProgressTask(org.pepsoft.util.swing.ProgressTask) FloodWithLava(org.pepsoft.worldpainter.layers.FloodWithLava) ObservableBoolean(org.pepsoft.util.ObservableBoolean) ProgressReceiver(org.pepsoft.util.ProgressReceiver) SelectionBlock(org.pepsoft.worldpainter.selection.SelectionBlock) OperationCancelled(org.pepsoft.util.ProgressReceiver.OperationCancelled) SelectionChunk(org.pepsoft.worldpainter.selection.SelectionChunk) SelectionHelper(org.pepsoft.worldpainter.selection.SelectionHelper) TILE_SIZE_BITS(org.pepsoft.worldpainter.Constants.TILE_SIZE_BITS) Filter(org.pepsoft.worldpainter.operations.Filter) javax.swing(javax.swing) Layer(org.pepsoft.worldpainter.layers.Layer)

Example 2 with TILE_SIZE

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

the class World2 method readObject.

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();
    propertyChangeSupport = new PropertyChangeSupport(this);
    // Legacy maps
    if (wpVersion < 1) {
        if (maxheight == 0) {
            maxheight = 128;
        }
        if (generator == null) {
            generator = Generator.DEFAULT;
            if ((generatorName != null) && generatorName.equals("FLAT")) {
                generator = Generator.FLAT;
            } else {
                TileFactory tileFactory = dimensions.containsKey(0) ? dimensions.get(0).getTileFactory() : null;
                if (tileFactory instanceof HeightMapTileFactory) {
                    if (((HeightMapTileFactory) tileFactory).getWaterHeight() < 32) {
                        // Low level
                        generator = Generator.FLAT;
                    }
                }
            }
        }
        if (biomeAlgorithm == BIOME_ALGORITHM_CUSTOM_BIOMES) {
            customBiomes = true;
        }
        if (upIs == null) {
            upIs = Direction.WEST;
            askToRotate = true;
        }
        if ((!allowMerging) && (biomeAlgorithm != BIOME_ALGORITHM_NONE)) {
            customBiomes = false;
        }
        if (mixedMaterials == null) {
            mixedMaterials = new MixedMaterial[Terrain.CUSTOM_TERRAIN_COUNT];
            if (customMaterials != null) {
                for (int i = 0; i < customMaterials.length; i++) {
                    if (customMaterials[i] != null) {
                        mixedMaterials[i] = MixedMaterial.create(customMaterials[i]);
                    }
                }
                customMaterials = null;
            }
        }
        Dimension dim = dimensions.get(DIM_NORMAL);
        if (dim != null) {
            // Migrate to refactored automatic biomes
            if (biomeAlgorithm == BIOME_ALGORITHM_AUTO_BIOMES) {
                // Automatic biomes was enabled; biome information should
                // be present throughout; no need to do anything. Schedule a
                // warning to warn the user about the change though
                warnings = EnumSet.of(Warning.AUTO_BIOMES_DISABLED);
            } else if (customBiomes) {
                // Custom biomes was enabled; a mix of initialised and
                // uninitialised tiles may be present which would be
                // problematic, as the initialised tiles would have been
                // initialised to zero and the default is now 255. Check what
                // the situation is and take appropriate steps
                boolean tilesWithBiomesFound = false, tilesWithoutBiomesFound = false;
                for (Tile tile : dim.getTiles()) {
                    if (tile.hasLayer(Biome.INSTANCE)) {
                        tilesWithBiomesFound = true;
                    } else {
                        tilesWithoutBiomesFound = true;
                    }
                }
                if (tilesWithBiomesFound) {
                    if (tilesWithoutBiomesFound) {
                        // behaviour
                        for (Tile tile : dim.getTiles()) {
                            if (!tile.hasLayer(Biome.INSTANCE)) {
                                for (int x = 0; x < TILE_SIZE; x++) {
                                    for (int y = 0; y < TILE_SIZE; y++) {
                                        tile.setLayerValue(Biome.INSTANCE, x, y, 0);
                                    }
                                }
                            }
                        }
                    } else {
                    // There are only initialised tiles. Good, we can leave
                    // it like that, and don't have to warn the user, as the
                    // behaviour will not change
                    }
                } else if (tilesWithoutBiomesFound) {
                    // There are only uninitialised tiles. Leave it like that,
                    // but warn the user that automatic biomes is now active
                    warnings = EnumSet.of(Warning.AUTO_BIOMES_ENABLED);
                }
            } else {
                // Neither custom nor automatic biomes was enabled; all
                // tiles *should* be uninitialised, but clear the layer data
                // anyway just to make sure. Schedule a warning to warn the user
                // that automatic biomes are now active
                dim.clearLayerData(Biome.INSTANCE);
                warnings = EnumSet.of(Warning.AUTO_BIOMES_ENABLED);
            }
        }
    }
    if (wpVersion < 2) {
        if (gameType == 3) {
            difficulty = org.pepsoft.minecraft.Constants.DIFFICULTY_HARD;
        } else {
            difficulty = org.pepsoft.minecraft.Constants.DIFFICULTY_NORMAL;
        }
    }
    if (wpVersion < 3) {
        history = new ArrayList<>();
        history.add(new HistoryEntry(HistoryEntry.WORLD_LEGACY_PRE_2_0_0));
    }
    if (wpVersion < 4) {
        borderSettings = new BorderSettings();
    }
    if (wpVersion < 5) {
        if (tilesToExport != null) {
            dimensionsToExport = Collections.singleton(dimensionToExport);
        } else {
            dimensionsToExport = null;
        }
        dimensionToExport = -1;
    }
    if (wpVersion < 6) {
        switch(version) {
            case org.pepsoft.minecraft.Constants.SUPPORTED_VERSION_1:
                platform = DefaultPlugin.JAVA_MCREGION;
                break;
            case org.pepsoft.minecraft.Constants.SUPPORTED_VERSION_2:
                platform = DefaultPlugin.JAVA_ANVIL;
                break;
            default:
                platform = (maxheight == org.pepsoft.minecraft.Constants.DEFAULT_MAX_HEIGHT_2) ? DefaultPlugin.JAVA_ANVIL : DefaultPlugin.JAVA_MCREGION;
        }
        version = -1;
        gameTypeObj = GameType.values()[gameType];
        gameType = -1;
    }
    wpVersion = CURRENT_WP_VERSION;
    // Bug fix: fix the maxHeight of the dimensions, which somehow is not
    // always correctly set (possibly only on imported worlds from
    // non-standard height maps due to a bug which should be fixed).
    dimensions.values().stream().filter(dimension -> dimension.getMaxHeight() != maxheight).forEach(dimension -> {
        logger.warn("Fixing maxHeight of dimension " + dimension.getDim() + " (was " + dimension.getMaxHeight() + ", should be " + maxheight + ")");
        dimension.setMaxHeight(maxheight);
        dimension.setDirty(false);
    });
    // worlds for it
    if (mixedMaterials.length != Terrain.CUSTOM_TERRAIN_COUNT) {
        mixedMaterials = Arrays.copyOf(mixedMaterials, Terrain.CUSTOM_TERRAIN_COUNT);
    }
}
Also used : java.util(java.util) Biome(org.pepsoft.worldpainter.layers.Biome) ObjectInputStream(java.io.ObjectInputStream) IOException(java.io.IOException) HistoryEntry(org.pepsoft.worldpainter.history.HistoryEntry) TILE_SIZE(org.pepsoft.worldpainter.Constants.TILE_SIZE) SubProgressReceiver(org.pepsoft.util.SubProgressReceiver) File(java.io.File) Layer(org.pepsoft.worldpainter.layers.Layer) Serializable(java.io.Serializable) Direction(org.pepsoft.minecraft.Direction) java.awt(java.awt) UndoManager(org.pepsoft.util.undo.UndoManager) List(java.util.List) PropertyChangeListener(java.beans.PropertyChangeListener) ProgressReceiver(org.pepsoft.util.ProgressReceiver) Material(org.pepsoft.minecraft.Material) AttributeKey(org.pepsoft.util.AttributeKey) MemoryUtils(org.pepsoft.util.MemoryUtils) PropertyChangeSupport(java.beans.PropertyChangeSupport) DIM_NORMAL(org.pepsoft.worldpainter.Constants.DIM_NORMAL) PropertyChangeSupport(java.beans.PropertyChangeSupport) HistoryEntry(org.pepsoft.worldpainter.history.HistoryEntry)

Example 3 with TILE_SIZE

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

the class FillDialog method fillWithLayer.

private void fillWithLayer(ProgressReceiver progressReceiver) throws UnsupportedOperationException, OperationCancelled {
    Layer layer = (Layer) comboBoxSetLayer.getSelectedItem();
    if (layer.getDataSize() == Layer.DataSize.NIBBLE) {
        int baseLayerValue = Math.round((sliderLayerValue.getValue() + 2) / 6.667f);
        dimension.visitTiles().forFilter(filter).andDo(tile -> {
            final int worldTileX = tile.getX() << TILE_SIZE_BITS;
            final int worldTileY = tile.getY() << TILE_SIZE_BITS;
            for (int x = 0; x < TILE_SIZE; x++) {
                for (int y = 0; y < TILE_SIZE; y++) {
                    int layerValue;
                    if (filter == null) {
                        layerValue = baseLayerValue;
                    } else {
                        layerValue = (int) (filter.modifyStrength(worldTileX | x, worldTileY | y, 1.0f) * baseLayerValue);
                    }
                    if (tile.getLayerValue(layer, x, y) < layerValue) {
                        tile.setLayerValue(layer, x, y, layerValue);
                    }
                }
            }
        }, progressReceiver);
    } else if (layer.getDataSize() == Layer.DataSize.BIT) {
        dimension.visitTiles().forFilter(filter).andDo(tile -> {
            final int worldTileX = tile.getX() << TILE_SIZE_BITS;
            final int worldTileY = tile.getY() << TILE_SIZE_BITS;
            for (int x = 0; x < TILE_SIZE; x++) {
                for (int y = 0; y < TILE_SIZE; y++) {
                    boolean set;
                    if (filter == null) {
                        set = true;
                    } else {
                        float strength = filter.modifyStrength(worldTileX | x, worldTileY | y, 1.0f);
                        set = (strength > 0.95f) || (Math.random() < strength);
                    }
                    if (set && (!tile.getBitLayerValue(layer, x, y))) {
                        tile.setBitLayerValue(layer, x, y, true);
                    }
                }
            }
        }, progressReceiver);
    } else if (layer.getDataSize() == Layer.DataSize.BIT_PER_CHUNK) {
        dimension.visitTiles().forFilter(filter).andDo(tile -> {
            final int worldTileX = tile.getX() << TILE_SIZE_BITS;
            final int worldTileY = tile.getY() << TILE_SIZE_BITS;
            for (int x = 0; x < TILE_SIZE; x += 16) {
                for (int y = 0; y < TILE_SIZE; y += 16) {
                    boolean set;
                    if (filter == null) {
                        set = true;
                    } else {
                        float strength = filter.modifyStrength(worldTileX | x, worldTileY | y, 1.0f);
                        set = (strength > 0.95f) || (Math.random() < strength);
                    }
                    if (set && (!tile.getBitLayerValue(layer, x, y))) {
                        tile.setBitLayerValue(layer, x, y, true);
                    }
                }
            }
        }, progressReceiver);
    } else {
        throw new UnsupportedOperationException();
    }
}
Also used : CustomBiomeManager(org.pepsoft.worldpainter.biomeschemes.CustomBiomeManager) BiomeHelper(org.pepsoft.worldpainter.biomeschemes.BiomeHelper) Arrays(java.util.Arrays) AutoBiomeScheme(org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme) Collection(java.util.Collection) Biome(org.pepsoft.worldpainter.layers.Biome) ProgressDialog(org.pepsoft.util.swing.ProgressDialog) Listener(org.pepsoft.worldpainter.panels.BrushOptions.Listener) Set(java.util.Set) DefaultFilter(org.pepsoft.worldpainter.panels.DefaultFilter) TILE_SIZE(org.pepsoft.worldpainter.Constants.TILE_SIZE) Layer(org.pepsoft.worldpainter.layers.Layer) TerrainListCellRenderer(org.pepsoft.worldpainter.themes.TerrainListCellRenderer) ProgressTask(org.pepsoft.util.swing.ProgressTask) FloodWithLava(org.pepsoft.worldpainter.layers.FloodWithLava) ObservableBoolean(org.pepsoft.util.ObservableBoolean) ProgressReceiver(org.pepsoft.util.ProgressReceiver) SelectionBlock(org.pepsoft.worldpainter.selection.SelectionBlock) OperationCancelled(org.pepsoft.util.ProgressReceiver.OperationCancelled) SelectionChunk(org.pepsoft.worldpainter.selection.SelectionChunk) SelectionHelper(org.pepsoft.worldpainter.selection.SelectionHelper) TILE_SIZE_BITS(org.pepsoft.worldpainter.Constants.TILE_SIZE_BITS) Filter(org.pepsoft.worldpainter.operations.Filter) javax.swing(javax.swing) Layer(org.pepsoft.worldpainter.layers.Layer)

Example 4 with TILE_SIZE

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

the class FillDialog method invertLayer.

private void invertLayer(ProgressReceiver progressReceiver) throws UnsupportedOperationException, OperationCancelled {
    Layer layer = (Layer) comboBoxInvertLayer.getSelectedItem();
    if (layer.getDataSize() == Layer.DataSize.NIBBLE) {
        dimension.visitTiles().forFilter(filter).andDo(tile -> {
            final int worldTileX = tile.getX() << TILE_SIZE_BITS;
            final int worldTileY = tile.getY() << TILE_SIZE_BITS;
            for (int x = 0; x < TILE_SIZE; x++) {
                for (int y = 0; y < TILE_SIZE; y++) {
                    boolean set;
                    if (filter == null) {
                        set = true;
                    } else {
                        float strength = filter.modifyStrength(worldTileX | x, worldTileY | y, 1.0f);
                        set = (strength > 0.95f) || (Math.random() < strength);
                    }
                    if (set) {
                        tile.setLayerValue(layer, x, y, 15 - tile.getLayerValue(layer, x, y));
                    }
                }
            }
        }, progressReceiver);
    } else if (layer.getDataSize() == Layer.DataSize.BIT) {
        dimension.visitTiles().forFilter(filter).andDo(tile -> {
            final int worldTileX = tile.getX() << TILE_SIZE_BITS;
            final int worldTileY = tile.getY() << TILE_SIZE_BITS;
            for (int x = 0; x < TILE_SIZE; x++) {
                for (int y = 0; y < TILE_SIZE; y++) {
                    boolean set;
                    if (filter == null) {
                        set = true;
                    } else {
                        float strength = filter.modifyStrength(worldTileX | x, worldTileY | y, 1.0f);
                        set = (strength > 0.95f) || (Math.random() < strength);
                    }
                    if (set) {
                        tile.setBitLayerValue(layer, x, y, !tile.getBitLayerValue(layer, x, y));
                    }
                }
            }
        }, progressReceiver);
    } else if (layer.getDataSize() == Layer.DataSize.BIT_PER_CHUNK) {
        dimension.visitTiles().forFilter(filter).andDo(tile -> {
            final int worldTileX = tile.getX() << TILE_SIZE_BITS;
            final int worldTileY = tile.getY() << TILE_SIZE_BITS;
            for (int x = 0; x < TILE_SIZE; x += 16) {
                for (int y = 0; y < TILE_SIZE; y += 16) {
                    boolean set;
                    if (filter == null) {
                        set = true;
                    } else {
                        float strength = filter.modifyStrength(worldTileX | x, worldTileY | y, 1.0f);
                        set = (strength > 0.95f) || (Math.random() < strength);
                    }
                    if (set) {
                        tile.setBitLayerValue(layer, x, y, !tile.getBitLayerValue(layer, x, y));
                    }
                }
            }
        }, progressReceiver);
    } else {
        throw new UnsupportedOperationException();
    }
}
Also used : CustomBiomeManager(org.pepsoft.worldpainter.biomeschemes.CustomBiomeManager) BiomeHelper(org.pepsoft.worldpainter.biomeschemes.BiomeHelper) Arrays(java.util.Arrays) AutoBiomeScheme(org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme) Collection(java.util.Collection) Biome(org.pepsoft.worldpainter.layers.Biome) ProgressDialog(org.pepsoft.util.swing.ProgressDialog) Listener(org.pepsoft.worldpainter.panels.BrushOptions.Listener) Set(java.util.Set) DefaultFilter(org.pepsoft.worldpainter.panels.DefaultFilter) TILE_SIZE(org.pepsoft.worldpainter.Constants.TILE_SIZE) Layer(org.pepsoft.worldpainter.layers.Layer) TerrainListCellRenderer(org.pepsoft.worldpainter.themes.TerrainListCellRenderer) ProgressTask(org.pepsoft.util.swing.ProgressTask) FloodWithLava(org.pepsoft.worldpainter.layers.FloodWithLava) ObservableBoolean(org.pepsoft.util.ObservableBoolean) ProgressReceiver(org.pepsoft.util.ProgressReceiver) SelectionBlock(org.pepsoft.worldpainter.selection.SelectionBlock) OperationCancelled(org.pepsoft.util.ProgressReceiver.OperationCancelled) SelectionChunk(org.pepsoft.worldpainter.selection.SelectionChunk) SelectionHelper(org.pepsoft.worldpainter.selection.SelectionHelper) TILE_SIZE_BITS(org.pepsoft.worldpainter.Constants.TILE_SIZE_BITS) Filter(org.pepsoft.worldpainter.operations.Filter) javax.swing(javax.swing) Layer(org.pepsoft.worldpainter.layers.Layer)

Aggregations

ProgressReceiver (org.pepsoft.util.ProgressReceiver)4 TILE_SIZE (org.pepsoft.worldpainter.Constants.TILE_SIZE)4 Biome (org.pepsoft.worldpainter.layers.Biome)4 Layer (org.pepsoft.worldpainter.layers.Layer)4 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 Set (java.util.Set)3 javax.swing (javax.swing)3 ObservableBoolean (org.pepsoft.util.ObservableBoolean)3 OperationCancelled (org.pepsoft.util.ProgressReceiver.OperationCancelled)3 ProgressDialog (org.pepsoft.util.swing.ProgressDialog)3 ProgressTask (org.pepsoft.util.swing.ProgressTask)3 TILE_SIZE_BITS (org.pepsoft.worldpainter.Constants.TILE_SIZE_BITS)3 AutoBiomeScheme (org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme)3 BiomeHelper (org.pepsoft.worldpainter.biomeschemes.BiomeHelper)3 CustomBiomeManager (org.pepsoft.worldpainter.biomeschemes.CustomBiomeManager)3 FloodWithLava (org.pepsoft.worldpainter.layers.FloodWithLava)3 Filter (org.pepsoft.worldpainter.operations.Filter)3 Listener (org.pepsoft.worldpainter.panels.BrushOptions.Listener)3 DefaultFilter (org.pepsoft.worldpainter.panels.DefaultFilter)3