@nxg-org/mineflayer-util-plugin 1.3.12 → 1.3.16

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.
@@ -8,6 +8,7 @@ export declare class AABB {
8
8
  maxZ: number;
9
9
  constructor(x0: number, y0: number, z0: number, x1: number, y1: number, z1: number);
10
10
  static fromVecs(min: Vec3, max: Vec3): AABB;
11
+ static fromBlock(min: Vec3): AABB;
11
12
  set(x0: number, y0: number, z0: number, x1: number, y1: number, z1: number): void;
12
13
  clone(): AABB;
13
14
  toArray(): number[];
@@ -40,8 +41,17 @@ export declare class AABB {
40
41
  } | null;
41
42
  intersectsSegment(org: Vec3, dest: Vec3): Vec3 | null;
42
43
  distanceFromRay(origin: Vec3, direction: Vec3, xz?: boolean): number;
44
+ intersect(aABB: AABB): AABB;
43
45
  equals(other: AABB): boolean;
44
- xzDistanceTo(pos: Vec3, heightOffset?: number): number;
45
- distanceTo(pos: Vec3, heightOffset?: number): number;
46
+ xzDistanceToVec(pos: Vec3, heightOffset?: number): number;
47
+ distanceToVec(pos: Vec3, heightOffset?: number): number;
48
+ expandTowards(vec3: Vec3): AABB;
49
+ expandTowardsCoords(d: number, d2: number, d3: number): AABB;
50
+ moveCoords(d: number, d2: number, d3: number): AABB;
51
+ move(vec3: Vec3): AABB;
52
+ intersectsCoords(d: number, d2: number, d3: number, d4: number, d5: number, d6: number): boolean;
53
+ collidesAABB(aABB: AABB): boolean;
54
+ collidesCoords(d: number, d2: number, d3: number, d4: number, d5: number, d6: number): boolean;
55
+ getCenter(): Vec3;
46
56
  }
47
57
  export default AABB;
package/lib/calcs/aabb.js CHANGED
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AABB = void 0;
4
4
  const vec3_1 = require("vec3");
