feat(util, anvil): add FloorDiv utility and nil-check in ChunkAt

This commit is contained in:
adman
2026-05-06 22:38:24 +02:00
parent 4b95ea9ae2
commit d5979b2c3d
2 changed files with 9 additions and 0 deletions
+5
View File
@@ -62,12 +62,17 @@ func ReadChunkHeader(r *os.File) (ch *ChunkHeader, err error) {
return
}
// ChunkAt returns the chunk at the given position, or nil if it is empty.
func (c *ChunkHeader) ChunkAt(f *os.File, x, z int32) (n *nbt.Tag, err error) {
if x < 0 || z < 0 || x >= ChunksWidthRegionFile || z >= ChunksWidthRegionFile {
err = fmt.Errorf("chunk out of bounds")
return
}
off, size := chunkLocation(c.Chunk[chunkXZtoIndex(x, z)])
if off == 0 {
return nil, nil
}
_, err = f.Seek(int64(off), 0)
if err != nil {
return
+4
View File
@@ -2,6 +2,10 @@ package util
import "math"
func FloorDiv(a, b int32) int32 {
return (a - ((a%b + b) % b)) / b
}
func BpeByNum(x float64) uint8 {
return uint8(math.Ceil(math.Log2(x)))
}