@nxg-org/mineflayer-util-plugin 1.3.13 → 1.4.0

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.
@@ -1,4 +1,7 @@
1
1
  import { Vec3 } from "vec3";
2
+ declare type AABBPoints = [minX: number, minY: number, minZ: number, maxX: number, maxY: number, maxZ: number];
3
+ declare type MinAndMaxPoints = [min: [x: number, y: number, z: number], max: [x: number, y: number, z: number]];
4
+ declare type Vec3AABB = [min: Vec3, max: Vec3];
2
5
  export declare class AABB {
3
6
  minX: number;
4
7
  minY: number;
@@ -8,19 +11,14 @@ export declare class AABB {
8
11
  maxZ: number;
9
12
  constructor(x0: number, y0: number, z0: number, x1: number, y1: number, z1: number);
10
13
  static fromVecs(min: Vec3, max: Vec3): AABB;
14
+ static fromBlock(min: Vec3): AABB;
11
15
  set(x0: number, y0: number, z0: number, x1: number, y1: number, z1: number): void;
12
16
  clone(): AABB;
13
- toArray(): number[];
14
- toMinAndMaxArrays(): {
15
- 0: number[];
16
- 1: number[];
17
- };
18
- toVecs(): {
19
- 0: Vec3;
20
- 1: Vec3;
21
- };
17
+ toArray(): AABBPoints;
18
+ toMinAndMaxArrays(): MinAndMaxPoints;
19
+ toVecs(): Vec3AABB;
22
20
  toVertices(): Vec3[];
23
- floor(): void;
21
+ floor(): this;
24
22
  extend(dx: number, dy: number, dz: number): this;
25
23
  contract(x: number, y: number, z: number): this;
26
24
  expand(x: number, y: number, z: number): this;
@@ -40,8 +38,17 @@ export declare class AABB {
40
38
  } | null;
41
39
  intersectsSegment(org: Vec3, dest: Vec3): Vec3 | null;
42
40
  distanceFromRay(origin: Vec3, direction: Vec3, xz?: boolean): number;
41
+ intersect(aABB: AABB): AABB;
43
42
  equals(other: AABB): boolean;
44
- xzDistanceTo(pos: Vec3, heightOffset?: number): number;
45
- distanceTo(pos: Vec3, heightOffset?: number): number;
43
+ xzDistanceToVec(pos: Vec3): number;
44
+ distanceToVec(pos: Vec3): number;
45
+ expandTowards(vec3: Vec3): AABB;
46
+ expandTowardsCoords(d: number, d2: number, d3: number): AABB;
47
+ moveCoords(d: number, d2: number, d3: number): AABB;
48
+ move(vec3: Vec3): AABB;
49
+ intersectsCoords(d: number, d2: number, d3: number, d4: number, d5: number, d6: number): boolean;
50
+ collidesAABB(aABB: AABB): boolean;
51
+ collidesCoords(d: number, d2: number, d3: number, d4: number, d5: number, d6: number): boolean;
52
+ getCenter(): Vec3;
46
53
  }
47
54
  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;
@@ -29,10 +35,10 @@ class AABB {
29
35
  return [this.minX, this.minY, this.minZ, this.maxX, this.maxY, this.maxZ];
30
36
  }
31
37
  toMinAndMaxArrays() {
32
- return { 0: [this.minX, this.minY, this.minZ], 1: [this.maxX, this.maxY, this.maxZ] };
38
+ return [[this.minX, this.minY, this.minZ], [this.maxX, this.maxY, this.maxZ]];
33
39
  }
34
40
  toVecs() {
35
- return { 0: new vec3_1.Vec3(this.minX, this.minY, this.minZ), 1: new vec3_1.Vec3(this.maxX, this.maxY, this.maxZ) };
41
+ return [new vec3_1.Vec3(this.minX, this.minY, this.minZ), new vec3_1.Vec3(this.maxX, this.maxY, this.maxZ)];
36
42
  }
37
43
  toVertices() {
38
44
  return [
@@ -53,6 +59,7 @@ class AABB {
53
59
  this.maxX = Math.floor(this.maxX);
54
60
  this.maxY = Math.floor(this.maxY);
55
61
  this.maxZ = Math.floor(this.maxZ);
62
+ return this;
56
63
  }
57
64
  extend(dx, dy, dz) {
58
65
  if (dx < 0)
@@ -184,6 +191,15 @@ class AABB {
184
191
  }
185
192
  return lo > hi ? Infinity : lo;
186
193
  }
194
+ intersect(aABB) {
195
+ const d = Math.max(this.minX, aABB.minX);
196
+ const d2 = Math.max(this.minY, aABB.minY);
197
+ const d3 = Math.max(this.minZ, aABB.minZ);
198
+ const d4 = Math.min(this.maxX, aABB.maxX);
199
+ const d5 = Math.min(this.maxY, aABB.maxY);
200
+ const d6 = Math.min(this.maxZ, aABB.maxZ);
201
+ return new AABB(d, d2, d3, d4, d5, d6);
202
+ }
187
203
  equals(other) {
188
204
  return (this.minX === other.minX &&
189
205
  this.minY === other.minY &&
@@ -192,19 +208,65 @@ class AABB {
192
208
  this.maxY === other.maxY &&
193
209
  this.maxZ === other.maxZ);
194
210
  }
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);
211
+ xzDistanceToVec(pos) {
212
+ let dx = Math.max(this.minX - pos.x, 0, pos.x - this.maxX);
213
+ let dz = Math.max(this.minZ - pos.z, 0, pos.z - this.maxZ);
199
214
  return Math.sqrt(dx * dx + dz * dz);
200
215
  }
201
- distanceTo(pos, heightOffset = 0) {
202
- const { x, y, z } = pos.offset(0, heightOffset, 0);
203
- let dx = Math.max(this.minX - x, 0, x - this.maxX);
204
- let dy = Math.max(this.minY - y, 0, y - this.maxY);
205
- let dz = Math.max(this.minZ - z, 0, z - this.maxZ);
216
+ distanceToVec(pos) {
217
+ let dx = Math.max(this.minX - pos.x, 0, pos.x - this.maxX);
218
+ let dy = Math.max(this.minY - pos.y, 0, pos.y - this.maxY);
219
+ let dz = Math.max(this.minZ - pos.z, 0, pos.z - this.maxZ);
206
220
  return Math.sqrt(dx * dx + dy * dy + dz * dz);
207
221
  }
222
+ expandTowards(vec3) {
223
+ return this.expandTowardsCoords(vec3.x, vec3.y, vec3.z);
224
+ }
225
+ expandTowardsCoords(d, d2, d3) {
226
+ let d4 = this.minX;
227
+ let d5 = this.minY;
228
+ let d6 = this.minZ;
229
+ let d7 = this.maxX;
230
+ let d8 = this.maxY;
231
+ let d9 = this.maxZ;
232
+ if (d < 0.0) {
233
+ d4 += d;
234
+ }
235
+ else if (d > 0.0) {
236
+ d7 += d;
237
+ }
238
+ if (d2 < 0.0) {
239
+ d5 += d2;
240
+ }
241
+ else if (d2 > 0.0) {
242
+ d8 += d2;
243
+ }
244
+ if (d3 < 0.0) {
245
+ d6 += d3;
246
+ }
247
+ else if (d3 > 0.0) {
248
+ d9 += d3;
249
+ }
250
+ return new AABB(d4, d5, d6, d7, d8, d9);
251
+ }
252
+ moveCoords(d, d2, d3) {
253
+ return new AABB(this.minX + d, this.minY + d2, this.minZ + d3, this.maxX + d, this.maxY + d2, this.maxZ + d3);
254
+ }
255
+ move(vec3) {
256
+ 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);
257
+ }
258
+ intersectsCoords(d, d2, d3, d4, d5, d6) {
259
+ return this.minX < d4 && this.maxX > d && this.minY < d5 && this.maxY > d2 && this.minZ < d6 && this.maxZ > d3;
260
+ }
261
+ collidesAABB(aABB) {
262
+ return this.collidesCoords(aABB.minX, aABB.minY, aABB.minZ, aABB.maxX, aABB.maxY, aABB.maxZ);
263
+ }
264
+ collidesCoords(d, d2, d3, d4, d5, d6) {
265
+ return this.minX <= d4 && this.maxX >= d && this.minY <= d5 && this.maxY >= d2 && this.minZ <= d6 && this.maxZ >= d3;
266
+ }
267
+ getCenter() {
268
+ 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));
269
+ }
208
270
  }
