@nxg-org/mineflayer-util-plugin 1.3.0 → 1.3.1
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 +5 -1
- package/lib/calcs/aabb.js +8 -22
- package/lib/rayTracingFunctions.js +1 -1
- package/package.json +1 -1
package/lib/calcs/aabb.d.ts
CHANGED
|
@@ -28,8 +28,12 @@ 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(origin: Vec3, direction: Vec3): {
|
|
32
|
+
x: number;
|
|
33
|
+
z: number;
|
|
34
|
+
} | null;
|
|
31
35
|
intersectsRay(origin: Vec3, direction: Vec3): Vec3 | null;
|
|
32
|
-
distanceFromRay(origin: Vec3, direction: Vec3): number;
|
|
36
|
+
distanceFromRay(origin: Vec3, direction: Vec3, xz?: boolean): number;
|
|
33
37
|
equals(other: AABB): boolean;
|
|
34
38
|
distanceTo(pos: Vec3, heightOffset?: number): number;
|
|
35
39
|
}
|
package/lib/calcs/aabb.js
CHANGED
|
@@ -125,24 +125,24 @@ class AABB {
|
|
|
125
125
|
this.minZ < other.maxZ &&
|
|
126
126
|
this.maxZ > other.minZ);
|
|
127
127
|
}
|
|
128
|
+
xzIntersectsRay(origin, direction) {
|
|
129
|
+
const d = this.distanceFromRay(origin, direction);
|
|
130
|
+
return d === Infinity ? null : { x: origin.x + direction.x * d, z: origin.z + direction.z * d };
|
|
131
|
+
}
|
|
128
132
|
intersectsRay(origin, direction) {
|
|
129
133
|
const d = this.distanceFromRay(origin, direction);
|
|
130
|
-
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
return new vec3_1.Vec3(origin.x + direction.x * d, origin.y + direction.y * d, origin.z + direction.z * d);
|
|
135
|
-
}
|
|
134
|
+
return d === Infinity ? null : new vec3_1.Vec3(origin.x + direction.x * d, origin.y + direction.y * d, origin.z + direction.z * d);
|
|
136
135
|
}
|
|
137
|
-
distanceFromRay(origin, direction) {
|
|
136
|
+
distanceFromRay(origin, direction, xz = false) {
|
|
138
137
|
const ro = origin.toArray();
|
|
139
138
|
const rd = direction.normalize().toArray();
|
|
140
139
|
const aabb = this.toMinAndMaxArrays();
|
|
141
140
|
const dims = ro.length; // will change later.
|
|
141
|
+
const dif = xz ? 2 : 1;
|
|
142
142
|
let lo = -Infinity;
|
|
143
143
|
let hi = +Infinity;
|
|
144
144
|
// let test = origin.clone()
|
|
145
|
-
for (let i = 0; i < dims; i
|
|
145
|
+
for (let i = 0; i < dims; i += dif) {
|
|
146
146
|
let dimLo = (aabb[0][i] - ro[i]) / rd[i];
|
|
147
147
|
let dimHi = (aabb[1][i] - ro[i]) / rd[i];
|
|
148
148
|
if (dimLo > dimHi) {
|
|
@@ -150,21 +150,7 @@ class AABB {
|
|
|
150
150
|
dimLo = dimHi;
|
|
151
151
|
dimHi = tmp;
|
|
152
152
|
}
|
|
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
153
|
if (dimHi < lo || dimLo > hi) {
|
|
167
|
-
console.log("fuck", dimHi < lo, dimLo > hi);
|
|
168
154
|
return Infinity;
|
|
169
155
|
}
|
|
170
156
|
if (dimLo > lo)
|
|
@@ -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) {
|