get chunk from position

This commit is contained in:
Niklas Kapelle 2024-10-20 22:20:33 +02:00
parent 2dd85c2b26
commit 90b4015ba1
Signed by: niklas
GPG Key ID: 4EB651B36D841D16
2 changed files with 22 additions and 0 deletions

View File

@ -1,5 +1,6 @@
package lib;
import lib.Vec.Vec2;
import lib.Vec.Vec3;
/**
@ -51,6 +52,16 @@ abstract BlockPos(Vec3<Int>) from Vec3<Int> to Vec3<Int> {
return 'BlockPos(${this.x}, ${this.y}, ${this.z})';
}
/**
Returns the chunk the position is in.
**/
public function chunk():Vec2<Int> {
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.
**/

View File

@ -1,5 +1,6 @@
package lib;
import lib.Vec.Vec2;
import lib.Vec.Vec3;
/**
@ -65,6 +66,16 @@ abstract WorldPos(Vec3<Float>) from Vec3<Float> to Vec3<Float> {
return 'WorldPos(${this.x}, ${this.y}, ${this.z})';
}
/**
Returns the chunk the position is in.
**/
public function chunk():Vec2<Int> {
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),