func EachChunkNearby(wc coords.World, cb func(cc coords.Chunk, priority int)) { occ := func(cc coords.Chunk, x, y, z int) coords.Chunk { return coords.Chunk{ X: cc.X + x, Y: cc.Y + y, Z: cc.Z + z, } } eachWithin := func(cc coords.Chunk, xdist, ydist, zdist int, cb func(newCC coords.Chunk, dist int)) { abs := func(n int) int { if n < 0 { return -n } return n } dist := func(x, y, z int) int { return abs(x) + abs(y) + abs(z) } cb(cc, 0) for x := -xdist; x <= xdist; x++ { for y := -ydist; y <= ydist; y++ { for z := -zdist; z <= zdist; z++ { cb(occ(cc, x, y, z), dist(x, y, z)) } } } } cc := wc.Chunk() eachWithin(cc, 2, 1, 2, func(newCC coords.Chunk, dist int) { // We want to prioritize further away chunks lower, but the // priority must be a positive integer. cb(newCC, 10-dist) }) oc := wc.Offset() if oc.Y <= 4 { cb(occ(cc, 0, -1, 0), 1) } else if oc.Y >= 28 { cb(occ(cc, 0, 1, 0), 1) } }