summaryrefslogtreecommitdiff
path: root/mcmap/examples
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2013-08-11 23:01:55 +0200
committerKevin Chabowski <kevin@kch42.de>2013-08-11 23:01:55 +0200
commitb9be995232e8299d504e7898a9d6c5384664b8ee (patch)
tree791b91d23fa261680de231ea4b8d8bb8dc451437 /mcmap/examples
downloadgomcmap-b9be995232e8299d504e7898a9d6c5384664b8ee.tar.gz
gomcmap-b9be995232e8299d504e7898a9d6c5384664b8ee.tar.bz2
gomcmap-b9be995232e8299d504e7898a9d6c5384664b8ee.zip
Initial commit.
Reading maps is already working :-D
Diffstat (limited to 'mcmap/examples')
-rw-r--r--mcmap/examples/emeraldfinder/main.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/mcmap/examples/emeraldfinder/main.go b/mcmap/examples/emeraldfinder/main.go
new file mode 100644
index 0000000..c437d41
--- /dev/null
+++ b/mcmap/examples/emeraldfinder/main.go
@@ -0,0 +1,53 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "github.com/kch42/gomcmap/mcmap"
+ "os"
+)
+
+func main() {
+ path := flag.String("path", "", "Path to region directory")
+ flag.Parse()
+
+ if *path == "" {
+ flag.Usage()
+ os.Exit(1)
+ }
+
+ region, err := mcmap.OpenRegion(*path)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Could not open region: %s", err)
+ os.Exit(1)
+ }
+
+chunkLoop:
+ for chunkPos := range region.AllChunks() {
+ cx, cz := chunkPos.X, chunkPos.Z
+ chunk, err := region.Chunk(cx, cz)
+ switch err {
+ case nil:
+ case mcmap.NotAvailable:
+ continue chunkLoop
+ default:
+ fmt.Fprintf(os.Stderr, "Error while getting chunk (%d, %d): %s", cx, cz, err)
+ os.Exit(1)
+ }
+
+ for y := 0; y < 256; y++ {
+ for x := 0; x < 16; x++ {
+ for z := 0; z < 16; z++ {
+ blk := chunk.Block(x, y, z)
+ if blk.ID == mcmap.BlkEmeraldOre {
+ absx, absz := mcmap.ChunkToBlock(cx, cz, x, z)
+ fmt.Printf("%d, %d, %d\n", absx, y, absz)
+ }
+ }
+ }
+ }
+
+ chunk = nil
+ region.UnloadChunk(cx, cz)
+ }
+}