From 9fea1eafdb656fdadb968b7a1e2e9c33594ba1cf Mon Sep 17 00:00:00 2001 From: FrozenCow Date: Mon, 28 Feb 2011 19:26:05 +0100 Subject: [PATCH] Added shitty-looking top-down flat map. --- configuration.txt | 8 ++ src/main/java/org/dynmap/flat/FlatMap.java | 99 ++++++++++++++++++++++ web/index.html | 1 + 3 files changed, 108 insertions(+) create mode 100644 src/main/java/org/dynmap/flat/FlatMap.java diff --git a/configuration.txt b/configuration.txt index c0a23c27..bdfac2c9 100755 --- a/configuration.txt +++ b/configuration.txt @@ -28,6 +28,7 @@ jsonfile-interval: 1 worlds: - name: world maps: + - class: org.dynmap.flat.FlatMap - class: org.dynmap.kzedmap.KzedMap renderers: - class: org.dynmap.kzedmap.DefaultTileRenderer @@ -38,6 +39,7 @@ worlds: maximumheight: 127 - name: nether maps: + - class: org.dynmap.flat.FlatMap - class: org.dynmap.kzedmap.KzedMap renderers: - class: org.dynmap.kzedmap.DefaultTileRenderer @@ -66,6 +68,9 @@ web: - title: World name: world maps: + - type: FlatMapType + title: Flat + name: flat - type: KzedMapType title: Surface name: surface @@ -77,6 +82,9 @@ web: - title: Nether name: nether maps: + - type: FlatMapType + title: Flat + name: flat - type: KzedMapType title: Surface name: nether diff --git a/src/main/java/org/dynmap/flat/FlatMap.java b/src/main/java/org/dynmap/flat/FlatMap.java new file mode 100644 index 00000000..a71b43ae --- /dev/null +++ b/src/main/java/org/dynmap/flat/FlatMap.java @@ -0,0 +1,99 @@ +package org.dynmap.flat; + +import java.awt.Color; +import java.awt.image.BufferedImage; +import java.awt.image.WritableRaster; +import java.io.File; +import java.io.IOException; +import java.util.Map; + +import javax.imageio.ImageIO; + +import org.bukkit.Location; +import org.bukkit.World; +import org.dynmap.DynmapChunk; +import org.dynmap.MapTile; +import org.dynmap.MapType; +import org.dynmap.debug.Debug; +import org.dynmap.kzedmap.KzedMap; + +public class FlatMap extends MapType { + + public FlatMap(Map configuration) { + } + + @Override + public MapTile[] getTiles(Location l) { + return new MapTile[] { + new FlatMapTile(l.getWorld(), this, (int)Math.floor(l.getBlockX() / 128.0), (int)Math.floor(l.getBlockZ() / 128.0), 128) + }; + } + + @Override + public MapTile[] getAdjecentTiles(MapTile tile) { + // TODO Auto-generated method stub + return null; + } + + @Override + public DynmapChunk[] getRequiredChunks(MapTile tile) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean render(MapTile tile, File outputFile) { + FlatMapTile t = (FlatMapTile)tile; + World w = t.getWorld(); + + BufferedImage im = new BufferedImage(t.size, t.size, BufferedImage.TYPE_INT_RGB); + WritableRaster r = im.getRaster(); + + for(int x = 0; x < t.size; x++) + for (int y = 0; y < t.size; y++) { + int mx = x+t.x*t.size; + int mz = y+t.y*t.size; + int my = w.getHighestBlockYAt(mx, mz) - 1; + int blockType = w.getBlockTypeIdAt(mx, my, mz); + Color[] colors = KzedMap.colors.get(blockType); + if (colors == null) + continue; + Color c = colors[0]; + if (c == null) + continue; + r.setPixel(x, y, new int[] { + c.getRed(), + c.getGreen(), + c.getBlue() }); + } + + try { + ImageIO.write(im, "png", outputFile); + } catch (IOException e) { + Debug.error("Failed to save image: " + outputFile.getPath(), e); + } catch (java.lang.NullPointerException e) { + Debug.error("Failed to save image (NullPointerException): " + outputFile.getPath(), e); + } + im.flush(); + return false; + } + + public class FlatMapTile extends MapTile { + + public int x; + public int y; + public int size; + + public FlatMapTile(World world, FlatMap map, int x, int y, int size) { + super(world, map); + this.x = x; + this.y = y; + this.size = size; + } + + @Override + public String getFilename() { + return "flat_" + size + "_" + x + "_" + y + ".png"; + } + } +} diff --git a/web/index.html b/web/index.html index 9ad0328d..ca8e66de 100644 --- a/web/index.html +++ b/web/index.html @@ -20,6 +20,7 @@ +