get chunk from position
This commit is contained in:
parent
2dd85c2b26
commit
90b4015ba1
@ -1,5 +1,6 @@
|
|||||||
package lib;
|
package lib;
|
||||||
|
|
||||||
|
import lib.Vec.Vec2;
|
||||||
import lib.Vec.Vec3;
|
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})';
|
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.
|
Returns a list of positions neighboring the block. No Diagonal.
|
||||||
**/
|
**/
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package lib;
|
package lib;
|
||||||
|
|
||||||
|
import lib.Vec.Vec2;
|
||||||
import lib.Vec.Vec3;
|
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})';
|
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 {
|
public function round():WorldPos {
|
||||||
return new WorldPos({
|
return new WorldPos({
|
||||||
x: Math.fround(this.x),
|
x: Math.fround(this.x),
|
||||||
|
Loading…
Reference in New Issue
Block a user