@nxg-org/mineflayer-util-plugin 1.3.2 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/calcs/aabb.d.ts +8 -2
- package/lib/calcs/aabb.js +26 -8
- package/package.json +1 -1
package/lib/calcs/aabb.d.ts
CHANGED
|
@@ -28,13 +28,19 @@ export declare class AABB {
|
|
|
28
28
|
computeOffsetY(other: AABB, offsetY: number): number;
|
|
29
29
|
computeOffsetZ(other: AABB, offsetZ: number): number;
|
|
30
30
|
intersects(other: AABB): boolean;
|
|
31
|
-
xzIntersectsRay(
|
|
31
|
+
xzIntersectsRay(org: Vec3, dir: Vec3): {
|
|
32
32
|
x: number;
|
|
33
33
|
z: number;
|
|
34
34
|
} | null;
|
|
35
|
-
intersectsRay(
|
|
35
|
+
intersectsRay(org: Vec3, dir: Vec3): Vec3 | null;
|
|
36
|
+
xzIntersectsSegment(org: Vec3, dest: Vec3): {
|
|
37
|
+
x: number;
|
|
38
|
+
z: number;
|
|
39
|
+
} | null;
|
|
40
|
+
intersectsSegment(org: Vec3, dest: Vec3): Vec3 | null;
|
|
36
41
|
distanceFromRay(origin: Vec3, direction: Vec3, xz?: boolean): number;
|
|
37
42
|
equals(other: AABB): boolean;
|
|
43
|
+
xzDistanceTo(pos: Vec3, heightOffset?: number): number;
|
|
38
44
|
distanceTo(pos: Vec3, heightOffset?: number): number;
|
|
39
45
|
}
|
|
40
46
|
export default AABB;
|
package/lib/calcs/aabb.js
CHANGED
|
@@ -125,17 +125,29 @@ class AABB {
|
|
|
125
125
|
this.minZ < other.maxZ &&
|
|
126
126
|
this.maxZ > other.minZ);
|
|
127
127
|
}
|
|
128
|
-
xzIntersectsRay(
|
|
129
|
-
const d = this.distanceFromRay(
|
|
130
|
-
return d === Infinity ? null : { x:
|
|
131
|
-
}
|
|
132
|
-
intersectsRay(
|
|
133
|
-
const d = this.distanceFromRay(
|
|
134
|
-
return d === Infinity ? null : new vec3_1.Vec3(
|
|
128
|
+
xzIntersectsRay(org, dir) {
|
|
129
|
+
const d = this.distanceFromRay(org, dir, true);
|
|
130
|
+
return d === Infinity ? null : { x: org.x + dir.x * d, z: org.z + dir.z * d };
|
|
131
|
+
}
|
|
132
|
+
intersectsRay(org, dir) {
|
|
133
|
+
const d = this.distanceFromRay(org, dir);
|
|
134
|
+
return d === Infinity ? null : new vec3_1.Vec3(org.x + dir.x * d, org.y + dir.y * d, org.z + dir.z * d);
|
|
135
|
+
}
|
|
136
|
+
//TODO: Better check for hit reg of PLANES.
|
|
137
|
+
xzIntersectsSegment(org, dest) {
|
|
138
|
+
const dir = dest.clone().subtract(org).normalize();
|
|
139
|
+
const d = this.distanceFromRay(org, dir, true);
|
|
140
|
+
return d > dest.distanceTo(org) || d < 0 ? null : { x: org.x + dir.x * d, z: org.z + dir.z * d };
|
|
141
|
+
}
|
|
142
|
+
//TODO: Better check for hit reg of PLANES.
|
|
143
|
+
intersectsSegment(org, dest) {
|
|
144
|
+
const dir = dest.clone().subtract(org).normalize();
|
|
145
|
+
const d = this.distanceFromRay(org, dir);
|
|
146
|
+
return d > dest.distanceTo(org) || d < 0 ? null : new vec3_1.Vec3(org.x + dir.x * d, org.y + dir.y * d, org.z + dir.z * d);
|
|
135
147
|
}
|
|
136
148
|
distanceFromRay(origin, direction, xz = false) {
|
|
137
149
|
const ro = origin.toArray();
|
|
138
|
-
const rd = direction.normalize().toArray();
|
|
150
|
+
const rd = direction.clone().normalize().toArray();
|
|
139
151
|
const aabb = this.toMinAndMaxArrays();
|
|
140
152
|
const dims = ro.length; // will change later.
|
|
141
153
|
const dif = xz ? 2 : 1;
|
|
@@ -168,6 +180,12 @@ class AABB {
|
|
|
168
180
|
this.maxY === other.maxY &&
|
|
169
181
|
this.maxZ === other.maxZ);
|
|
170
182
|
}
|
|
183
|
+
xzDistanceTo(pos, heightOffset = 0) {
|
|
184
|
+
const { x, y, z } = pos.offset(0, heightOffset, 0);
|
|
185
|
+
let dx = Math.max(this.minX - x, 0, x - this.maxX);
|
|
186
|
+
let dz = Math.max(this.minZ - z, 0, z - this.maxZ);
|
|
187
|
+
return Math.sqrt(dx * dx + dz * dz);
|
|
188
|
+
}
|
|
171
189
|
distanceTo(pos, heightOffset = 0) {
|
|
172
190
|
const { x, y, z } = pos.offset(0, heightOffset, 0);
|
|
173
191
|
let dx = Math.max(this.minX - x, 0, x - this.maxX);
|