@nxg-org/mineflayer-util-plugin 1.3.0 → 1.3.5
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 +13 -2
- package/lib/calcs/aabb.js +41 -25
- package/lib/rayTracingFunctions.js +1 -1
- package/package.json +1 -1
package/lib/calcs/aabb.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export declare class AABB {
|
|
|
19
19
|
0: Vec3;
|
|
20
20
|
1: Vec3;
|
|
21
21
|
};
|
|
22
|
+
toVertices(): Vec3[];
|
|
22
23
|
floor(): void;
|
|
23
24
|
extend(dx: number, dy: number, dz: number): this;
|
|
24
25
|
contract(x: number, y: number, z: number): this;
|
|
@@ -28,9 +29,19 @@ export declare class AABB {
|
|
|
28
29
|
computeOffsetY(other: AABB, offsetY: number): number;
|
|
29
30
|
computeOffsetZ(other: AABB, offsetZ: number): number;
|
|
30
31
|
intersects(other: AABB): boolean;
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
xzIntersectsRay(org: Vec3, dir: Vec3): {
|
|
33
|
+
x: number;
|
|
34
|
+
z: number;
|
|
35
|
+
} | null;
|
|
36
|
+
intersectsRay(org: Vec3, dir: Vec3): Vec3 | null;
|
|
37
|
+
xzIntersectsSegment(org: Vec3, dest: Vec3): {
|
|
38
|
+
x: number;
|
|
39
|
+
z: number;
|
|
40
|
+
} | null;
|
|
41
|
+
intersectsSegment(org: Vec3, dest: Vec3): Vec3 | null;
|
|
42
|
+
distanceFromRay(origin: Vec3, direction: Vec3, xz?: boolean): number;
|
|
33
43
|
equals(other: AABB): boolean;
|
|
44
|
+
xzDistanceTo(pos: Vec3, heightOffset?: number): number;
|
|
34
45
|
distanceTo(pos: Vec3, heightOffset?: number): number;
|
|
35
46
|
}
|
|
36
47
|
export default AABB;
|
package/lib/calcs/aabb.js
CHANGED
|
@@ -34,6 +34,18 @@ class AABB {
|
|
|
34
34
|
toVecs() {
|
|
35
35
|
return { 0: new vec3_1.Vec3(this.minX, this.minY, this.minZ), 1: new vec3_1.Vec3(this.maxX, this.maxY, this.maxZ) };
|
|
36
36
|
}
|
|
37
|
+
toVertices() {
|
|
38
|
+
return [
|
|
39
|
+
new vec3_1.Vec3(this.minX, this.minY, this.minZ),
|
|
40
|
+
new vec3_1.Vec3(this.minX, this.minY, this.maxZ),
|
|
41
|
+
new vec3_1.Vec3(this.minX, this.maxY, this.minZ),
|
|
42
|
+
new vec3_1.Vec3(this.minX, this.maxY, this.maxZ),
|
|
43
|
+
new vec3_1.Vec3(this.maxX, this.minY, this.minZ),
|
|
44
|
+
new vec3_1.Vec3(this.maxX, this.minY, this.maxZ),
|
|
45
|
+
new vec3_1.Vec3(this.maxX, this.maxY, this.minZ),
|
|
46
|
+
new vec3_1.Vec3(this.maxX, this.maxY, this.maxZ),
|
|
47
|
+
];
|
|
48
|
+
}
|
|
37
49
|
floor() {
|
|
38
50
|
this.minX = Math.floor(this.minX);
|
|
39
51
|
this.minY = Math.floor(this.minY);
|
|
@@ -125,24 +137,36 @@ class AABB {
|
|
|
125
137
|
this.minZ < other.maxZ &&
|
|
126
138
|
this.maxZ > other.minZ);
|
|
127
139
|
}
|
|
128
|
-
|
|
129
|
-
const d = this.distanceFromRay(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
140
|
+
xzIntersectsRay(org, dir) {
|
|
141
|
+
const d = this.distanceFromRay(org, dir, true);
|
|
142
|
+
return d === Infinity ? null : { x: org.x + dir.x * d, z: org.z + dir.z * d };
|
|
143
|
+
}
|
|
144
|
+
intersectsRay(org, dir) {
|
|
145
|
+
const d = this.distanceFromRay(org, dir);
|
|
146
|
+
return d === Infinity ? null : new vec3_1.Vec3(org.x + dir.x * d, org.y + dir.y * d, org.z + dir.z * d);
|
|
147
|
+
}
|
|
148
|
+
//TODO: Better check for hit reg of PLANES.
|
|
149
|
+
xzIntersectsSegment(org, dest) {
|
|
150
|
+
const dir = dest.clone().subtract(org).normalize();
|
|
151
|
+
const d = this.distanceFromRay(org, dir, true);
|
|
152
|
+
return d > dest.distanceTo(org) || d < 0 ? null : { x: org.x + dir.x * d, z: org.z + dir.z * d };
|
|
136
153
|
}
|
|
137
|
-
|
|
154
|
+
//TODO: Better check for hit reg of PLANES.
|
|
155
|
+
intersectsSegment(org, dest) {
|
|
156
|
+
const dir = dest.clone().subtract(org).normalize();
|
|
157
|
+
const d = this.distanceFromRay(org, dir);
|
|
158
|
+
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);
|
|
159
|
+
}
|
|
160
|
+
distanceFromRay(origin, direction, xz = false) {
|
|
138
161
|
const ro = origin.toArray();
|
|
139
|
-
const rd = direction.normalize().toArray();
|
|
162
|
+
const rd = direction.clone().normalize().toArray();
|
|
140
163
|
const aabb = this.toMinAndMaxArrays();
|
|
141
164
|
const dims = ro.length; // will change later.
|
|
165
|
+
const dif = xz ? 2 : 1;
|
|
142
166
|
let lo = -Infinity;
|
|
143
167
|
let hi = +Infinity;
|
|
144
168
|
// let test = origin.clone()
|
|
145
|
-
for (let i = 0; i < dims; i
|
|
169
|
+
for (let i = 0; i < dims; i += dif) {
|
|
146
170
|
let dimLo = (aabb[0][i] - ro[i]) / rd[i];
|
|
147
171
|
let dimHi = (aabb[1][i] - ro[i]) / rd[i];
|
|
148
172
|
if (dimLo > dimHi) {
|
|
@@ -150,21 +174,7 @@ class AABB {
|
|
|
150
174
|
dimLo = dimHi;
|
|
151
175
|
dimHi = tmp;
|
|
152
176
|
}
|
|
153
|
-
// let num;
|
|
154
|
-
// switch (i) {
|
|
155
|
-
// case 0:
|
|
156
|
-
// num = "x"
|
|
157
|
-
// break;
|
|
158
|
-
// case 1:
|
|
159
|
-
// num = "y"
|
|
160
|
-
// break;
|
|
161
|
-
// case 2:
|
|
162
|
-
// num = "z"
|
|
163
|
-
// break;
|
|
164
|
-
// }
|
|
165
|
-
// console.log(num, aabb[0][i], aabb[1][i], ro[i], "highest overall:", lo, hi )
|
|
166
177
|
if (dimHi < lo || dimLo > hi) {
|
|
167
|
-
console.log("fuck", dimHi < lo, dimLo > hi);
|
|
168
178
|
return Infinity;
|
|
169
179
|
}
|
|
170
180
|
if (dimLo > lo)
|
|
@@ -182,6 +192,12 @@ class AABB {
|
|
|
182
192
|
this.maxY === other.maxY &&
|
|
183
193
|
this.maxZ === other.maxZ);
|
|
184
194
|
}
|
|
195
|
+
xzDistanceTo(pos, heightOffset = 0) {
|
|
196
|
+
const { x, y, z } = pos.offset(0, heightOffset, 0);
|
|
197
|
+
let dx = Math.max(this.minX - x, 0, x - this.maxX);
|
|
198
|
+
let dz = Math.max(this.minZ - z, 0, z - this.maxZ);
|
|
199
|
+
return Math.sqrt(dx * dx + dz * dz);
|
|
200
|
+
}
|
|
185
201
|
distanceTo(pos, heightOffset = 0) {
|
|
186
202
|
const { x, y, z } = pos.offset(0, heightOffset, 0);
|
|
187
203
|
let dx = Math.max(this.minX - x, 0, x - this.maxX);
|
|
@@ -33,7 +33,7 @@ class RayTraceFunctions {
|
|
|
33
33
|
let targetDist = maxDistance;
|
|
34
34
|
for (let i = 0; i < entities.length; i++) {
|
|
35
35
|
const e = entities[i];
|
|
36
|
-
const w = e.height
|
|
36
|
+
const w = e.height >= 1.62 && e.height <= 1.99 || e.height === 2.9 ? 0.3 : e.height / 2;
|
|
37
37
|
const shapes = [[-w, 0, -w, w, e.height + (e.height === 1.62 ? 0.18 : 0), w]];
|
|
38
38
|
const intersect = iterator.intersect(shapes, e.position);
|
|
39
39
|
if (intersect) {
|