209
271
  exports.AABB = AABB;
210
272
  exports.default = AABB;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InterceptFunctions = void 0;
4
4
  const vec3_1 = require("vec3");
5
+ const iterators_1 = require("./iterators");
5
6
  class InterceptFunctions {
6
7
  constructor(bot) {
7
8
  this.bot = bot;
@@ -18,7 +19,7 @@ class InterceptFunctions {
18
19
  }
19
20
  raycast(from, direction, range) {
20
21
  const iterations = [];
21
- const iter = new RaycastIterator(from, direction, range);
22
+ const iter = new iterators_1.RaycastIterator(from, direction, range);
22
23
  let pos = iter.next();
23
24
  while (pos) {
24
25
  iterations.push(pos);
@@ -47,112 +48,3 @@ class InterceptFunctions {
47
48
  }
48
49
  }
49
50
  exports.InterceptFunctions = InterceptFunctions;
50
- var BlockFace;
51
- (function (BlockFace) {
52
- BlockFace[BlockFace["UNKNOWN"] = -999] = "UNKNOWN";
53
- BlockFace[BlockFace["BOTTOM"] = 0] = "BOTTOM";
54
- BlockFace[BlockFace["TOP"] = 1] = "TOP";
55
- BlockFace[BlockFace["NORTH"] = 2] = "NORTH";
56
- BlockFace[BlockFace["SOUTH"] = 3] = "SOUTH";
57
- BlockFace[BlockFace["WEST"] = 4] = "WEST";
58
- BlockFace[BlockFace["EAST"] = 5] = "EAST";
59
- })(BlockFace || (BlockFace = {}));
60
- class RaycastIterator {
61
- constructor(pos, dir, maxDistance) {
62
- this.block = {
63
- x: Math.floor(pos.x),
64
- y: Math.floor(pos.y),
65
- z: Math.floor(pos.z),
66
- face: BlockFace.UNKNOWN,
67
- };
68
- this.blockVec = new vec3_1.Vec3(Math.floor(pos.x), Math.floor(pos.y), Math.floor(pos.z));
69
- this.pos = pos;
70
- this.dir = dir;
71
- this.invDirX = dir.x === 0 ? Number.MAX_VALUE : 1 / dir.x;
72
- this.invDirY = dir.y === 0 ? Number.MAX_VALUE : 1 / dir.y;
73
- this.invDirZ = dir.z === 0 ? Number.MAX_VALUE : 1 / dir.z;
74
- this.stepX = Math.sign(dir.x);
75
- this.stepY = Math.sign(dir.y);
76
- this.stepZ = Math.sign(dir.z);
77
- this.tDeltaX = dir.x === 0 ? Number.MAX_VALUE : Math.abs(1 / dir.x);
78
- this.tDeltaY = dir.y === 0 ? Number.MAX_VALUE : Math.abs(1 / dir.y);
79
- this.tDeltaZ = dir.z === 0 ? Number.MAX_VALUE : Math.abs(1 / dir.z);
80
- this.tMaxX = dir.x === 0 ? Number.MAX_VALUE : Math.abs((this.block.x + (dir.x > 0 ? 1 : 0) - pos.x) / dir.x);
81
- this.tMaxY = dir.y === 0 ? Number.MAX_VALUE : Math.abs((this.block.y + (dir.y > 0 ? 1 : 0) - pos.y) / dir.y);
82
- this.tMaxZ = dir.z === 0 ? Number.MAX_VALUE : Math.abs((this.block.z + (dir.z > 0 ? 1 : 0) - pos.z) / dir.z);
83
- this.maxDistance = maxDistance;
84
- }
85
- // Returns null if none of the shapes is intersected, otherwise returns intersect pos and face
86
- // shapes are translated by offset
87
- //[x0: number,y0: number,z0: number,x1:number,y1:number,z1:number][]
88
- intersect(shapes, offset) {
89
- // Shapes is an array of shapes, each in the form of: [x0, y0, z0, x1, y1, z1]
90
- let t = Number.MAX_VALUE;
91
- let f = BlockFace.UNKNOWN;
92
- const p = this.pos.minus(offset);
93
- for (const shape of shapes) {
94
- let tmin = (shape[this.invDirX > 0 ? 0 : 3] - p.x) * this.invDirX;
95
- let tmax = (shape[this.invDirX > 0 ? 3 : 0] - p.x) * this.invDirX;
96
- const tymin = (shape[this.invDirY > 0 ? 1 : 4] - p.y) * this.invDirY;
97
- const tymax = (shape[this.invDirY > 0 ? 4 : 1] - p.y) * this.invDirY;
98
- let face = this.stepX > 0 ? BlockFace.WEST : BlockFace.EAST;
99
- if (tmin > tymax || tymin > tmax)
100
- continue;
101
- if (tymin > tmin) {
102
- tmin = tymin;
103
- face = this.stepY > 0 ? BlockFace.BOTTOM : BlockFace.TOP;
104
- }
105
- if (tymax < tmax)
106
- tmax = tymax;
107
- const tzmin = (shape[this.invDirZ > 0 ? 2 : 5] - p.z) * this.invDirZ;
108
- const tzmax = (shape[this.invDirZ > 0 ? 5 : 2] - p.z) * this.invDirZ;
109
- if (tmin > tzmax || tzmin > tmax)
110
- continue;
111
- if (tzmin > tmin) {
112
- tmin = tzmin;
113
- face = this.stepZ > 0 ? BlockFace.NORTH : BlockFace.SOUTH;
114
- }
115
- if (tzmax < tmax)
116
- tmax = tzmax;
117
- if (tmin < t) {
118
- t = tmin;
119
- f = face;
120
- }
121
- }
122
- if (t === Number.MAX_VALUE)
123
- return null;
124
- return { pos: this.pos.plus(this.dir.scaled(t)), face: f };
125
- }
126
- next() {
127
- if (Math.min(Math.min(this.tMaxX, this.tMaxY), this.tMaxZ) > this.maxDistance) {
128
- return null;
129
- }
130
- if (this.tMaxX < this.tMaxY) {
131
- if (this.tMaxX < this.tMaxZ) {
132
- this.block.x += this.stepX;
133
- this.tMaxX += this.tDeltaX;
134
- this.block.face = this.stepX > 0 ? BlockFace.WEST : BlockFace.EAST;
135
- }
136
- else {
137
- this.block.z += this.stepZ;
138
- this.tMaxZ += this.tDeltaZ;
139
- this.block.face = this.stepZ > 0 ? BlockFace.NORTH : BlockFace.SOUTH;
140
- }
141
- }
142
- else {
143
- if (this.tMaxY < this.tMaxZ) {
144
- this.block.y += this.stepY;
145
- this.tMaxY += this.tDeltaY;
146
- this.block.face = this.stepY > 0 ? BlockFace.BOTTOM : BlockFace.TOP;
147
- }
148
- else {
149
- this.block.z += this.stepZ;
150
- this.tMaxZ += this.tDeltaZ;
151
- this.block.face = this.stepZ > 0 ? BlockFace.NORTH : BlockFace.SOUTH;
152
- }
153
- }
154
- if (isNaN(this.block.x) || isNaN(this.block.y) || isNaN(this.block.z))
155
- return null;
156
- return this.block;
157
- }
158
- }
@@ -52,7 +52,7 @@ export declare class EntityFunctions {
52
52
  getEntityAABBRaw(entity: {
53
53
  position: Vec3;
54
54
  height: number;
55
- width: number;
55
+ width?: number;
56
56
  }): AABB;
57
57
  private parseMetadata;
58
58
  }
@@ -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.
@@ -91,19 +89,19 @@ class EntityFunctions {
91
89
  case "player":
92
90
  return this.getPlayerAABB({ position: entity.position });
93
91
  case "mob":
94
- default: //TODO: Implement better AABBs. However, this may just be correct.
92
+ default:
93
+ //TODO: Implement better AABBs. However, this may just be correct.
95
94
  return this.getEntityAABBRaw({ position: entity.position, height: entity.height, width: (_a = entity.width) !== null && _a !== void 0 ? _a : entity.height });
96
95
  }
97
96
  }
98
97
  getPlayerAABB(entity) {
99
- return this.getEntityAABBRaw({ position: entity.position, height: 1.8, width: 0.3 });
98
+ return this.getEntityAABBRaw({ position: entity.position, height: 1.8, width: 0.6 });
100
99
  }
101
100
  getEntityAABBRaw(entity) {
102
- const w = entity.width / 2;
101
+ const w = entity.width ? entity.width / 2 : entity.height / 2;
103
102
  const { x, y, z } = entity.position;
104
103
  return new aabb_1.AABB(-w, 0, -w, w, entity.height, w).offset(x, y, z);
105
104
  }
106
- //Stolen from mineflayer.
107
105
  parseMetadata(packetMetadata, entityMetadata = {}) {
108
106
  if (packetMetadata !== undefined) {
109
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
+ }));
@@ -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) { }
@@ -16,6 +16,6 @@ export declare namespace AABBUtils {
16
16
  function getEntityAABBRaw(entity: {
17
17
  position: Vec3;
18
18
  height: number;
19
- width: number;
19
+ width?: number;
20
20
  }): AABB;
21
21
  }
