use of org.pepsoft.worldpainter.Terrain in project WorldPainter by Captain-Chaos.
the class TerrainRangesTableModel method addRow.
public void addRow(int level, Terrain terrain) {
SortedMap<Integer, Terrain> sortedMap = new TreeMap<>();
sortedMap.put(level, terrain);
for (int i = 0; i < rows; i++) {
sortedMap.put(levels[i], terrains[i]);
}
rows++;
if (rows > levels.length) {
levels = new int[rows];
terrains = new Terrain[rows];
}
int i = 0;
for (Map.Entry<Integer, Terrain> row : sortedMap.entrySet()) {
levels[i] = row.getKey();
terrains[i] = row.getValue();
i++;
}
TableModelEvent event = new TableModelEvent(this);
for (TableModelListener listener : listeners) {
listener.tableChanged(event);
}
notifyChangeListener();
}
use of org.pepsoft.worldpainter.Terrain in project WorldPainter by Captain-Chaos.
the class BorderChunkFactory method create.
public static ChunkFactory.ChunkCreationResult create(int chunkX, int chunkZ, Dimension dimension, Map<Layer, LayerExporter> exporters) {
final int maxHeight = dimension.getMaxHeight();
final Platform platform = dimension.getWorld().getPlatform();
final Border border = dimension.getBorder();
final int borderLevel = dimension.getBorderLevel();
final boolean dark = dimension.isDarkLevel();
final boolean bottomless = dimension.isBottomless();
final Terrain subsurfaceMaterial = dimension.getSubsurfaceMaterial();
final PerlinNoise noiseGenerator;
if (noiseGenerators.get() == null) {
noiseGenerator = new PerlinNoise(0);
noiseGenerators.set(noiseGenerator);
} else {
noiseGenerator = noiseGenerators.get();
}
final long seed = dimension.getSeed();
if (noiseGenerator.getSeed() != seed) {
noiseGenerator.setSeed(seed);
}
final int floor = Math.max(borderLevel - 20, 0);
final int variation = Math.min(15, (borderLevel - floor) / 2);
final ChunkFactory.ChunkCreationResult result = new ChunkFactory.ChunkCreationResult();
result.chunk = PlatformManager.getInstance().createChunk(platform, chunkX, chunkZ, maxHeight);
final int maxY = maxHeight - 1;
if (platform.capabilities.contains(BIOMES)) {
switch(border) {
case VOID:
case LAVA:
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
result.chunk.setBiome(x, z, BIOME_PLAINS);
}
}
break;
case WATER:
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
result.chunk.setBiome(x, z, BIOME_OCEAN);
}
}
break;
default:
throw new InternalError();
}
}
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
if (border != Border.VOID) {
final int worldX = (chunkX << 4) | x, worldZ = (chunkZ << 4) | z;
final int floorLevel = (int) (floor + (noiseGenerator.getPerlinNoise(worldX / MEDIUM_BLOBS, worldZ / MEDIUM_BLOBS) + 0.5f) * variation + 0.5f);
final int surfaceLayerLevel = floorLevel - dimension.getTopLayerDepth(worldX, worldZ, floorLevel);
for (int y = 0; y <= maxY; y++) {
if ((y == 0) && (!bottomless)) {
result.chunk.setBlockType(x, y, z, BLK_BEDROCK);
} else if (y <= surfaceLayerLevel) {
result.chunk.setMaterial(x, y, z, subsurfaceMaterial.getMaterial(seed, worldX, worldZ, y, floorLevel));
} else if (y <= floorLevel) {
result.chunk.setMaterial(x, y, z, BEACHES.getMaterial(seed, worldX, worldZ, y, floorLevel));
} else if (y <= borderLevel) {
switch(border) {
case WATER:
result.chunk.setBlockType(x, y, z, BLK_STATIONARY_WATER);
break;
case LAVA:
result.chunk.setBlockType(x, y, z, BLK_STATIONARY_LAVA);
break;
default:
}
}
}
}
if (dark) {
result.chunk.setBlockType(x, maxY, z, BLK_BEDROCK);
result.chunk.setHeight(x, z, maxY);
} else if (border == Border.VOID) {
result.chunk.setHeight(x, z, 0);
} else {
result.chunk.setHeight(x, z, (borderLevel < maxY) ? (borderLevel + 1) : maxY);
}
}
}
if (border != Border.VOID) {
// Apply layers set to be applied everywhere, if any
final Set<Layer> minimumLayers = dimension.getMinimumLayers();
if (!minimumLayers.isEmpty()) {
Tile virtualTile = new Tile(chunkX >> 3, chunkZ >> 3, dimension.getMaxHeight()) {
@Override
public synchronized float getHeight(int x, int y) {
return floor + (noiseGenerator.getPerlinNoise(((getX() << TILE_SIZE_BITS) | x) / MEDIUM_BLOBS, ((getY() << TILE_SIZE_BITS) | y) / MEDIUM_BLOBS) + 0.5f) * variation;
}
@Override
public synchronized int getWaterLevel(int x, int y) {
return borderLevel;
}
private static final long serialVersionUID = 1L;
};
for (Layer layer : minimumLayers) {
LayerExporter layerExporter = exporters.get(layer);
if (layerExporter instanceof FirstPassLayerExporter) {
((FirstPassLayerExporter) layerExporter).render(dimension, virtualTile, result.chunk);
}
}
}
}
result.chunk.setTerrainPopulated(true);
result.stats.surfaceArea = 256;
if ((border == Border.WATER) || (border == Border.LAVA)) {
result.stats.waterArea = 256;
}
return result;
}
use of org.pepsoft.worldpainter.Terrain in project WorldPainter by Captain-Chaos.
the class UndergroundPocketsDialog method ok.
@Override
protected void ok() {
String name = fieldName.getText();
MixedMaterial material = radioButtonCustomMaterial.isSelected() ? mixedMaterialChooser.getMaterial() : null;
if (material != null) {
// Make sure the material is registered, in case it's new
material = MixedMaterialManager.getInstance().register(material);
}
Terrain terrain = radioButtonTerrain.isSelected() ? (Terrain) comboBoxTerrain.getSelectedItem() : null;
int occurrence = (Integer) spinnerOccurrence.getValue();
int scale = (Integer) spinnerScale.getValue();
int minLevel = (Integer) spinnerMinLevel.getValue();
int maxLevel = (Integer) spinnerMaxLevel.getValue();
if (layer == null) {
layer = new UndergroundPocketsLayer(name, material, terrain, occurrence, minLevel, maxLevel, scale, selectedColour);
} else {
layer.setName(name);
layer.setColour(selectedColour);
layer.setMaterial(material);
layer.setTerrain(terrain);
layer.setFrequency(occurrence);
layer.setMinLevel(minLevel);
layer.setMaxLevel(maxLevel);
layer.setScale(scale);
}
super.ok();
}
use of org.pepsoft.worldpainter.Terrain in project WorldPainter by Captain-Chaos.
the class SimpleTheme method apply.
@Override
public void apply(Tile tile, int x, int y) {
int height = tile.getIntHeight(x, y);
Terrain terrain = getTerrain(x, y, clamp(minHeight, height, maxHeight - 1));
// Sanity checks because of NPE's observed in the wild from this method
if (terrain == null) {
throw new NullPointerException("apply(" + tile + ", " + x + ", " + y + ": getTerrain() returned null for " + this);
}
if (tile.getTerrain(x, y) != terrain) {
tile.setTerrain(x, y, terrain);
}
if (layerCache != null) {
for (int i = 0; i < layerCache.length; i++) {
int level = layerLevelCache[i][height - minHeight];
if (level != tile.getLayerValue(layerCache[i], x, y)) {
tile.setLayerValue(layerCache[i], x, y, level);
}
}
}
if (bitLayerCache != null) {
for (int i = 0; i < bitLayerCache.length; i++) {
int level = bitLayerLevelCache[i][height - minHeight];
boolean set = (level > 0) && ((level == 15) || (random.nextInt(15) < level));
if (set != tile.getBitLayerValue(bitLayerCache[i], x, y)) {
tile.setBitLayerValue(bitLayerCache[i], x, y, set);
}
}
}
}
use of org.pepsoft.worldpainter.Terrain in project WorldPainter by Captain-Chaos.
the class SimpleTheme method setTerrainRanges.
public final void setTerrainRanges(SortedMap<Integer, Terrain> terrainRanges) {
// Make sure the ranges actually start from the lowest level
final int lowestLevel = terrainRanges.firstKey();
if (lowestLevel >= minHeight) {
Terrain lowestTerrain = terrainRanges.get(lowestLevel);
terrainRanges.remove(lowestLevel);
terrainRanges.put(minHeight - 1, lowestTerrain);
}
this.terrainRanges = terrainRanges;
for (int i = minHeight; i < maxHeight; i++) {
terrainRangesTable[i - minHeight] = terrainRanges.get(terrainRanges.headMap(i).lastKey());
}
}
Aggregations