use of org.pepsoft.worldpainter.gardenofeden.Seed in project WorldPainter by Captain-Chaos.
the class AbstractWorldExporter method secondPass.
protected List<Fixup> secondPass(List<Layer> secondaryPassLayers, Dimension dimension, MinecraftWorld minecraftWorld, Map<Layer, LayerExporter> exporters, Collection<Tile> tiles, Point regionCoords, ProgressReceiver progressReceiver) throws OperationCancelled {
// Apply other secondary pass layers
if (logger.isDebugEnabled()) {
logger.debug("Start of second pass for region {},{}", regionCoords.x, regionCoords.y);
}
int layerCount = secondaryPassLayers.size(), counter = 0;
Rectangle area = new Rectangle((regionCoords.x << 9) - 16, (regionCoords.y << 9) - 16, 544, 544);
Rectangle exportedArea = new Rectangle((regionCoords.x << 9), (regionCoords.y << 9), 512, 512);
List<Fixup> fixups = new ArrayList<>();
// boolean frost = false;
for (Layer layer : secondaryPassLayers) {
// if (layer instanceof Frost) {
// frost = true;
// continue;
// }
@SuppressWarnings("unchecked") SecondPassLayerExporter exporter = (SecondPassLayerExporter) exporters.get(layer);
if (logger.isDebugEnabled()) {
logger.debug("Exporting layer {} for region {},{}", layer, regionCoords.x, regionCoords.y);
}
if (progressReceiver != null) {
if (minecraftWorld instanceof InvertedWorld) {
progressReceiver.setMessage("Exporting layer " + layer + " for ceiling");
} else {
progressReceiver.setMessage("Exporting layer " + layer);
}
}
List<Fixup> layerFixups = exporter.render(dimension, area, exportedArea, minecraftWorld);
if (layerFixups != null) {
fixups.addAll(layerFixups);
}
if (progressReceiver != null) {
counter++;
progressReceiver.setProgress((float) counter / layerCount);
}
}
// Garden / seeds first and second pass
GardenExporter gardenExporter = new GardenExporter();
Set<Seed> firstPassProcessedSeeds = new HashSet<>();
Set<Seed> secondPassProcessedSeeds = new HashSet<>();
tiles.stream().filter(tile -> tile.getLayers().contains(GardenCategory.INSTANCE)).forEach(tile -> {
gardenExporter.firstPass(dimension, tile, minecraftWorld, firstPassProcessedSeeds);
gardenExporter.secondPass(dimension, tile, minecraftWorld, secondPassProcessedSeeds);
});
// elegant
if ((dimension.getDim() == 0) && world.isCreateGoodiesChest()) {
Point goodiesPoint = (Point) world.getSpawnPoint().clone();
goodiesPoint.translate(3, 3);
int height = Math.min(dimension.getIntHeightAt(goodiesPoint) + 1, dimension.getMaxHeight() - 1);
minecraftWorld.setMaterialAt(goodiesPoint.x, goodiesPoint.y, height, Material.CHEST_NORTH);
Chunk chunk = minecraftWorld.getChunk(goodiesPoint.x >> 4, goodiesPoint.y >> 4);
if ((chunk != null) && (chunk.getTileEntities() != null)) {
Chest goodiesChest = createGoodiesChest();
goodiesChest.setX(goodiesPoint.x);
goodiesChest.setY(height);
goodiesChest.setZ(goodiesPoint.y);
chunk.getTileEntities().add(goodiesChest);
}
}
if (logger.isDebugEnabled()) {
logger.debug("End of second pass for region {},{}", regionCoords.x, regionCoords.y);
}
return fixups;
}
use of org.pepsoft.worldpainter.gardenofeden.Seed in project WorldPainter by Captain-Chaos.
the class Dimension method init.
private void init() {
listeners = new ArrayList<>();
dirtyTiles = new HashSet<>();
addedTiles = new HashSet<>();
removedTiles = new HashSet<>();
propertyChangeSupport = new PropertyChangeSupport(this);
garden = new WPGarden();
topLayerDepthNoise = new PerlinNoise(seed + TOP_LAYER_DEPTH_SEED_OFFSET);
for (Tile tile : tiles.values()) {
tile.addListener(this);
Set<Seed> seeds = tile.getSeeds();
if (seeds != null) {
for (Seed gardenSeed : seeds) {
gardenSeed.garden = garden;
}
}
}
// Legacy support
if (wpVersion < 1) {
if (borderSize == 0) {
borderSize = 2;
}
if (overlayScale == 0.0f) {
overlayScale = 1.0f;
}
if (overlayTransparency == 0.0f) {
overlayTransparency = 0.5f;
}
if (gridSize == 0) {
gridSize = 128;
}
if (!biomesConverted) {
// Convert the nibble sized biomes data from a legacy map (by
// deleting it so that it will be recalculated
tiles.values().forEach(org.pepsoft.worldpainter.Tile::convertBiomeData);
biomesConverted = true;
}
if (maxHeight == 0) {
maxHeight = 128;
}
if (subsurfaceMaterial == Terrain.RESOURCES) {
subsurfaceMaterial = Terrain.STONE;
// Load legacy settings
ResourcesExporterSettings settings = new ResourcesExporterSettings(maxHeight);
settings.setChance(BLK_GOLD_ORE, 1);
settings.setChance(BLK_IRON_ORE, 5);
settings.setChance(BLK_COAL, 9);
settings.setChance(BLK_LAPIS_LAZULI_ORE, 1);
settings.setChance(BLK_DIAMOND_ORE, 1);
settings.setChance(BLK_REDSTONE_ORE, 6);
settings.setChance(BLK_WATER, 1);
settings.setChance(BLK_LAVA, 1);
settings.setChance(BLK_DIRT, 9);
settings.setChance(BLK_GRAVEL, 9);
settings.setMaxLevel(BLK_GOLD_ORE, Terrain.GOLD_LEVEL);
settings.setMaxLevel(BLK_IRON_ORE, Terrain.IRON_LEVEL);
settings.setMaxLevel(BLK_COAL, Terrain.COAL_LEVEL);
settings.setMaxLevel(BLK_LAPIS_LAZULI_ORE, Terrain.LAPIS_LAZULI_LEVEL);
settings.setMaxLevel(BLK_DIAMOND_ORE, Terrain.DIAMOND_LEVEL);
settings.setMaxLevel(BLK_REDSTONE_ORE, Terrain.REDSTONE_LEVEL);
settings.setMaxLevel(BLK_WATER, Terrain.WATER_LEVEL);
settings.setMaxLevel(BLK_LAVA, Terrain.LAVA_LEVEL);
settings.setMaxLevel(BLK_DIRT, Terrain.DIRT_LEVEL);
settings.setMaxLevel(BLK_GRAVEL, Terrain.GRAVEL_LEVEL);
layerSettings.put(Resources.INSTANCE, settings);
}
if (contourSeparation == 0) {
contourSeparation = 10;
}
if (topLayerMinDepth == 0) {
topLayerMinDepth = 3;
topLayerVariation = 4;
}
if (lastViewPosition == null) {
lastViewPosition = new Point();
}
if ((customLayers == null) || customLayers.isEmpty()) {
// The customLayers.isEmpty() is to fix a bug which escaped in a beta
customLayers = new ArrayList<>();
customLayers.addAll(getAllLayers(false).stream().filter(layer -> layer instanceof CustomLayer).map(layer -> (CustomLayer) layer).collect(Collectors.toList()));
}
}
if (wpVersion < 2) {
if (overlay != null) {
fixOverlayCoords = true;
}
}
if (wpVersion < 3) {
ceilingHeight = maxHeight;
}
wpVersion = CURRENT_WP_VERSION;
// Make sure that any custom layers which somehow ended up in the world
// are on the custom layer list so they will be added to a palette in
// the GUI. TODO: fix this properly
// Make sure customLayers isn't some weird read-only list
getAllLayers(false).stream().filter(layer -> (layer instanceof CustomLayer) && (!customLayers.contains(layer))).forEach(layer -> {
if ((!(customLayers instanceof ArrayList)) && (!(customLayers instanceof LinkedList))) {
// Make sure customLayers isn't some weird read-only list
customLayers = new ArrayList<>(customLayers);
}
customLayers.add((CustomLayer) layer);
});
}
use of org.pepsoft.worldpainter.gardenofeden.Seed in project WorldPainter by Captain-Chaos.
the class Tile method transform.
/**
* Create a new tile based on this one but horizontally transformed according to some transformation.
*
* @param transform The transform to apply.
* @return A new tile with the same contents, except transformed according to the specified transform (including the
* X and Y coordinates).
*/
public synchronized Tile transform(CoordinateTransform transform) {
Point transformedCoords = transform.transform(x << TILE_SIZE_BITS, y << TILE_SIZE_BITS);
Tile transformedTile;
boolean transformContents = ((transformedCoords.x & TILE_SIZE_MASK) != 0) || ((transformedCoords.y & TILE_SIZE_MASK) != 0);
if (transformContents) {
transformedTile = new Tile(transformedCoords.x >> TILE_SIZE_BITS, transformedCoords.y >> TILE_SIZE_BITS, maxHeight);
for (int x = 0; x < TILE_SIZE; x++) {
for (int y = 0; y < TILE_SIZE; y++) {
transformedCoords.x = x;
transformedCoords.y = y;
transform.transformInPlace(transformedCoords);
transformedCoords.x &= TILE_SIZE_MASK;
transformedCoords.y &= TILE_SIZE_MASK;
transformedTile.setTerrain(transformedCoords.x, transformedCoords.y, getTerrain(x, y));
transformedTile.setRawHeight(transformedCoords.x, transformedCoords.y, getRawHeight(x, y));
transformedTile.setWaterLevel(transformedCoords.x, transformedCoords.y, getWaterLevel(x, y));
}
}
for (Layer layer : getLayers()) {
if ((layer.getDataSize() == Layer.DataSize.BIT) || (layer.getDataSize() == Layer.DataSize.BIT_PER_CHUNK)) {
for (int x = 0; x < TILE_SIZE; x++) {
for (int y = 0; y < TILE_SIZE; y++) {
if (getBitLayerValue(layer, x, y)) {
transformedCoords.x = x;
transformedCoords.y = y;
transform.transformInPlace(transformedCoords);
transformedCoords.x &= TILE_SIZE_MASK;
transformedCoords.y &= TILE_SIZE_MASK;
transformedTile.setBitLayerValue(layer, transformedCoords.x, transformedCoords.y, true);
}
}
}
} else if (layer.getDataSize() != Layer.DataSize.NONE) {
for (int x = 0; x < TILE_SIZE; x++) {
for (int y = 0; y < TILE_SIZE; y++) {
int value = getLayerValue(layer, x, y);
if (value > 0) {
transformedCoords.x = x;
transformedCoords.y = y;
transform.transformInPlace(transformedCoords);
transformedCoords.x &= TILE_SIZE_MASK;
transformedCoords.y &= TILE_SIZE_MASK;
transformedTile.setLayerValue(layer, transformedCoords.x, transformedCoords.y, value);
}
}
}
}
}
} else {
// The transformation does not affect intra-tile coordinates, so just copy the buffers without transforming them
transformedTile = new Tile(transformedCoords.x >> TILE_SIZE_BITS, transformedCoords.y >> TILE_SIZE_BITS, maxHeight, false);
transformedTile.heightMap = copyObject(heightMap);
transformedTile.tallHeightMap = copyObject(tallHeightMap);
transformedTile.terrain = terrain.clone();
transformedTile.waterLevel = copyObject(waterLevel);
transformedTile.tallWaterLevel = copyObject(tallWaterLevel);
transformedTile.layerData = copyObject(layerData);
transformedTile.bitLayerData = copyObject(bitLayerData);
transformedTile.init();
}
if (seeds != null) {
transformedTile.seeds = new HashSet<>();
transformedTile.seeds.addAll(seeds);
for (Seed seed : transformedTile.seeds) {
seed.transform(transform);
}
}
return transformedTile;
}
Aggregations