summaryrefslogtreecommitdiff
path: root/mcmap
diff options
context:
space:
mode:
Diffstat (limited to 'mcmap')
-rw-r--r--mcmap/chunk.go11
-rw-r--r--mcmap/examples/emeraldfinder/main.go15
-rw-r--r--mcmap/examples/replace/main.go15
3 files changed, 21 insertions, 20 deletions
diff --git a/mcmap/chunk.go b/mcmap/chunk.go
index 3241d82..9cf2dc7 100644
--- a/mcmap/chunk.go
+++ b/mcmap/chunk.go
@@ -86,6 +86,17 @@ func (c *Chunk) Height(x, z int) int {
return int(c.heightMap[z*ChunkSizeXZ+x])
}
+// Iter iterates ofer all blocks of this chunk and calls the function fx with the coords (x,y,z) and a pointer to the block.
+func (c *Chunk) Iter(fx func(int, int, int, *Block)) {
+ for x := 0; x < ChunkSizeXZ; x++ {
+ for y := 0; y < ChunkSizeY; y++ {
+ for z := 0; z < ChunkSizeXZ; z++ {
+ fx(x, y, z, &(c.blocks[calcBlockOffset(x, y, z)]))
+ }
+ }
+ }
+}
+
// Biome gets the Biome at x,z.
func (c *Chunk) Biome(x, z int) Biome { return c.biomes[x*ChunkSizeXZ+z] }
diff --git a/mcmap/examples/emeraldfinder/main.go b/mcmap/examples/emeraldfinder/main.go
index 3249a35..ea22624 100644
--- a/mcmap/examples/emeraldfinder/main.go
+++ b/mcmap/examples/emeraldfinder/main.go
@@ -36,17 +36,12 @@ chunkLoop:
os.Exit(1)
}
- for y := 0; y < mcmap.ChunkSizeY; y++ {
- for x := 0; x < mcmap.ChunkSizeXZ; x++ {
- for z := 0; z < mcmap.ChunkSizeXZ; 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.Iter(func(x, y, z int, blk *mcmap.Block) {
+ if blk.ID == mcmap.BlkEmeraldOre {
+ absx, absz := mcmap.ChunkToBlock(cx, cz, x, z)
+ fmt.Printf("%d, %d, %d\n", absx, y, absz)
}
- }
+ })
chunk.MarkUnused()
}
diff --git a/mcmap/examples/replace/main.go b/mcmap/examples/replace/main.go
index 87dd677..d289522 100644
--- a/mcmap/examples/replace/main.go
+++ b/mcmap/examples/replace/main.go
@@ -37,17 +37,12 @@ chunkLoop:
}
modified := false
- for y := 0; y < mcmap.ChunkSizeY; y++ {
- for x := 0; x < mcmap.ChunkSizeXZ; x++ {
- for z := 0; z < mcmap.ChunkSizeXZ; z++ {
- blk := chunk.Block(x, y, z)
- if blk.ID == mcmap.BlkBlockOfIron {
- blk.ID = mcmap.BlkBlockOfDiamond
- modified = true
- }
- }
+ chunk.Iter(func(x, y, z int, blk *mcmap.Block) {
+ if blk.ID == mcmap.BlkBlockOfIron {
+ blk.ID = mcmap.BlkBlockOfDiamond
+ modified = true
}
- }
+ })
if modified {
fmt.Printf("Modified chunk %d, %d.\n", cx, cz)