5
+ function lerp(f, f2, f3) {
6
+ return f2 + f * (f3 - f2);
7
+ }
5
8
  class AABB {
6
9
  constructor(x0, y0, z0, x1, y1, z1) {
7
10
  this.minX = x0;
@@ -14,6 +17,9 @@ class AABB {
14
17
  static fromVecs(min, max) {
15
18
  return new AABB(min.x, min.y, min.z, max.x, max.y, max.z);
16
19
  }
20
+ static fromBlock(min) {
21
+ return new AABB(min.x, min.y, min.z, min.x + 1.0, min.y + 1.0, min.z + 1.0);
22
+ }
17
23
  set(x0, y0, z0, x1, y1, z1) {
18
24
  this.minX = x0;
19
25
  this.minY = y0;
@@ -184,6 +190,15 @@ class AABB {
184
190
  }
185
191
  return lo > hi ? Infinity : lo;
186
192
  }
193
+ intersect(aABB) {
194
+ const d = Math.max(this.minX, aABB.minX);
195
+ const d2 = Math.max(this.minY, aABB.minY);
196
+ const d3 = Math.max(this.minZ, aABB.minZ);
197
+ const d4 = Math.min(this.maxX, aABB.maxX);
198
+ const d5 = Math.min(this.maxY, aABB.maxY);
199
+ const d6 = Math.min(this.maxZ, aABB.maxZ);
200
+ return new AABB(d, d2, d3, d4, d5, d6);
201
+ }
187
202
  equals(other) {
188
203
  return (this.minX === other.minX &&
189
204
  this.minY === other.minY &&
@@ -192,19 +207,67 @@ class AABB {
192
207
  this.maxY === other.maxY &&
193
208
  this.maxZ === other.maxZ);
194
209
  }
195
- xzDistanceTo(pos, heightOffset = 0) {
210
+ xzDistanceToVec(pos, heightOffset = 0) {
196
211
  const { x, y, z } = pos.offset(0, heightOffset, 0);
197
212
  let dx = Math.max(this.minX - x, 0, x - this.maxX);
198
213
  let dz = Math.max(this.minZ - z, 0, z - this.maxZ);
199
214
  return Math.sqrt(dx * dx + dz * dz);
200
215
  }
201
- distanceTo(pos, heightOffset = 0) {
216
+ distanceToVec(pos, heightOffset = 0) {
202
217
  const { x, y, z } = pos.offset(0, heightOffset, 0);
203
218
  let dx = Math.max(this.minX - x, 0, x - this.maxX);
204
219
  let dy = Math.max(this.minY - y, 0, y - this.maxY);
205
220
  let dz = Math.max(this.minZ - z, 0, z - this.maxZ);
206
221
  return Math.sqrt(dx * dx + dy * dy + dz * dz);
207
222
  }
223
+ expandTowards(vec3) {
224
+ return this.expandTowardsCoords(vec3.x, vec3.y, vec3.z);
225
+ }
226
+ expandTowardsCoords(d, d2, d3) {
227
+ let d4 = this.minX;
228
+ let d5 = this.minY;
229
+ let d6 = this.minZ;
230
+ let d7 = this.maxX;
231
+ let d8 = this.maxY;
232
+ let d9 = this.maxZ;
233
+ if (d < 0.0) {
234
+ d4 += d;
235
+ }
236
+ else if (d > 0.0) {
237
+ d7 += d;
238
+ }
239
+ if (d2 < 0.0) {
240
+ d5 += d2;
241
+ }
242
+ else if (d2 > 0.0) {
243
+ d8 += d2;
244
+ }
245
+ if (d3 < 0.0) {
246
+ d6 += d3;
247
+ }
248
+ else if (d3 > 0.0) {
249
+ d9 += d3;
250
+ }
251
+ return new AABB(d4, d5, d6, d7, d8, d9);
252
+ }
253
+ moveCoords(d, d2, d3) {
254
+ return new AABB(this.minX + d, this.minY + d2, this.minZ + d3, this.maxX + d, this.maxY + d2, this.maxZ + d3);
255
+ }
256
+ move(vec3) {
257
+ return new AABB(this.minX + vec3.x, this.minY + vec3.y, this.minZ + vec3.z, this.maxX + vec3.x, this.maxY + vec3.y, this.maxZ + vec3.z);
258
+ }
259
+ intersectsCoords(d, d2, d3, d4, d5, d6) {
260
+ return this.minX < d4 && this.maxX > d && this.minY < d5 && this.maxY > d2 && this.minZ < d6 && this.maxZ > d3;
261
+ }
262
+ collidesAABB(aABB) {
263
+ return this.collidesCoords(aABB.minX, aABB.minY, aABB.minZ, aABB.maxX, aABB.maxY, aABB.maxZ);
264
+ }
265
+ collidesCoords(d, d2, d3, d4, d5, d6) {
266
+ return this.minX <= d4 && this.maxX >= d && this.minY <= d5 && this.maxY >= d2 && this.minZ <= d6 && this.maxZ >= d3;
267
+ }
268
+ getCenter() {
269
+ return new vec3_1.Vec3(lerp(0.5, this.minX, this.maxX), lerp(0.5, this.minY, this.maxY), lerp(0.5, this.minZ, this.maxZ));
270
+ }
208
271
  }
209
272
  exports.AABB = AABB;
210
273
  exports.default = AABB;
File without changes
@@ -0,0 +1,663 @@
1
+ "use strict";
2
+ // /*
3
+ // * Decompiled with CFR 0.146.
4
+ // *
5
+ // * Could not load the following classes:
6
+ // * org.apache.commons.lang3.math.NumberUtils
7
+ // */
8
+ // export class Mth {
9
+ // private static final int BIG_ENOUGH_INT = 1024;
10
+ // private static final float BIG_ENOUGH_FLOAT = 1024.0f;
11
+ // private static final long UUID_VERSION = 61440L;
12
+ // private static final long UUID_VERSION_TYPE_4 = 16384L;
13
+ // private static final long UUID_VARIANT = -4611686018427387904L;
14
+ // private static final long UUID_VARIANT_2 = Long.MIN_VALUE;
15
+ // public static final float PI = 3.1415927f;
16
+ // public static final float HALF_PI = 1.5707964f;
17
+ // public static final float TWO_PI = 6.2831855f;
18
+ // public static final float DEG_TO_RAD = 0.017453292f;
19
+ // public static final float RAD_TO_DEG = 57.295776f;
20
+ // public static final float EPSILON = 1.0E-5f;
21
+ // public static final float SQRT_OF_TWO = Mth.sqrt(2.0f);
22
+ // private static final float SIN_SCALE = 10430.378f;
23
+ // private static final float[] SIN = Util.make(new float[65536], arrf -> {
24
+ // for (int i = 0; i < ((float[])arrf).length; ++i) {
25
+ // arrf[i] = (float)Math.sin((double)i * 3.141592653589793 * 2.0 / 65536.0);
26
+ // }
27
+ // });
28
+ // private static final Random RANDOM = new Random();
29
+ // private static final int[] MULTIPLY_DE_BRUIJN_BIT_POSITION = new int[]{0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9};
30
+ // private static final double ONE_SIXTH = 0.16666666666666666;
31
+ // private static final int FRAC_EXP = 8;
32
+ // private static final int LUT_SIZE = 257;
33
+ // private static final double FRAC_BIAS = Double.longBitsToDouble(4805340802404319232L);
34
+ // private static final double[] ASIN_TAB = new double[257];
35
+ // private static final double[] COS_TAB = new double[257];
36
+ // public static float sin(float f) {
37
+ // return SIN[(int)(f * 10430.378f) & 0xFFFF];
38
+ // }
39
+ // public static float cos(float f) {
40
+ // return SIN[(int)(f * 10430.378f + 16384.0f) & 0xFFFF];
41
+ // }
42
+ // public static float sqrt(float f) {
43
+ // return (float)Math.sqrt(f);
44
+ // }
45
+ // public static int floor(float f) {
46
+ // int n = (int)f;
47
+ // return f < (float)n ? n - 1 : n;
48
+ // }
49
+ // public static int fastFloor(double d) {
50
+ // return (int)(d + 1024.0) - 1024;
51
+ // }
52
+ // public static int floor(double d) {
53
+ // int n = (int)d;
54
+ // return d < (double)n ? n - 1 : n;
55
+ // }
56
+ // public static long lfloor(double d) {
57
+ // long l = (long)d;
58
+ // return d < (double)l ? l - 1L : l;
59
+ // }
60
+ // public static int absFloor(double d) {
61
+ // return (int)(d >= 0.0 ? d : -d + 1.0);
62
+ // }
63
+ // public static float abs(float f) {
64
+ // return Math.abs(f);
65
+ // }
66
+ // public static int abs(int n) {
67
+ // return Math.abs(n);
68
+ // }
69
+ // public static int ceil(float f) {
70
+ // int n = (int)f;
71
+ // return f > (float)n ? n + 1 : n;
72
+ // }
73
+ // public static int ceil(double d) {
74
+ // int n = (int)d;
75
+ // return d > (double)n ? n + 1 : n;
76
+ // }
77
+ // public static byte clamp(byte by, byte by2, byte by3) {
78
+ // if (by < by2) {
79
+ // return by2;
80
+ // }
81
+ // if (by > by3) {
82
+ // return by3;
83
+ // }
84
+ // return by;
85
+ // }
86
+ // public static int clamp(int n, int n2, int n3) {
87
+ // if (n < n2) {
88
+ // return n2;
89
+ // }
90
+ // if (n > n3) {
91
+ // return n3;
92
+ // }
93
+ // return n;
94
+ // }
95
+ // public static long clamp(long l, long l2, long l3) {
96
+ // if (l < l2) {
97
+ // return l2;
98
+ // }
99
+ // if (l > l3) {
100
+ // return l3;
101
+ // }
102
+ // return l;
103
+ // }
104
+ // public static float clamp(float f, float f2, float f3) {
105
+ // if (f < f2) {
106
+ // return f2;
107
+ // }
108
+ // if (f > f3) {
109
+ // return f3;
110
+ // }
111
+ // return f;
112
+ // }
113
+ // public static double clamp(double d, double d2, double d3) {
114
+ // if (d < d2) {
115
+ // return d2;
116
+ // }
117
+ // if (d > d3) {
118
+ // return d3;
119
+ // }
120
+ // return d;
121
+ // }
122
+ // public static double clampedLerp(double d, double d2, double d3) {
123
+ // if (d3 < 0.0) {
124
+ // return d;
125
+ // }
126
+ // if (d3 > 1.0) {
127
+ // return d2;
128
+ // }
129
+ // return Mth.lerp(d3, d, d2);
130
+ // }
131
+ // public static float clampedLerp(float f, float f2, float f3) {
132
+ // if (f3 < 0.0f) {
133
+ // return f;
134
+ // }
135
+ // if (f3 > 1.0f) {
136
+ // return f2;
137
+ // }
138
+ // return Mth.lerp(f3, f, f2);
139
+ // }
140
+ // public static double absMax(double d, double d2) {
141
+ // if (d < 0.0) {
142
+ // d = -d;
143
+ // }
144
+ // if (d2 < 0.0) {
145
+ // d2 = -d2;
146
+ // }
147
+ // return d > d2 ? d : d2;
148
+ // }
149
+ // public static int intFloorDiv(int n, int n2) {
150
+ // return Math.floorDiv(n, n2);
151
+ // }
152
+ // public static int nextInt(Random random, int n, int n2) {
153
+ // if (n >= n2) {
154
+ // return n;
155
+ // }
156
+ // return random.nextInt(n2 - n + 1) + n;
157
+ // }
158
+ // public static float nextFloat(Random random, float f, float f2) {
159
+ // if (f >= f2) {
160
+ // return f;
161
+ // }
162
+ // return random.nextFloat() * (f2 - f) + f;
163
+ // }
164
+ // public static double nextDouble(Random random, double d, double d2) {
165
+ // if (d >= d2) {
166
+ // return d;
167
+ // }
168
+ // return random.nextDouble() * (d2 - d) + d;
169
+ // }
170
+ // public static double average(long[] arrl) {
171
+ // long l = 0L;
172
+ // for (long l2 : arrl) {
173
+ // l += l2;
174
+ // }
175
+ // return (double)l / (double)arrl.length;
176
+ // }
177
+ // public static boolean equal(float f, float f2) {
178
+ // return Math.abs(f2 - f) < 1.0E-5f;
179
+ // }
180
+ // public static boolean equal(double d, double d2) {
181
+ // return Math.abs(d2 - d) < 9.999999747378752E-6;
182
+ // }
183
+ // public static int positiveModulo(int n, int n2) {
184
+ // return Math.floorMod(n, n2);
185
+ // }
186
+ // public static float positiveModulo(float f, float f2) {
187
+ // return (f % f2 + f2) % f2;
188
+ // }
189
+ // public static double positiveModulo(double d, double d2) {
190
+ // return (d % d2 + d2) % d2;
191
+ // }
192
+ // public static int wrapDegrees(int n) {
193
+ // int n2 = n % 360;
194
+ // if (n2 >= 180) {
195
+ // n2 -= 360;
196
+ // }
197
+ // if (n2 < -180) {
198
+ // n2 += 360;
199
+ // }
200
+ // return n2;
201
+ // }
202
+ // public static float wrapDegrees(float f) {
203
+ // float f2 = f % 360.0f;
204
+ // if (f2 >= 180.0f) {
205
+ // f2 -= 360.0f;
206
+ // }
207
+ // if (f2 < -180.0f) {
208
+ // f2 += 360.0f;
209
+ // }
210
+ // return f2;
211
+ // }
212
+ // public static double wrapDegrees(double d) {
213
+ // double d2 = d % 360.0;
214
+ // if (d2 >= 180.0) {
215
+ // d2 -= 360.0;
216
+ // }
217
+ // if (d2 < -180.0) {
218
+ // d2 += 360.0;
219
+ // }
220
+ // return d2;
221
+ // }
222
+ // public static float degreesDifference(float f, float f2) {
223
+ // return Mth.wrapDegrees(f2 - f);
224
+ // }
225
+ // public static float degreesDifferenceAbs(float f, float f2) {
226
+ // return Mth.abs(Mth.degreesDifference(f, f2));
227
+ // }
228
+ // public static float rotateIfNecessary(float f, float f2, float f3) {
229
+ // float f4 = Mth.degreesDifference(f, f2);
230
+ // float f5 = Mth.clamp(f4, -f3, f3);
231
+ // return f2 - f5;
232
+ // }
233
+ // public static float approach(float f, float f2, float f3) {
234
+ // f3 = Mth.abs(f3);
235
+ // if (f < f2) {
236
+ // return Mth.clamp(f + f3, f, f2);
237
+ // }
238
+ // return Mth.clamp(f - f3, f2, f);
239
+ // }
240
+ // public static float approachDegrees(float f, float f2, float f3) {
241
+ // float f4 = Mth.degreesDifference(f, f2);
242
+ // return Mth.approach(f, f + f4, f3);
243
+ // }
244
+ // public static int getInt(String string, int n) {
245
+ // return NumberUtils.toInt((String)string, (int)n);
246
+ // }
247
+ // public static int getInt(String string, int n, int n2) {
248
+ // return Math.max(n2, Mth.getInt(string, n));
249
+ // }
250
+ // public static double getDouble(String string, double d) {
251
+ // try {
252
+ // return Double.parseDouble(string);
253
+ // }
254
+ // catch (Throwable throwable) {
255
+ // return d;
256
+ // }
257
+ // }
258
+ // public static double getDouble(String string, double d, double d2) {
259
+ // return Math.max(d2, Mth.getDouble(string, d));
260
+ // }
261
+ // public static int smallestEncompassingPowerOfTwo(int n) {
262
+ // int n2 = n - 1;
263
+ // n2 |= n2 >> 1;
264
+ // n2 |= n2 >> 2;
265
+ // n2 |= n2 >> 4;
266
+ // n2 |= n2 >> 8;
267
+ // n2 |= n2 >> 16;
268
+ // return n2 + 1;
269
+ // }
270
+ // public static boolean isPowerOfTwo(int n) {
271
+ // return n != 0 && (n & n - 1) == 0;
272
+ // }
273
+ // public static int ceillog2(int n) {
274
+ // n = Mth.isPowerOfTwo(n) ? n : Mth.smallestEncompassingPowerOfTwo(n);
275
+ // return MULTIPLY_DE_BRUIJN_BIT_POSITION[(int)((long)n * 125613361L >> 27) & 0x1F];
276
+ // }
277
+ // public static int log2(int n) {
278
+ // return Mth.ceillog2(n) - (Mth.isPowerOfTwo(n) ? 0 : 1);
279
+ // }
280
+ // public static int color(float f, float f2, float f3) {
281
+ // return Mth.color(Mth.floor(f * 255.0f), Mth.floor(f2 * 255.0f), Mth.floor(f3 * 255.0f));
282
+ // }
283
+ // public static int color(int n, int n2, int n3) {
284
+ // int n4 = n;
285
+ // n4 = (n4 << 8) + n2;
286
+ // n4 = (n4 << 8) + n3;
287
+ // return n4;
288
+ // }
289
+ // public static int colorMultiply(int n, int n2) {
290
+ // int n3 = (n & 0xFF0000) >> 16;
291
+ // int n4 = (n2 & 0xFF0000) >> 16;
292
+ // int n5 = (n & 0xFF00) >> 8;
293
+ // int n6 = (n2 & 0xFF00) >> 8;
294
+ // int n7 = (n & 0xFF) >> 0;
295
+ // int n8 = (n2 & 0xFF) >> 0;
296
+ // int n9 = (int)((float)n3 * (float)n4 / 255.0f);
297
+ // int n10 = (int)((float)n5 * (float)n6 / 255.0f);
298
+ // int n11 = (int)((float)n7 * (float)n8 / 255.0f);
299
+ // return n & 0xFF000000 | n9 << 16 | n10 << 8 | n11;
300
+ // }
301
+ // public static int colorMultiply(int n, float f, float f2, float f3) {
302
+ // int n2 = (n & 0xFF0000) >> 16;
303
+ // int n3 = (n & 0xFF00) >> 8;
304
+ // int n4 = (n & 0xFF) >> 0;
305
+ // int n5 = (int)((float)n2 * f);
306
+ // int n6 = (int)((float)n3 * f2);
307
+ // int n7 = (int)((float)n4 * f3);
308
+ // return n & 0xFF000000 | n5 << 16 | n6 << 8 | n7;
309
+ // }
310
+ // public static float frac(float f) {
311
+ // return f - (float)Mth.floor(f);
312
+ // }
313
+ // public static double frac(double d) {
314
+ // return d - (double)Mth.lfloor(d);
315
+ // }
316
+ // public static Vec3 catmullRomSplinePos(Vec3 vec3, Vec3 vec32, Vec3 vec33, Vec3 vec34, double d) {
317
+ // double d2 = ((-d + 2.0) * d - 1.0) * d * 0.5;
318
+ // double d3 = ((3.0 * d - 5.0) * d * d + 2.0) * 0.5;
319
+ // double d4 = ((-3.0 * d + 4.0) * d + 1.0) * d * 0.5;
320
+ // double d5 = (d - 1.0) * d * d * 0.5;
321
+ // return new Vec3(vec3.x * d2 + vec32.x * d3 + vec33.x * d4 + vec34.x * d5, vec3.y * d2 + vec32.y * d3 + vec33.y * d4 + vec34.y * d5, vec3.z * d2 + vec32.z * d3 + vec33.z * d4 + vec34.z * d5);
322
+ // }
323
+ // public static long getSeed(Vec3i vec3i) {
324
+ // return Mth.getSeed(vec3i.getX(), vec3i.getY(), vec3i.getZ());
325
+ // }
326
+ // public static long getSeed(int n, int n2, int n3) {
327
+ // long l = (long)(n * 3129871) ^ (long)n3 * 116129781L ^ (long)n2;
328
+ // l = l * l * 42317861L + l * 11L;
329
+ // return l >> 16;
330
+ // }
331
+ // public static UUID createInsecureUUID(Random random) {
332
+ // long l = random.nextLong() & 0xFFFFFFFFFFFF0FFFL | 0x4000L;
333
+ // long l2 = random.nextLong() & 0x3FFFFFFFFFFFFFFFL | Long.MIN_VALUE;
334
+ // return new UUID(l, l2);
335
+ // }
336
+ // public static UUID createInsecureUUID() {
337
+ // return Mth.createInsecureUUID(RANDOM);
338
+ // }
339
+ // public static double inverseLerp(double d, double d2, double d3) {
340
+ // return (d - d2) / (d3 - d2);
341
+ // }
342
+ // public static boolean rayIntersectsAABB(Vec3 vec3, Vec3 vec32, AABB aABB) {
343
+ // double d = (aABB.minX + aABB.maxX) * 0.5;
344
+ // double d2 = (aABB.maxX - aABB.minX) * 0.5;
345
+ // double d3 = vec3.x - d;
346
+ // if (Math.abs(d3) > d2 && d3 * vec32.x >= 0.0) {
347
+ // return false;
348
+ // }
349
+ // double d4 = (aABB.minY + aABB.maxY) * 0.5;
350
+ // double d5 = (aABB.maxY - aABB.minY) * 0.5;
351
+ // double d6 = vec3.y - d4;
352
+ // if (Math.abs(d6) > d5 && d6 * vec32.y >= 0.0) {
353
+ // return false;
354
+ // }
355
+ // double d7 = (aABB.minZ + aABB.maxZ) * 0.5;
356
+ // double d8 = (aABB.maxZ - aABB.minZ) * 0.5;
357
+ // double d9 = vec3.z - d7;
358
+ // if (Math.abs(d9) > d8 && d9 * vec32.z >= 0.0) {
359
+ // return false;
360
+ // }
361
+ // double d10 = Math.abs(vec32.x);
362
+ // double d11 = Math.abs(vec32.y);
363
+ // double d12 = Math.abs(vec32.z);
364
+ // double d13 = vec32.y * d9 - vec32.z * d6;
365
+ // if (Math.abs(d13) > d5 * d12 + d8 * d11) {
366
+ // return false;
367
+ // }
368
+ // d13 = vec32.z * d3 - vec32.x * d9;
369
+ // if (Math.abs(d13) > d2 * d12 + d8 * d10) {
370
+ // return false;
371
+ // }
372
+ // d13 = vec32.x * d6 - vec32.y * d3;
373
+ // return Math.abs(d13) < d2 * d11 + d5 * d10;
374
+ // }
375
+ // public static double atan2(double d, double d2) {
376
+ // boolean bl;
377
+ // boolean bl2;
378
+ // double d3;
379
+ // boolean bl3;
380
+ // double d4 = d2 * d2 + d * d;
381
+ // if (Double.isNaN(d4)) {
382
+ // return Double.NaN;
383
+ // }
384
+ // boolean bl4 = bl = d < 0.0;
385
+ // if (bl) {
386
+ // d = -d;
387
+ // }
388
+ // boolean bl5 = bl3 = d2 < 0.0;
389
+ // if (bl3) {
390
+ // d2 = -d2;
391
+ // }
392
+ // boolean bl6 = bl2 = d > d2;
393
+ // if (bl2) {
394
+ // d3 = d2;
395
+ // d2 = d;
396
+ // d = d3;
397
+ // }
398
+ // d3 = Mth.fastInvSqrt(d4);
399
+ // double d5 = FRAC_BIAS + (d *= d3);
400
+ // int n = (int)Double.doubleToRawLongBits(d5);
401
+ // double d6 = ASIN_TAB[n];
402
+ // double d7 = COS_TAB[n];
403
+ // double d8 = d5 - FRAC_BIAS;
404
+ // double d9 = d * d7 - (d2 *= d3) * d8;
405
+ // double d10 = (6.0 + d9 * d9) * d9 * 0.16666666666666666;
406
+ // double d11 = d6 + d10;
407
+ // if (bl2) {
408
+ // d11 = 1.5707963267948966 - d11;
409
+ // }
410
+ // if (bl3) {
411
+ // d11 = 3.141592653589793 - d11;
412
+ // }
413
+ // if (bl) {
414
+ // d11 = -d11;
415
+ // }
416
+ // return d11;
417
+ // }
418
+ // public static float fastInvSqrt(float f) {
419
+ // float f2 = 0.5f * f;
420
+ // int n = Float.floatToIntBits(f);
421
+ // n = 1597463007 - (n >> 1);
422
+ // f = Float.intBitsToFloat(n);
423
+ // f *= 1.5f - f2 * f * f;
424
+ // return f;
425
+ // }
426
+ // public static double fastInvSqrt(double d) {
427
+ // double d2 = 0.5 * d;
428
+ // long l = Double.doubleToRawLongBits(d);
429
+ // l = 6910469410427058090L - (l >> 1);
430
+ // d = Double.longBitsToDouble(l);
431
+ // d *= 1.5 - d2 * d * d;
432
+ // return d;
433
+ // }
434
+ // public static float fastInvCubeRoot(float f) {
435
+ // int n = Float.floatToIntBits(f);
436
+ // n = 1419967116 - n / 3;
437
+ // float f2 = Float.intBitsToFloat(n);
438
+ // f2 = 0.6666667f * f2 + 1.0f / (3.0f * f2 * f2 * f);
439
+ // f2 = 0.6666667f * f2 + 1.0f / (3.0f * f2 * f2 * f);
440
+ // return f2;
441
+ // }
442
+ // public static int hsvToRgb(float f, float f2, float f3) {
443
+ // float f4;
444
+ // float f5;
445
+ // int n = (int)(f * 6.0f) % 6;
446
+ // float f6 = f * 6.0f - (float)n;
447
+ // float f7 = f3 * (1.0f - f2);
448
+ // float f8 = f3 * (1.0f - f6 * f2);
449
+ // float f9 = f3 * (1.0f - (1.0f - f6) * f2);
450
+ // float f10 = switch (n) {
451
+ // case 0 -> {
452
+ // f4 = f3;
453
+ // f5 = f9;
454
+ // break f7;
455
+ // }
456
+ // case 1 -> {
457
+ // f4 = f8;
458
+ // f5 = f3;
459
+ // break f7;
460
+ // }
461
+ // case 2 -> {
462
+ // f4 = f7;
463
+ // f5 = f3;
464
+ // break f9;
465
+ // }
466
+ // case 3 -> {
467
+ // f4 = f7;
468
+ // f5 = f8;
469
+ // break f3;
470
+ // }
471
+ // case 4 -> {
472
+ // f4 = f9;
473
+ // f5 = f7;
474
+ // break f3;
475
+ // }
476
+ // case 5 -> {
477
+ // f4 = f3;
478
+ // f5 = f7;
479
+ // break f8;
480
+ // }
481
+ // default -> throw new java.lang.RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + f + ", " + f2 + ", " + f3);
482
+ // };
483
+ // int n2 = Mth.clamp((int)(f4 * 255.0f), 0, 255);
484
+ // int n3 = Mth.clamp((int)(f5 * 255.0f), 0, 255);
485
+ // int n4 = Mth.clamp((int)(f10 * 255.0f), 0, 255);
486
+ // return n2 << 16 | n3 << 8 | n4;
487
+ // }
488
+ // public static int murmurHash3Mixer(int n) {
489
+ // n ^= n >>> 16;
490
+ // n *= -2048144789;
491
+ // n ^= n >>> 13;
492
+ // n *= -1028477387;
493
+ // n ^= n >>> 16;
494
+ // return n;
495
+ // }
496
+ // public static long murmurHash3Mixer(long l) {
497
+ // l ^= l >>> 33;
498
+ // l *= -49064778989728563L;
499
+ // l ^= l >>> 33;
500
+ // l *= -4265267296055464877L;
501
+ // l ^= l >>> 33;
502
+ // return l;
503
+ // }
504
+ // public static double[] cumulativeSum(double ... arrd) {
505
+ // float f = 0.0f;
506
+ // for (double d : arrd) {
507
+ // f = (float)((double)f + d);
508
+ // }
509
+ // int n = 0;
510
+ // while (n < arrd.length) {
511
+ // double[] arrd2 = arrd;
512
+ // int n2 = n++;
513
+ // arrd2[n2] = arrd2[n2] / (double)f;
514
+ // }
515
+ // for (n = 0; n < arrd.length; ++n) {
516
+ // arrd[n] = (n == 0 ? 0.0 : arrd[n - 1]) + arrd[n];
517
+ // }
518
+ // return arrd;
519
+ // }
520
+ // public static int getRandomForDistributionIntegral(Random random, double[] arrd) {
521
+ // double d = random.nextDouble();
522
+ // for (int i = 0; i < arrd.length; ++i) {
523
+ // if (!(d < arrd[i])) continue;
524
+ // return i;
525
+ // }
526
+ // return arrd.length;
527
+ // }
528
+ // public static double[] binNormalDistribution(double d, double d2, double d3, int n, int n2) {
529
+ // double[] arrd = new double[n2 - n + 1];
530
+ // int n3 = 0;
531
+ // for (int i = n; i <= n2; ++i) {
532
+ // arrd[n3] = Math.max(0.0, d * StrictMath.exp(-((double)i - d3) * ((double)i - d3) / (2.0 * d2 * d2)));
533
+ // ++n3;
534
+ // }
535
+ // return arrd;
536
+ // }
537
+ // public static double[] binBiModalNormalDistribution(double d, double d2, double d3, double d4, double d5, double d6, int n, int n2) {
538
+ // double[] arrd = new double[n2 - n + 1];
539
+ // int n3 = 0;
540
+ // for (int i = n; i <= n2; ++i) {
541
+ // arrd[n3] = Math.max(0.0, d * StrictMath.exp(-((double)i - d3) * ((double)i - d3) / (2.0 * d2 * d2)) + d4 * StrictMath.exp(-((double)i - d6) * ((double)i - d6) / (2.0 * d5 * d5)));
542
+ // ++n3;
543
+ // }
544
+ // return arrd;
545
+ // }
546
+ // public static double[] binLogDistribution(double d, double d2, int n, int n2) {
547
+ // double[] arrd = new double[n2 - n + 1];
548
+ // int n3 = 0;
549
+ // for (int i = n; i <= n2; ++i) {
550
+ // arrd[n3] = Math.max(d * StrictMath.log(i) + d2, 0.0);
551
+ // ++n3;
552
+ // }
553
+ // return arrd;
554
+ // }
555
+ // public static int binarySearch(int n, int n2, IntPredicate intPredicate) {
556
+ // int n3 = n2 - n;
557
+ // while (n3 > 0) {
558
+ // int n4 = n3 / 2;
559
+ // int n5 = n + n4;
560
+ // if (intPredicate.test(n5)) {
561
+ // n3 = n4;
562
+ // continue;
563
+ // }
564
+ // n = n5 + 1;
565
+ // n3 -= n4 + 1;
566
+ // }
567
+ // return n;
568
+ // }
569
+ // public static float lerp(float f, float f2, float f3) {
570
+ // return f2 + f * (f3 - f2);
571
+ // }
572
+ // public static double lerp(double d, double d2, double d3) {
573
+ // return d2 + d * (d3 - d2);
574
+ // }
575
+ // public static double lerp2(double d, double d2, double d3, double d4, double d5, double d6) {
576
+ // return Mth.lerp(d2, Mth.lerp(d, d3, d4), Mth.lerp(d, d5, d6));
577
+ // }
578
+ // public static double lerp3(double d, double d2, double d3, double d4, double d5, double d6, double d7, double d8, double d9, double d10, double d11) {
579
+ // return Mth.lerp(d3, Mth.lerp2(d, d2, d4, d5, d6, d7), Mth.lerp2(d, d2, d8, d9, d10, d11));
580
+ // }
581
+ // public static double smoothstep(double d) {
582
+ // return d * d * d * (d * (d * 6.0 - 15.0) + 10.0);
583
+ // }
584
+ // public static double smoothstepDerivative(double d) {
585
+ // return 30.0 * d * d * (d - 1.0) * (d - 1.0);
586
+ // }
587
+ // public static int sign(double d) {
588
+ // if (d == 0.0) {
589
+ // return 0;
590
+ // }
591
+ // return d > 0.0 ? 1 : -1;
592
+ // }
593
+ // public static float rotLerp(float f, float f2, float f3) {
594
+ // return f2 + f * Mth.wrapDegrees(f3 - f2);
595
+ // }
596
+ // public static float diffuseLight(float f, float f2, float f3) {
597
+ // return Math.min(f * f * 0.6f + f2 * f2 * ((3.0f + f2) / 4.0f) + f3 * f3 * 0.8f, 1.0f);
598
+ // }
599
+ // @Deprecated
600
+ // public static float rotlerp(float f, float f2, float f3) {
601
+ // float f4;
602
+ // for (f4 = f2 - f; f4 < -180.0f; f4 += 360.0f) {
603
+ // }
604
+ // while (f4 >= 180.0f) {
605
+ // f4 -= 360.0f;
606
+ // }
607
+ // return f + f3 * f4;
608
+ // }
609
+ // @Deprecated
610
+ // public static float rotWrap(double d) {
611
+ // while (d >= 180.0) {
612
+ // d -= 360.0;
613
+ // }
614
+ // while (d < -180.0) {
615
+ // d += 360.0;
616
+ // }
617
+ // return (float)d;
618
+ // }
619
+ // public static float triangleWave(float f, float f2) {
620
+ // return (Math.abs(f % f2 - f2 * 0.5f) - f2 * 0.25f) / (f2 * 0.25f);
621
+ // }
622
+ // public static float square(float f) {
623
+ // return f * f;
624
+ // }
625
+ // public static double square(double d) {
626
+ // return d * d;
627
+ // }
628
+ // public static int square(int n) {
629
+ // return n * n;
630
+ // }
631
+ // public static double clampedMap(double d, double d2, double d3, double d4, double d5) {
632
+ // return Mth.clampedLerp(d4, d5, Mth.inverseLerp(d, d2, d3));
633
+ // }
634
+ // public static double map(double d, double d2, double d3, double d4, double d5) {
635
+ // return Mth.lerp(Mth.inverseLerp(d, d2, d3), d4, d5);
636
+ // }
637
+ // public static double wobble(double d) {
638
+ // return d + (2.0 * new Random(Mth.floor(d * 3000.0)).nextDouble() - 1.0) * 1.0E-7 / 2.0;
639
+ // }
640
+ // public static int roundToward(int n, int n2) {
641
+ // return (n + n2 - 1) / n2 * n2;
642
+ // }
643
+ // public static int randomBetweenInclusive(Random random, int n, int n2) {
644
+ // return random.nextInt(n2 - n + 1) + n;
645
+ // }
646
+ // public static float randomBetween(Random random, float f, float f2) {
647
+ // return random.nextFloat() * (f2 - f) + f;
648
+ // }
649
+ // public static float normal(Random random, float f, float f2) {
650
+ // return f + (float)random.nextGaussian() * f2;
651
+ // }
652
+ // public static double length(int n, double d, int n2) {
653
+ // return Math.sqrt((double)(n * n) + d * d + (double)(n2 * n2));
654
+ // }
655
+ // static {
656
+ // for (int i = 0; i < 257; ++i) {
657
+ // double d = (double)i / 256.0;
658
+ // double d2 = Math.asin(d);
659
+ // Mth.COS_TAB[i] = Math.cos(d2);
660
+ // Mth.ASIN_TAB[i] = d2;
661
+ // }
662
+ // }
663
+ // }
@@ -41,6 +41,15 @@ export declare class EntityFunctions {
41
41
  getDistanceToEntity(entity: Entity): number;
42
42
  getDistanceBetweenEntities(first: Entity, second: Entity): number;
43
43
  getEntityAABB(entity: {
44
+ type: string;
45
+ position: Vec3;
46
+ height: number;
47
+ width?: number;
48
+ }): AABB;
49
+ getPlayerAABB(entity: {
50
+ position: Vec3;
51
+ }): AABB;
52
+ getEntityAABBRaw(entity: {
44
53
  position: Vec3;
45
54
  height: number;
46
55
  width?: number;
@@ -31,7 +31,7 @@ class EntityFunctions {
31
31
  * @returns boolean
32
32
  */
33
33
  isMainHandActive(entity) {
34
- return (entity !== null && entity !== void 0 ? entity : this.bot.entity).metadata[6] === 1; //as any & (1 | 0)) === (1 | 0);
34
+ return (entity !== null && entity !== void 0 ? entity : this.bot.entity).metadata[6] === 2; //as any & (1 | 0)) === (1 | 0);
35
35
  }
36
36
  /**
37
37
  * TODO: Version specific right now. Generalize. Unknown method.
@@ -40,7 +40,7 @@ class EntityFunctions {
40
40
  * @returns boolean
41
41
  */
42
42
  isOffHandActive(entity) {
43
- return (entity !== null && entity !== void 0 ? entity : this.bot.entity).metadata[6] === 1; //& (1 | 2)) === (1 | 2);
43
+ return (entity !== null && entity !== void 0 ? entity : this.bot.entity).metadata[6] === 3; //& (1 | 2)) === (1 | 2);
44
44
  }
45
45
  /**
46
46
  * TODO: Version specific right now. Generalize. Unknown method.
@@ -55,8 +55,6 @@ class EntityFunctions {
55
55
  let health = Number(metadata[healthSlot]);
56
56
  if (!health || health === 0)
57
57
  health = entity === this.bot.entity ? (_a = this.bot.entity.health) !== null && _a !== void 0 ? _a : 0 : 0;
58
- if (health === 0)
59
- console.log(this.healthSlot, entity.metadata);
60
58
  // console.log(health + (Number(metadata[this.healthSlot + 4]) ?? 0))
61
59
  return health + ((_b = Number(metadata[this.healthSlot + 4])) !== null && _b !== void 0 ? _b : 0);
62
60
  }
@@ -67,7 +65,7 @@ class EntityFunctions {
67
65
  */
68
66
  getHealthFromMetadata(metadata) {
69
67
  var _a;
70
- return (_a = (Number(metadata[this.healthSlot]) + Number(metadata[this.healthSlot + 4]))) !== null && _a !== void 0 ? _a : undefined;
68
+ return (_a = Number(metadata[this.healthSlot]) + Number(metadata[this.healthSlot + 4])) !== null && _a !== void 0 ? _a : undefined;
71
69
  }
72
70
  /**
73
71
  * TODO: Version specific right now. Generalize. Unknown method.
@@ -87,11 +85,23 @@ class EntityFunctions {
87
85
  }
88
86
  getEntityAABB(entity) {
89
87
  var _a;
90
- const w = (_a = entity.width) !== null && _a !== void 0 ? _a : entity.height / 2;
88
+ switch (entity.type) {
89
+ case "player":
90
+ return this.getPlayerAABB({ position: entity.position });
91
+ case "mob":
92
+ default:
93
+ //TODO: Implement better AABBs. However, this may just be correct.
94
+ return this.getEntityAABBRaw({ position: entity.position, height: entity.height, width: (_a = entity.width) !== null && _a !== void 0 ? _a : entity.height });
95
+ }
96
+ }
97
+ getPlayerAABB(entity) {
98
+ return this.getEntityAABBRaw({ position: entity.position, height: 1.8, width: 0.6 });
99
+ }
100
+ getEntityAABBRaw(entity) {
101
+ const w = entity.width ? entity.width / 2 : entity.height / 2;
91
102
  const { x, y, z } = entity.position;
92
103
  return new aabb_1.AABB(-w, 0, -w, w, entity.height, w).offset(x, y, z);
93
104
  }
94
- //Stolen from mineflayer.
95
105
  parseMetadata(packetMetadata, entityMetadata = {}) {
96
106
  if (packetMetadata !== undefined) {
97
107
  for (const { key, value } of packetMetadata) {
@@ -0,0 +1 @@
1
+ export {};
package/lib/example.js ADDED
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ var _a, _b;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ const mineflayer_1 = require("mineflayer");
17
+ const index_1 = __importDefault(require("./index"));
18
+ const vec3_1 = require("vec3");
19
+ let target;
20
+ const bot = (0, mineflayer_1.createBot)({
21
+ username: "utilTesting",
22
+ host: (_a = process.argv[2]) !== null && _a !== void 0 ? _a : "localhost",
23
+ port: (_b = Number(process.argv[3])) !== null && _b !== void 0 ? _b : 25565,
24
+ version: "1.17.1",
25
+ });
26
+ bot.loadPlugin(index_1.default);
27
+ const emptyVec = new vec3_1.Vec3(0, 0, 0);
28
+ bot.on("chat", (username, message) => __awaiter(void 0, void 0, void 0, function* () {
29
+ var _c;
30
+ const split = message.split(" ");
31
+ switch (split[0]) {
32
+ case "look":
33
+ target = bot.nearestEntity((e) => { var _a; return ((_a = e.username) !== null && _a !== void 0 ? _a : e.name) === split[1]; });
34
+ if (!target)
35
+ return console.log("no entity");
36
+ bot.util.move.forceLookAt(target.position, true);
37
+ break;
38
+ case "equip":
39
+ const item = bot.util.inv.getAllItems().find((i) => i.name.includes(split[1]));
40
+ if (!item)
41
+ return console.log("no item");
42
+ if (["hand", "off-hand"].includes(split[2])) {
43
+ bot.util.inv.customEquip(item, split[2]);
44
+ }
45
+ break;
46
+ case "health":
47
+ const health = bot.util.entity.getHealth();
48
+ bot.chat(`${health}`);
49
+ break;
50
+ case "WhatAmILookingAt":
51
+ target = bot.nearestEntity((e) => { var _a; return ((_a = e.username) !== null && _a !== void 0 ? _a : e.name) === username; });
52
+ if (!target)
53
+ return console.log("no entity");
54
+ const player = bot.util.raytrace.entityAtEntityCursor(target, 256);
55
+ if (player) {
56
+ console.log(player);
57
+ bot.chat(`${(_c = player.username) !== null && _c !== void 0 ? _c : player.name} at ${player.position}`);
58
+ }
59
+ else {
60
+ const block = bot.util.raytrace.blockAtEntityCursor(target, 256); //includes face and intersect. That's very nice.
61
+ if (block) {
62
+ console.log(block);
63
+ bot.chat(`${block.name} at ${block.position}`);
64
+ }
65
+ else {
66
+ bot.chat("You're not looking at anything.");
67
+ }
68
+ }
69
+ break;
70
+ case "come":
71
+ target = bot.nearestEntity((e) => { var _a; return ((_a = e.username) !== null && _a !== void 0 ? _a : e.name) === username; });
72
+ if (!target)
73
+ return console.log("no entity");
74
+ if (!bot.pathfinder)
75
+ bot.chat("pathfinder is not loaded!");
76
+ bot.util.move.followEntityWithRespectRange(target, 1);
77
+ break;
78
+ case "follow":
79
+ target = bot.nearestEntity((e) => { var _a; return ((_a = e.username) !== null && _a !== void 0 ? _a : e.name) === split[1]; });
80
+ if (!target)
81
+ return console.log("no entity");
82
+ if (!bot.pathfinder)
83
+ bot.chat("pathfinder is not loaded!");
84
+ bot.util.move.followEntityWithRespectRange(target, 1);
85
+ break;
86
+ case "stop":
87
+ if (!bot.pathfinder)
88
+ bot.chat("pathfinder is not loaded!");
89
+ bot.util.move.stop();
90
+ break;
91
+ default:
92
+ console.log(username, bot.entity.username);
93
+ if (username !== bot.entity.username)
94
+ bot.chat("unknown command: " + message);
95
+ break;
96
+ }
97
+ }));
package/lib/index.d.ts CHANGED
@@ -15,15 +15,8 @@ declare module "mineflayer" {
15
15
  }
16
16
  }
17
17
  declare module "prismarine-entity" {
18
- interface Entity {
19
- attributes: {
20
- [index: string]: {
21
- value: number;
22
- modifiers: any[];
23
- };
24
- };
25
- }
26
18
  }
27
19
  export default function inject(bot: Bot): void;
28
20
  export { AABB } from "./calcs/aabb";
29
21
  export { InterceptFunctions } from "./calcs/intercept";
22
+ export { AABBUtils, MathUtils } from "./static";
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InterceptFunctions = exports.AABB = void 0;
3
+ exports.MathUtils = exports.AABBUtils = exports.InterceptFunctions = exports.AABB = void 0;
4
4
  const utilFunctions_1 = require("./utilFunctions");
5
5
  const mineflayer_pathfinder_1 = require("mineflayer-pathfinder");
6
6
  function inject(bot) {
@@ -13,3 +13,6 @@ var aabb_1 = require("./calcs/aabb");
13
13
  Object.defineProperty(exports, "AABB", { enumerable: true, get: function () { return aabb_1.AABB; } });
14
14
  var intercept_1 = require("./calcs/intercept");
15
15
  Object.defineProperty(exports, "InterceptFunctions", { enumerable: true, get: function () { return intercept_1.InterceptFunctions; } });
16
+ var static_1 = require("./static");
17
+ Object.defineProperty(exports, "AABBUtils", { enumerable: true, get: function () { return static_1.AABBUtils; } });
18
+ Object.defineProperty(exports, "MathUtils", { enumerable: true, get: function () { return static_1.MathUtils; } });
@@ -37,7 +37,7 @@ export declare class MovementFunctions {
37
37
  * @returns have the goals changed
38
38
  */
39
39
  followEntityWithRespectRange(entity: Entity, followDistance: number, invertDistance?: number): boolean;
40
- forceLook(yaw: number, pitch: number, onGround?: boolean, update?: boolean): void;
41
- forceLookAt(pos: Vec3, onGround?: boolean, update?: boolean): void;
40
+ forceLook(yaw: number, pitch: number, update?: boolean, onGround?: boolean): void;
41
+ forceLookAt(pos: Vec3, update?: boolean, onGround?: boolean): void;
42
42
  lazyTeleport(endPos: Vec3): void;
43
43
  }
@@ -92,23 +92,19 @@ class MovementFunctions {
92
92
  }
93
93
  return false;
94
94
  }
95
- forceLook(yaw, pitch, onGround, update = false) {
95
+ forceLook(yaw, pitch, update = false, onGround) {
96
96
  const notchianYawAndPitch = { yaw: this.bot.util.math.toNotchianYaw(yaw), pitch: this.bot.util.math.toNotchianPitch(pitch) };
97
97
  this.bot._client.write("look", Object.assign(Object.assign({}, notchianYawAndPitch), { onGround: onGround !== null && onGround !== void 0 ? onGround : this.bot.entity.onGround }));
98
98
  if (update) {
99
- this.bot.entity.yaw = yaw;
100
- this.bot.entity.pitch = pitch;
101
- // this.bot.look(yaw, pitch, true);
99
+ this.bot.look(yaw, pitch, true);
102
100
  }
103
101
  }
104
- forceLookAt(pos, onGround, update = false) {
102
+ forceLookAt(pos, update = false, onGround) {
105
103
  const { yaw, pitch } = this.bot.util.math.pointToYawAndPitch(this.bot, pos);
106
104
  const nyp = { yaw: this.bot.util.math.toNotchianYaw(yaw), pitch: this.bot.util.math.toNotchianPitch(pitch) };
107
105
  this.bot._client.write("look", Object.assign(Object.assign({}, nyp), { onGround: onGround !== null && onGround !== void 0 ? onGround : this.bot.entity.onGround }));
108
106
  if (update) {
109
- this.bot.entity.yaw = yaw;
110
- this.bot.entity.pitch = pitch;
111
- // this.bot.look(yaw, pitch, true);
107
+ this.bot.look(yaw, pitch, true);
112
108
  }
113
109
  }
114
110
  lazyTeleport(endPos) { }
@@ -0,0 +1,21 @@
1
+ import type { Block } from "prismarine-block";
2
+ import { AABB } from "../calcs/aabb";
3
+ import type { Vec3 } from "vec3";
4
+ export declare namespace AABBUtils {
5
+ function getBlockAABB(block: Block, height?: number): AABB;
6
+ function getBlockPosAABB(block: Vec3, height?: number): AABB;
7
+ function getEntityAABB(entity: {
8
+ type: string;
9
+ position: Vec3;
10
+ height: number;
11
+ width?: number;
12
+ }): AABB;
13
+ function getPlayerAABB(entity: {
14
+ position: Vec3;
15
+ }): AABB;
16
+ function getEntityAABBRaw(entity: {
17
+ position: Vec3;
18
+ height: number;
19
+ width?: number;
20
+ }): AABB;
21
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AABBUtils = void 0;
4
+ const aabb_1 = require("../calcs/aabb");
5
+ var AABBUtils;
6
+ (function (AABBUtils) {
7
+ function getBlockAABB(block, height = 1) {
8
+ const { x, y, z } = block.position;
9
+ return new aabb_1.AABB(x, y, z, x + 1, y + height, z + 1);
10
+ }
11
+ AABBUtils.getBlockAABB = getBlockAABB;
12
+ function getBlockPosAABB(block, height = 1) {
13
+ const { x, y, z } = block.floored();
14
+ return new aabb_1.AABB(x, y, z, x + 1, y + height, z + 1);
15
+ }
16
+ AABBUtils.getBlockPosAABB = getBlockPosAABB;
17
+ function getEntityAABB(entity) {
18
+ var _a;
19
+ switch (entity.type) {
20
+ case "player":
21
+ return getPlayerAABB({ position: entity.position });
22
+ case "mob":
23
+ default: //TODO: Implement better AABBs. However, this may just be correct.
24
+ return getEntityAABBRaw({ position: entity.position, height: entity.height, width: (_a = entity.width) !== null && _a !== void 0 ? _a : entity.height });
25
+ }
26
+ }
27
+ AABBUtils.getEntityAABB = getEntityAABB;
28
+ function getPlayerAABB(entity) {
29
+ return getEntityAABBRaw({ position: entity.position, height: 1.8, width: 0.6 });
30
+ }
31
+ AABBUtils.getPlayerAABB = getPlayerAABB;
32
+ function getEntityAABBRaw(entity) {
33
+ const w = entity.width ? entity.width / 2 : entity.height / 2;
34
+ const { x, y, z } = entity.position;
35
+ return new aabb_1.AABB(-w, 0, -w, w, entity.height, w).offset(x, y, z);
36
+ }
37
+ AABBUtils.getEntityAABBRaw = getEntityAABBRaw;
38
+ })(AABBUtils = exports.AABBUtils || (exports.AABBUtils = {}));
@@ -0,0 +1,2 @@
1
+ export * from "./aabbUtil";
2
+ export * from "./mathUtil";
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./aabbUtil"), exports);
14
+ __exportStar(require("./mathUtil"), exports);
@@ -0,0 +1,24 @@
1
+ import { Bot } from "mineflayer";
2
+ import { Vec3 } from "vec3";
3
+ export declare namespace MathUtils {
4
+ const toNotchianYaw: (yaw: number) => number;
5
+ const toNotchianPitch: (pitch: number) => number;
6
+ const fromNotchianYawByte: (yaw: number) => number;
7
+ const fromNotchianPitchByte: (pitch: number) => number;
8
+ function euclideanMod(numerator: number, denominator: number): number;
9
+ function toRadians(degrees: number): number;
10
+ function toDegrees(radians: number): number;
11
+ function fromNotchianYaw(yaw: number): number;
12
+ function fromNotchianPitch(pitch: number): number;
13
+ function fromNotchVelocity(vel: Vec3): Vec3;
14
+ function pointToYawAndPitch(bot: Bot, point: Vec3): {
15
+ yaw: number;
16
+ pitch: number;
17
+ };
18
+ function dirToYawAndPitch(dir: Vec3): {
19
+ yaw: number;
20
+ pitch: number;
21
+ };
22
+ function getYaw(origin: Vec3, destination: Vec3): number;
23
+ function yawPitchAndSpeedToDir(yaw: number, pitch: number, speed: number): Vec3;
24
+ }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MathUtils = void 0;
4
+ const vec3_1 = require("vec3");
5
+ const PI = Math.PI;
6
+ const PI_2 = Math.PI * 2;
7
+ const TO_RAD = PI / 180;
8
+ const TO_DEG = 1 / TO_RAD;
9
+ const FROM_NOTCH_BYTE = 360 / 256;
10
+ // From wiki.vg: Velocity is believed to be in units of 1/8000 of a block per server tick (50ms)
11
+ const FROM_NOTCH_VEL = 1 / 8000;
12
+ var MathUtils;
13
+ (function (MathUtils) {
14
+ MathUtils.toNotchianYaw = (yaw) => toDegrees(PI - yaw);
15
+ MathUtils.toNotchianPitch = (pitch) => toDegrees(-pitch);
16
+ MathUtils.fromNotchianYawByte = (yaw) => fromNotchianYaw(yaw * FROM_NOTCH_BYTE);
17
+ MathUtils.fromNotchianPitchByte = (pitch) => fromNotchianPitch(pitch * FROM_NOTCH_BYTE);
18
+ function euclideanMod(numerator, denominator) {
19
+ const result = numerator % denominator;
20
+ return result < 0 ? result + denominator : result;
21
+ }
22
+ MathUtils.euclideanMod = euclideanMod;
23
+ function toRadians(degrees) {
24
+ return TO_RAD * degrees;
25
+ }
26
+ MathUtils.toRadians = toRadians;
27
+ function toDegrees(radians) {
28
+ return TO_DEG * radians;
29
+ }
30
+ MathUtils.toDegrees = toDegrees;
31
+ function fromNotchianYaw(yaw) {
32
+ return euclideanMod(PI - toRadians(yaw), PI_2);
33
+ }
34
+ MathUtils.fromNotchianYaw = fromNotchianYaw;
35
+ function fromNotchianPitch(pitch) {
36
+ return euclideanMod(toRadians(-pitch) + PI, PI_2) - PI;
37
+ }
38
+ MathUtils.fromNotchianPitch = fromNotchianPitch;
39
+ function fromNotchVelocity(vel) {
40
+ return new vec3_1.Vec3(vel.x * FROM_NOTCH_VEL, vel.y * FROM_NOTCH_VEL, vel.z * FROM_NOTCH_VEL);
41
+ }
42
+ MathUtils.fromNotchVelocity = fromNotchVelocity;
43
+ function pointToYawAndPitch(bot, point) {
44
+ const delta = point.minus(bot.entity.position.offset(0, bot.entity.height, 0));
45
+ return dirToYawAndPitch(delta);
46
+ }
47
+ MathUtils.pointToYawAndPitch = pointToYawAndPitch;
48
+ function dirToYawAndPitch(dir) {
49
+ const yaw = Math.atan2(-dir.x, -dir.z);
50
+ const groundDistance = Math.sqrt(dir.x * dir.x + dir.z * dir.z);
51
+ const pitch = Math.atan2(dir.y, groundDistance);
52
+ return { yaw: yaw, pitch: pitch };
53
+ }
54
+ MathUtils.dirToYawAndPitch = dirToYawAndPitch;
55
+ function getYaw(origin, destination) {
56
+ const xDistance = destination.x - origin.x;
57
+ const zDistance = destination.z - origin.z;
58
+ const yaw = Math.atan2(xDistance, zDistance) + Math.PI;
59
+ return yaw;
60
+ }
61
+ MathUtils.getYaw = getYaw;
62
+ //Scuffed.
63
+ function yawPitchAndSpeedToDir(yaw, pitch, speed) {
64
+ const thetaY = PI + yaw;
65
+ const thetaP = pitch;
66
+ const x = speed * Math.sin(thetaY);
67
+ const y = speed * Math.sin(thetaP);
68
+ const z = speed * Math.cos(thetaY);
69
+ const VxMag = Math.sqrt(x * x + z * z);
70
+ const VxRatio = Math.sqrt(VxMag * VxMag - y * y);
71
+ const allRatio = VxRatio / VxMag;
72
+ return new vec3_1.Vec3(x * allRatio, y, z * allRatio);
73
+ }
74
+ MathUtils.yawPitchAndSpeedToDir = yawPitchAndSpeedToDir;
75
+ })(MathUtils = exports.MathUtils || (exports.MathUtils = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxg-org/mineflayer-util-plugin",
3
- "version": "1.3.12",
3
+ "version": "1.3.16",
4
4
  "description": "mineflayer utils for NextGEN mineflayer plugins.",
5
5
  "keywords": [
6
6
  "mineflayer",
@@ -16,7 +16,8 @@
16
16
  "types": "lib/index.d.ts",
17
17
  "scripts": {
18
18
  "build": "npx tsc",
19
- "prepublish": "npm run build"
19
+ "prepublish": "npm run build",
20
+ "test": "node --trace-warnings lib/example.js"
20
21
  },
21
22
  "dependencies": {
22
23
  "minecraft-data": "^2.97.0",