@@ -26,11 +26,11 @@ var AABBUtils;
26
26
  }
27
27
  AABBUtils.getEntityAABB = getEntityAABB;
28
28
  function getPlayerAABB(entity) {
29
- return getEntityAABBRaw({ position: entity.position, height: 1.8, width: 0.3 });
29
+ return getEntityAABBRaw({ position: entity.position, height: 1.8, width: 0.6 });
30
30
  }
31
31
  AABBUtils.getPlayerAABB = getPlayerAABB;
32
32
  function getEntityAABBRaw(entity) {
33
- const w = entity.width / 2;
33
+ const w = entity.width ? entity.width / 2 : entity.height / 2;
34
34
  const { x, y, z } = entity.position;
35
35
  return new aabb_1.AABB(-w, 0, -w, w, entity.height, w).offset(x, y, z);
36
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxg-org/mineflayer-util-plugin",
3
- "version": "1.3.13",
3
+ "version": "1.4.0",
4
4
  "description": "mineflayer utils for NextGEN mineflayer plugins.",
5
5
  "keywords": [
6
6
  "mineflayer",
@@ -16,15 +16,16 @@
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
- "minecraft-data": "^2.97.0",
23
- "mineflayer": "^3.11.2",
24
- "mineflayer-pathfinder": "^1.8.0",
25
- "prismarine-block": "^1.10.3",
26
- "prismarine-entity": "^1.2.0",
27
- "prismarine-item": "^1.11.1",
23
+ "minecraft-data": "^2.113.0",
24
+ "mineflayer": "^4.0.0",
25
+ "mineflayer-pathfinder": "^1.9.1",
26
+ "prismarine-block": "^1.13.1",
27
+ "prismarine-entity": "^2.0.0",
28
+ "prismarine-item": "^1.11.2",
28
29
  "vec3": "^0.1.7"
29
30
  },
30
31
  "devDependencies": {