use of org.pepsoft.worldpainter.gardenofeden.Garden 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.Garden in project WorldPainter by Captain-Chaos.
the class TestTool method main.
public static void main(String[] args) throws IOException, OperationCancelled {
Random random = new Random();
long seed = random.nextLong();
// TileFactory tileFactory = new NoiseTileFactory(Terrain.GRASS, DEFAULT_MAX_HEIGHT_2, 58, 62, false, false);
TileFactory tileFactory = TileFactoryFactory.createFlatTileFactory(seed, Terrain.GRASS, DEFAULT_MAX_HEIGHT_2, 62, 0, false, false);
World2 world = new World2(JAVA_ANVIL, seed, tileFactory, DEFAULT_MAX_HEIGHT_2);
world.setName("TestWorld");
world.setSpawnPoint(new Point(64, 64));
world.setGameType(GameType.CREATIVE);
Dimension dimension = world.getDimension(0);
dimension.addTile(tileFactory.createTile(0, 0));
Garden garden = dimension.getGarden();
// garden.plantSeed(inn);
while (!garden.tick()) ;
JavaWorldExporter worldExporter = new JavaWorldExporter(world);
File exportDir = new File(args[0]);
worldExporter.export(exportDir, "TestWorld", worldExporter.selectBackupDir(new File(exportDir, "TestWorld")), null);
}
use of org.pepsoft.worldpainter.gardenofeden.Garden in project WorldPainter by Captain-Chaos.
the class RiverGenerator method generateRivers.
public void generateRivers() {
dimension.setEventsInhibited(true);
UndoManager undoManager = new UndoManager(2);
dimension.register(undoManager);
snapshot = dimension.getSnapshot();
dimension.armSavePoint();
garden = dimension.getGarden();
try {
dimension.getTiles().forEach(this::generateRivers);
// Grow seeds until all activity has ceased
while (!garden.tick()) ;
// Apply the river nodes to the landscape
// A river source
dimension.getGarden().getSeeds().stream().filter(seed -> (seed instanceof RiverNode) && (seed.getParent() == null)).forEach(seed -> {
// A river source
((RiverNode) seed).apply(dimension, snapshot, new HashSet<>());
});
} finally {
garden = null;
snapshot = null;
dimension.unregister();
dimension.setEventsInhibited(false);
}
}
Aggregations