diff --git a/src/lib/BlockPos.hx b/src/lib/BlockPos.hx index 691852a..c198124 100644 --- a/src/lib/BlockPos.hx +++ b/src/lib/BlockPos.hx @@ -1,5 +1,6 @@ package lib; +import lib.Vec.Vec2; import lib.Vec.Vec3; /** @@ -51,6 +52,16 @@ abstract BlockPos(Vec3) from Vec3 to Vec3 { return 'BlockPos(${this.x}, ${this.y}, ${this.z})'; } + /** + Returns the chunk the position is in. + **/ + public function chunk():Vec2 { + var x = Math.floor(this.x / 16); + var z = Math.floor(this.z / 16); + + return new Vec2(x, z); + } + /** Returns a list of positions neighboring the block. No Diagonal. **/ diff --git a/src/lib/WorldPos.hx b/src/lib/WorldPos.hx index b99fe7a..8f7d9ec 100644 --- a/src/lib/WorldPos.hx +++ b/src/lib/WorldPos.hx @@ -1,5 +1,6 @@ package lib; +import lib.Vec.Vec2; import lib.Vec.Vec3; /** @@ -65,6 +66,16 @@ abstract WorldPos(Vec3) from Vec3 to Vec3 { return 'WorldPos(${this.x}, ${this.y}, ${this.z})'; } + /** + Returns the chunk the position is in. + **/ + public function chunk():Vec2 { + var x = Math.floor(this.x / 16); + var z = Math.floor(this.z / 16); + + return new Vec2(x, z); + } + public function round():WorldPos { return new WorldPos({ x: Math.fround(this.x),