use of org.pepsoft.worldpainter.Tile 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.Tile 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);
}
use of org.pepsoft.worldpainter.Tile in project WorldPainter by Captain-Chaos.
the class ThreeDeeView method hierarchyChanged.
// HierarchyListener
@Override
public void hierarchyChanged(HierarchyEvent event) {
if ((event.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) != 0) {
if (isDisplayable()) {
// for (Tile tile: dimension.getTiles()) {
// threeDeeRenderManager.renderTile(tile);
// }
timer = new Timer(250, this);
timer.start();
} else {
timer.stop();
timer = null;
threeDeeRenderManager.stop();
for (Tile tile : dimension.getTiles()) {
tile.removeListener(this);
}
dimension.removeDimensionListener(this);
}
}
}
use of org.pepsoft.worldpainter.Tile in project WorldPainter by Captain-Chaos.
the class ThreeDeeView method getImage.
public BufferedImage getImage(ProgressReceiver progressReceiver) throws ProgressReceiver.OperationCancelled {
Tile3DRenderer renderer = new Tile3DRenderer(dimension, colourScheme, biomeScheme, customBiomeManager, rotation);
// Paint the complete image
java.awt.Dimension preferredSize = unzoom(getPreferredSize());
BufferedImage image = new BufferedImage(preferredSize.width, preferredSize.height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = image.createGraphics();
try {
int tileCount = zSortedTiles.size(), tileNo = 0;
for (Tile tile : zSortedTiles) {
Rectangle tileBounds = getTileBounds(tile.getX(), tile.getY());
g2.drawImage(renderer.render(tile), tileBounds.x, tileBounds.y, null);
if (progressReceiver != null) {
tileNo++;
progressReceiver.setProgress((float) tileNo / tileCount);
}
}
} finally {
g2.dispose();
}
return image;
}
use of org.pepsoft.worldpainter.Tile in project WorldPainter by Captain-Chaos.
the class CavesExporter method render.
@Override
public List<Fixup> render(Dimension dimension, Rectangle area, Rectangle exportedArea, MinecraftWorld minecraftWorld) {
CavesSettings settings = (CavesSettings) getSettings();
int minZ = Math.max(settings.getMinimumLevel(), dimension.isBottomless() ? 0 : 1), maxZForWorld = Math.min(settings.getMaximumLevel(), minecraftWorld.getMaxHeight() - 1);
boolean surfaceBreaking = settings.isSurfaceBreaking();
Random random = new Random();
CaveSettings caveSettings = new CaveSettings();
caveSettings.minZ = minZ;
// Grow the area we will check for spawning caves, such that parts of
// caves which start outside the exported area are still rendered inside
// the exported area
Rectangle spawnArea = (Rectangle) exportedArea.clone();
spawnArea.grow(MAX_CAVE_LENGTH, MAX_CAVE_LENGTH);
// Go tile by tile, so we can quickly check whether the tile even
// exists and contains the layer and if not skip it entirely
int tileX1 = spawnArea.x >> TILE_SIZE_BITS, tileX2 = (spawnArea.x + spawnArea.width - 1) >> TILE_SIZE_BITS;
int tileY1 = spawnArea.y >> TILE_SIZE_BITS, tileY2 = (spawnArea.y + spawnArea.height - 1) >> TILE_SIZE_BITS;
for (int tileX = tileX1; tileX <= tileX2; tileX++) {
for (int tileY = tileY1; tileY <= tileY2; tileY++) {
Tile tile = dimension.getTile(tileX, tileY);
if ((tile == null) || (!tile.hasLayer(Caves.INSTANCE))) {
continue;
}
for (int xInTile = 0; xInTile < TILE_SIZE; xInTile++) {
for (int yInTile = 0; yInTile < TILE_SIZE; yInTile++) {
int x = (tileX << TILE_SIZE_BITS) | xInTile, y = (tileY << TILE_SIZE_BITS) | yInTile;
int value = tile.getLayerValue(Caves.INSTANCE, xInTile, yInTile);
if (value > 0) {
int height = tile.getIntHeight(xInTile, yInTile);
int maxZ = Math.min(maxZForWorld, height - (surfaceBreaking ? 0 : dimension.getTopLayerDepth(x, y, height)));
random.setSeed(dimension.getSeed() + x * 65537 + y);
for (int z = minZ; z <= maxZ; z++) {
if (value > random.nextInt(CAVE_CHANCE)) {
caveSettings.start = new Point3i(x, y, z);
caveSettings.length = MathUtils.clamp(0, (int) ((random.nextGaussian() + 2.0) * (MAX_CAVE_LENGTH / 3.0) + 0.5), MAX_CAVE_LENGTH);
createTunnel(minecraftWorld, dimension, new Random(random.nextLong()), caveSettings);
}
}
}
}
}
}
}
return null;
}
Aggregations