Commits

Owen Nelson committed 9b69655

implementing the getBlocks() method, poorly

Comments (0)

Files changed (6)

src/com/theomn/cartography/CartographyFileRelay.java

     static String outDir = "tiles";
 
     @Override
-    public void emit(Map obj) {
+    public void emit(MapTile tile) {
         BufferedWriter out = null;
         try {
-            out = new BufferedWriter(new FileWriter(outDir + File.separator + "tile"+obj.get("x")+","+obj.get("z")+".tmp"));
-            out.write(obj.get("blocks").toString());
+            out = new BufferedWriter(new FileWriter(outDir + File.separator + tile.getName()+".tmp"));
+            out.write(tile.getBlocks().toString());
             out.close();
         } catch (IOException e) {
             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.

src/com/theomn/cartography/CartographyLoggerRelay.java

 package com.theomn.cartography;
 
-import java.util.Map;
 import java.util.logging.Logger;
 
 public class CartographyLoggerRelay extends CartographyRelay {
     static Logger log = Logger.getLogger("Minecraft");
 
     @Override
-    public void emit(Map obj) {
+    public void emit(MapTile obj) {
         log.info(obj.toString());
     }
 }

src/com/theomn/cartography/CartographyPlayerListener.java

         Player player = event.getPlayer();
         MapTile tile = new MapTile(player);
         this.log.info(tile.toString());
+        this.relay.emit(tile);
+
+
 
 //        Location playerLoc = player.getLocation();
 //        World world = player.getWorld();

src/com/theomn/cartography/CartographyRelay.java

 package com.theomn.cartography;
 
-import java.util.Map;
 
 abstract class CartographyRelay {
-    abstract public void emit(Map obj);
+    abstract public void emit(MapTile tile);
 }
 

src/com/theomn/cartography/CartographyWorldListener.java

         payload.put("x", snap.getX());
         payload.put("z", snap.getZ());
         this.log.info("Chunk "+snap.getX()+","+snap.getZ()+":"+bounds.toString());
-        this.relay.emit(payload);
+//        this.relay.emit(payload);
 
     }
 

src/com/theomn/cartography/MapTile.java

 package com.theomn.cartography;
 
-import com.sun.org.apache.xpath.internal.axes.SelfIteratorNoPredicate;
 import org.bukkit.Chunk;
 import org.bukkit.ChunkSnapshot;
 import org.bukkit.Location;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.logging.Logger;
 
 /*
  * MapTile is a representation of a 10x10 chunk (160x160 block)
  *
  */
 public class MapTile {
+    static Logger log = Logger.getLogger("Minecraft");
 
     /* chunks are 16x16 blocks */
     public final static int blocks_per_chunk = 16;
 
     /*
      * Returns a list of block type ids for the selected tile.
+     * Currently something in these nested loops are borked. The block order appears to be messed up.
      */
     public List<Integer> getBlocks(){
+
         if (this.blocks == null){
             this.blocks = new ArrayList<Integer>();
+            for (int z = this.top; z <= this.bottom; z++){
 
+                List<ChunkSnapshot> snapshotRow = new ArrayList<ChunkSnapshot>();
+
+                for (int x = this.left; x <= this.right; x++){
+                    snapshotRow.add(this.world.getChunkAt(x, z).getChunkSnapshot(true, false, false));
+                }
+
+                for (ChunkSnapshot snap : snapshotRow){
+                    for (int i = 0; i < 16; i++){
+                        for (int j = 0; j < 16; j++){
+                            this.blocks.add(snap.getBlockTypeId(j, snap.getHighestBlockYAt(j, i) - 1, i));
+                        }
+                    }
+                }
+
+            }
         }
+
         return this.blocks;
     }
+
+    public String getName(){
+        return "tile_"+this.left+","+this.top+","+this.right+","+this.bottom;
+    }
 }