@nxg-org/mineflayer-util-plugin 1.0.1 → 1.0.2

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.
Files changed (38) hide show
  1. package/lib/WorldFunctions.d.ts +10 -0
  2. package/lib/WorldFunctions.js +18 -0
  3. package/lib/calcs/aabb.d.ts +36 -0
  4. package/{src/calcs/aabb.ts → lib/calcs/aabb.js} +52 -76
  5. package/lib/commonSense.d.ts +22 -0
  6. package/lib/commonSense.js +220 -0
  7. package/lib/customImplementations/inventory.d.ts +10 -0
  8. package/lib/customImplementations/inventory.js +95 -0
  9. package/lib/entityFunctions.d.ts +36 -0
  10. package/lib/entityFunctions.js +78 -0
  11. package/lib/filterFunctions.d.ts +23 -0
  12. package/lib/filterFunctions.js +45 -0
  13. package/{src/index.ts → lib/index.d.ts} +7 -10
  14. package/lib/inventoryFunctions.d.ts +45 -0
  15. package/lib/inventoryFunctions.js +208 -0
  16. package/lib/mathUtil.d.ts +23 -0
  17. package/{src/mathUtil.ts → lib/mathUtil.js} +21 -28
  18. package/lib/movementFunctions.d.ts +43 -0
  19. package/{src/movementFunctions.ts → lib/movementFunctions.js} +36 -43
  20. package/lib/predictiveFunctions.d.ts +25 -0
  21. package/{src/predictiveFunctions.ts → lib/predictiveFunctions.js} +62 -77
  22. package/lib/utilFunctions.d.ts +50 -0
  23. package/lib/utilFunctions.js +140 -0
  24. package/lib/worldRelated/predictiveWorld.d.ts +41 -0
  25. package/{src/worldRelated/predictiveWorld.ts → lib/worldRelated/predictiveWorld.js} +39 -40
  26. package/lib/worldRelated/raycastIterator.d.ts +45 -0
  27. package/{src/worldRelated/raycastIterator.ts → lib/worldRelated/raycastIterator.js} +37 -59
  28. package/package.json +2 -1
  29. package/.github/workflows/ci.yml +0 -22
  30. package/.github/workflows/release.yml +0 -37
  31. package/src/WorldFunctions.ts +0 -19
  32. package/src/commonSense.ts +0 -189
  33. package/src/customImplementations/inventory.ts +0 -90
  34. package/src/entityFunctions.ts +0 -71
  35. package/src/filterFunctions.ts +0 -54
  36. package/src/inventoryFunctions.ts +0 -187
  37. package/src/utilFunctions.ts +0 -152
  38. package/tsconfig.json +0 -17
@@ -0,0 +1,10 @@
1
+ import type { Bot } from "mineflayer";
2
+ import type { Block } from "prismarine-block";
3
+ import { AABB } from "./calcs/aabb";
4
+ import type { Vec3 } from "vec3";
5
+ export declare class WorldFunctions {
6
+ private bot;
7
+ constructor(bot: Bot);
8
+ getBlockAABB(block: Block, height?: number): AABB;
9
+ getBlockPosAABB(block: Vec3, height?: number): AABB;
10
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WorldFunctions = void 0;
4
+ const aabb_1 = require("./calcs/aabb");
5
+ class WorldFunctions {
6
+ constructor(bot) {
7
+ this.bot = bot;
8
+ }
9
+ getBlockAABB(block, height = 1) {
10
+ const { x, y, z } = block.position;
11
+ return new aabb_1.AABB(x, y, z, x + 1, y + height, z + 1);
12
+ }
13
+ getBlockPosAABB(block, height = 1) {
14
+ const { x, y, z } = block.floored();
15
+ return new aabb_1.AABB(x, y, z, x + 1, y + height, z + 1);
16
+ }
17
+ }
18
+ exports.WorldFunctions = WorldFunctions;
@@ -0,0 +1,36 @@
1
+ import { Vec3 } from "vec3";
2
+ export declare class AABB {
3
+ minX: number;
4
+ minY: number;
5
+ minZ: number;
6
+ maxX: number;
7
+ maxY: number;
8
+ maxZ: number;
9
+ constructor(x0: number, y0: number, z0: number, x1: number, y1: number, z1: number);
10
+ static fromVecs(min: Vec3, max: Vec3): AABB;
11
+ set(x0: number, y0: number, z0: number, x1: number, y1: number, z1: number): void;
12
+ clone(): AABB;
13
+ toArray(): number[];
14
+ toMinAndMaxArrays(): {
15
+ 0: number[];
16
+ 1: number[];
17
+ };
18
+ toVecs(): {
19
+ 0: Vec3;
20
+ 1: Vec3;
21
+ };
22
+ floor(): void;
23
+ extend(dx: number, dy: number, dz: number): this;
24
+ contract(x: number, y: number, z: number): this;
25
+ expand(x: number, y: number, z: number): this;
26
+ offset(x: number, y: number, z: number): this;
27
+ computeOffsetX(other: AABB, offsetX: number): number;
28
+ computeOffsetY(other: AABB, offsetY: number): number;
29
+ computeOffsetZ(other: AABB, offsetZ: number): number;
30
+ intersects(other: AABB): boolean;
31
+ intersectsRay(origin: Vec3, direction: Vec3): Vec3 | null;
32
+ distanceFromRay(origin: Vec3, direction: Vec3): number;
33
+ equals(other: AABB): boolean;
34
+ distanceTo(pos: Vec3, heightOffset?: number): number;
35
+ }
36
+ export default AABB;
@@ -1,14 +1,9 @@
1
- import { Vec3 } from "vec3";
2
-
3
- export class AABB {
4
- public minX: number;
5
- public minY: number;
6
- public minZ: number;
7
- public maxX: number;
8
- public maxY: number;
9
- public maxZ: number;
10
-
11
- constructor(x0: number, y0: number, z0: number, x1: number, y1: number, z1: number) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AABB = void 0;
4
+ const vec3_1 = require("vec3");
5
+ class AABB {
6
+ constructor(x0, y0, z0, x1, y1, z1) {
12
7
  this.minX = x0;
13
8
  this.minY = y0;
14
9
  this.minZ = z0;
@@ -16,12 +11,10 @@ export class AABB {
16
11
  this.maxY = y1;
17
12
  this.maxZ = z1;
18
13
  }
19
-
20
- static fromVecs(min: Vec3, max: Vec3) {
14
+ static fromVecs(min, max) {
21
15
  return new AABB(min.x, min.y, min.z, max.x, max.y, max.z);
22
16
  }
23
-
24
- set(x0: number, y0: number, z0: number, x1: number, y1: number, z1: number) {
17
+ set(x0, y0, z0, x1, y1, z1) {
25
18
  this.minX = x0;
26
19
  this.minY = y0;
27
20
  this.minZ = z0;
@@ -29,23 +22,18 @@ export class AABB {
29
22
  this.maxY = y1;
30
23
  this.maxZ = z1;
31
24
  }
32
-
33
25
  clone() {
34
26
  return new AABB(this.minX, this.minY, this.minZ, this.maxX, this.maxY, this.maxZ);
35
27
  }
36
-
37
28
  toArray() {
38
29
  return [this.minX, this.minY, this.minZ, this.maxX, this.maxY, this.maxZ];
39
30
  }
40
-
41
31
  toMinAndMaxArrays() {
42
32
  return { 0: [this.minX, this.minY, this.minZ], 1: [this.maxX, this.maxY, this.maxZ] };
43
33
  }
44
-
45
34
  toVecs() {
46
- return { 0: new Vec3(this.minX, this.minY, this.minZ), 1: new Vec3(this.maxX, this.maxY, this.maxZ) };
35
+ return { 0: new vec3_1.Vec3(this.minX, this.minY, this.minZ), 1: new vec3_1.Vec3(this.maxX, this.maxY, this.maxZ) };
47
36
  }
48
-
49
37
  floor() {
50
38
  this.minX = Math.floor(this.minX);
51
39
  this.minY = Math.floor(this.minY);
@@ -54,21 +42,22 @@ export class AABB {
54
42
  this.maxY = Math.floor(this.maxY);
55
43
  this.maxZ = Math.floor(this.maxZ);
56
44
  }
57
-
58
- extend(dx: number, dy: number, dz: number) {
59
- if (dx < 0) this.minX += dx;
60
- else this.maxX += dx;
61
-
62
- if (dy < 0) this.minY += dy;
63
- else this.maxY += dy;
64
-
65
- if (dz < 0) this.minZ += dz;
66
- else this.maxZ += dz;
67
-
45
+ extend(dx, dy, dz) {
46
+ if (dx < 0)
47
+ this.minX += dx;
48
+ else
49
+ this.maxX += dx;
50
+ if (dy < 0)
51
+ this.minY += dy;
52
+ else
53
+ this.maxY += dy;
54
+ if (dz < 0)
55
+ this.minZ += dz;
56
+ else
57
+ this.maxZ += dz;
68
58
  return this;
69
59
  }
70
-
71
- contract(x: number, y: number, z: number) {
60
+ contract(x, y, z) {
72
61
  this.minX += x;
73
62
  this.minY += y;
74
63
  this.minZ += z;
@@ -77,8 +66,7 @@ export class AABB {
77
66
  this.maxZ -= z;
78
67
  return this;
79
68
  }
80
-
81
- expand(x: number, y: number, z: number) {
69
+ expand(x, y, z) {
82
70
  this.minX -= x;
83
71
  this.minY -= y;
84
72
  this.minZ -= z;
@@ -87,8 +75,7 @@ export class AABB {
87
75
  this.maxZ += z;
88
76
  return this;
89
77
  }
90
-
91
- offset(x: number, y: number, z: number) {
78
+ offset(x, y, z) {
92
79
  this.minX += x;
93
80
  this.minY += y;
94
81
  this.minZ += z;
@@ -97,61 +84,57 @@ export class AABB {
97
84
  this.maxZ += z;
98
85
  return this;
99
86
  }
100
-
101
- computeOffsetX(other: AABB, offsetX: number) {
87
+ computeOffsetX(other, offsetX) {
102
88
  if (other.maxY > this.minY && other.minY < this.maxY && other.maxZ > this.minZ && other.minZ < this.maxZ) {
103
89
  if (offsetX > 0.0 && other.maxX <= this.minX) {
104
90
  offsetX = Math.min(this.minX - other.maxX, offsetX);
105
- } else if (offsetX < 0.0 && other.minX >= this.maxX) {
91
+ }
92
+ else if (offsetX < 0.0 && other.minX >= this.maxX) {
106
93
  offsetX = Math.max(this.maxX - other.minX, offsetX);
107
94
  }
108
95
  }
109
96
  return offsetX;
110
97
  }
111
-
112
- computeOffsetY(other: AABB, offsetY: number) {
98
+ computeOffsetY(other, offsetY) {
113
99
  if (other.maxX > this.minX && other.minX < this.maxX && other.maxZ > this.minZ && other.minZ < this.maxZ) {
114
100
  if (offsetY > 0.0 && other.maxY <= this.minY) {
115
101
  offsetY = Math.min(this.minY - other.maxY, offsetY);
116
- } else if (offsetY < 0.0 && other.minY >= this.maxY) {
102
+ }
103
+ else if (offsetY < 0.0 && other.minY >= this.maxY) {
117
104
  offsetY = Math.max(this.maxY - other.minY, offsetY);
118
105
  }
119
106
  }
120
107
  return offsetY;
121
108
  }
122
-
123
- computeOffsetZ(other: AABB, offsetZ: number) {
109
+ computeOffsetZ(other, offsetZ) {
124
110
  if (other.maxX > this.minX && other.minX < this.maxX && other.maxY > this.minY && other.minY < this.maxY) {
125
111
  if (offsetZ > 0.0 && other.maxZ <= this.minZ) {
126
112
  offsetZ = Math.min(this.minZ - other.maxZ, offsetZ);
127
- } else if (offsetZ < 0.0 && other.minZ >= this.maxZ) {
113
+ }
114
+ else if (offsetZ < 0.0 && other.minZ >= this.maxZ) {
128
115
  offsetZ = Math.max(this.maxZ - other.minZ, offsetZ);
129
116
  }
130
117
  }
131
118
  return offsetZ;
132
119
  }
133
-
134
- intersects(other: AABB) {
135
- return (
136
- this.minX < other.maxX &&
120
+ intersects(other) {
121
+ return (this.minX < other.maxX &&
137
122
  this.maxX > other.minX &&
138
123
  this.minY < other.maxY &&
139
124
  this.maxY > other.minY &&
140
125
  this.minZ < other.maxZ &&
141
- this.maxZ > other.minZ
142
- );
126
+ this.maxZ > other.minZ);
143
127
  }
144
-
145
- intersectsRay(origin: Vec3, direction: Vec3) {
128
+ intersectsRay(origin, direction) {
146
129
  const d = this.distanceFromRay(origin, direction);
147
130
  if (d === Infinity) {
148
131
  return null;
149
- } else {
150
- return new Vec3(origin.x + direction.x * d, origin.y + direction.y * d, origin.z + direction.z * d);
132
+ }
133
+ else {
134
+ return new vec3_1.Vec3(origin.x + direction.x * d, origin.y + direction.y * d, origin.z + direction.z * d);
151
135
  }
152
136
  }
153
-
154
- distanceFromRay(origin: Vec3, direction: Vec3) {
137
+ distanceFromRay(origin, direction) {
155
138
  const ro = origin.toArray();
156
139
  const rd = direction.normalize().toArray();
157
140
  const aabb = this.toMinAndMaxArrays();
@@ -159,17 +142,14 @@ export class AABB {
159
142
  let lo = -Infinity;
160
143
  let hi = +Infinity;
161
144
  // let test = origin.clone()
162
-
163
145
  for (let i = 0; i < dims; i++) {
164
146
  let dimLo = (aabb[0][i] - ro[i]) / rd[i];
165
147
  let dimHi = (aabb[1][i] - ro[i]) / rd[i];
166
-
167
148
  if (dimLo > dimHi) {
168
149
  let tmp = dimLo;
169
150
  dimLo = dimHi;
170
151
  dimHi = tmp;
171
152
  }
172
-
173
153
  // let num;
174
154
  // switch (i) {
175
155
  // case 0:
@@ -187,26 +167,22 @@ export class AABB {
187
167
  console.log("fuck", dimHi < lo, dimLo > hi);
188
168
  return Infinity;
189
169
  }
190
-
191
- if (dimLo > lo) lo = dimLo;
192
- if (dimHi < hi) hi = dimHi;
170
+ if (dimLo > lo)
171
+ lo = dimLo;
172
+ if (dimHi < hi)
173
+ hi = dimHi;
193
174
  }
194
-
195
175
  return lo > hi ? Infinity : lo;
196
176
  }
197
-
198
- equals(other: AABB): boolean {
199
- return (
200
- this.minX === other.minX &&
177
+ equals(other) {
178
+ return (this.minX === other.minX &&
201
179
  this.minY === other.minY &&
202
180
  this.minZ === other.minZ &&
203
181
  this.maxX === other.maxX &&
204
182
  this.maxY === other.maxY &&
205
- this.maxZ === other.maxZ
206
- );
183
+ this.maxZ === other.maxZ);
207
184
  }
208
-
209
- distanceTo(pos: Vec3, heightOffset: number = 0): number {
185
+ distanceTo(pos, heightOffset = 0) {
210
186
  const { x, y, z } = pos.offset(0, heightOffset, 0);
211
187
  let dx = Math.max(this.minX - x, 0, x - this.maxX);
212
188
  let dy = Math.max(this.minY - y, 0, y - this.maxY);
@@ -214,5 +190,5 @@ export class AABB {
214
190
  return Math.sqrt(dx * dx + dy * dy + dz * dz);
215
191
  }
216
192
  }
217
-
218
- export default AABB;
193
+ exports.AABB = AABB;
194
+ exports.default = AABB;
@@ -0,0 +1,22 @@
1
+ import type { Bot } from "mineflayer";
2
+ import type { Block } from "prismarine-block";
3
+ export declare class CommonSense {
4
+ bot: Bot;
5
+ autoRespond: boolean;
6
+ isFalling: boolean;
7
+ isOnFire: boolean;
8
+ checkForFalling: boolean;
9
+ checkForFire: boolean;
10
+ useOffHand: boolean;
11
+ requipLastItem: boolean;
12
+ puttingOutFire: boolean;
13
+ MLGing: boolean;
14
+ constructor(bot: Bot);
15
+ onMetadataFireCheck(packet: any): Promise<void>;
16
+ onStatusFireCheck(packet: any): Promise<void>;
17
+ putOutFire(): Promise<boolean>;
18
+ pickUpWater(nearbyBlock?: Block | null, maxDistance?: number, immediate?: boolean): Promise<void>;
19
+ isFallingCheckEasy(): Promise<void>;
20
+ private findBlockForWaterPlacement;
21
+ waterBucket(): Promise<boolean>;
22
+ }
@@ -0,0 +1,220 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CommonSense = void 0;
13
+ const vec3_1 = require("vec3");
14
+ const util_1 = require("util");
15
+ const sleep = (0, util_1.promisify)(setTimeout);
16
+ class CommonSense {
17
+ constructor(bot) {
18
+ this.bot = bot;
19
+ this.autoRespond = false;
20
+ this.isFalling = false;
21
+ this.isOnFire = false;
22
+ this.checkForFalling = true;
23
+ this.checkForFire = true;
24
+ this.useOffHand = true;
25
+ this.requipLastItem = false;
26
+ this.puttingOutFire = false;
27
+ this.MLGing = false;
28
+ this.bot.on("physicsTick", this.isFallingCheckEasy.bind(this));
29
+ this.bot._client.on("entity_metadata", this.onMetadataFireCheck.bind(this));
30
+ this.bot._client.on("entity_status", this.onStatusFireCheck.bind(this));
31
+ // this.bot.on("physicsTick", this.onPhysicsTickFireCheck.bind(this));
32
+ //TODO: Move this to bot movement.
33
+ }
34
+ // async onPhysicsTickFireCheck() {
35
+ // if ((this.bot.entity.metadata[0] as any) === 1) {
36
+ // this.isOnFire = true;
37
+ // while (!this.bot.entity.onGround) await sleep(0);
38
+ // if (!this.puttingOutFire && this.autoRespond) this.putOutFire();
39
+ // } else {
40
+ // this.isOnFire = false
41
+ // }
42
+ // }
43
+ onMetadataFireCheck(packet) {
44
+ var _a;
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ if (!this.checkForFire)
47
+ return;
48
+ if (!packet.entityId)
49
+ return;
50
+ const entity = this.bot.entities[packet.entityId];
51
+ if (!entity || entity !== this.bot.entity)
52
+ return;
53
+ // if ((entity.metadata[0] as any).value !== 1) {
54
+ const wantedKey = packet.metadata.findIndex((md) => md.key === 0);
55
+ if (wantedKey === -1)
56
+ return;
57
+ if (((_a = packet.metadata[wantedKey]) === null || _a === void 0 ? void 0 : _a.value) !== 1) {
58
+ this.isOnFire = false;
59
+ return;
60
+ }
61
+ // }
62
+ this.isOnFire = true;
63
+ while (!this.bot.entity.onGround)
64
+ yield this.bot.waitForTicks(1);
65
+ if (!this.puttingOutFire && this.autoRespond)
66
+ this.putOutFire();
67
+ });
68
+ }
69
+ onStatusFireCheck(packet) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ if (!this.checkForFire)
72
+ return;
73
+ if (!packet.entityId)
74
+ return;
75
+ const entity = this.bot.entities[packet.entityId];
76
+ if (!entity || entity !== this.bot.entity)
77
+ return;
78
+ if (!packet.entityStatus || packet.entityStatus !== 37) {
79
+ this.isOnFire = false;
80
+ return;
81
+ }
82
+ this.isOnFire = true;
83
+ while (!this.bot.entity.onGround)
84
+ yield sleep(0);
85
+ if (!this.puttingOutFire && this.autoRespond)
86
+ this.putOutFire();
87
+ });
88
+ }
89
+ putOutFire() {
90
+ var _a, _b;
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ if (this.puttingOutFire)
93
+ return true;
94
+ this.puttingOutFire = true;
95
+ const water = this.bot.util.inv.getAllItemsExceptCurrent("off-hand").find((item) => item === null || item === void 0 ? void 0 : item.name.includes("water_bucket"));
96
+ const holdingItem = (_a = this.bot.util.inv.getHandWithItem(this.useOffHand)) === null || _a === void 0 ? void 0 : _a.name.includes("water_bucket");
97
+ if (!water && !holdingItem) {
98
+ this.puttingOutFire = false;
99
+ return false;
100
+ }
101
+ else if (!holdingItem && water)
102
+ yield this.bot.util.inv.customEquip(water, "off-hand");
103
+ if ((_b = this.bot.util.inv.getHandWithItem(this.useOffHand)) === null || _b === void 0 ? void 0 : _b.name.includes("water_bucket")) {
104
+ const nearbyBlock = this.bot.findBlock({ matching: (block) => (block === null || block === void 0 ? void 0 : block.name) === "fire", maxDistance: 2 });
105
+ if (nearbyBlock) {
106
+ yield this.bot.dig(nearbyBlock, true);
107
+ yield this.bot.util.move.forceLookAt(nearbyBlock.position.offset(0, -1, 0));
108
+ }
109
+ else {
110
+ yield this.bot.util.move.forceLook(this.bot.entity.yaw, -90);
111
+ }
112
+ // while (!this.bot.entity.isCollidedVertically) await this.bot.waitForTicks(1);
113
+ this.bot.activateItem(this.useOffHand);
114
+ yield this.pickUpWater(nearbyBlock);
115
+ this.puttingOutFire = false;
116
+ return true;
117
+ }
118
+ else {
119
+ this.puttingOutFire = false;
120
+ return false;
121
+ }
122
+ });
123
+ }
124
+ pickUpWater(nearbyBlock = null, maxDistance = 2, immediate = false) {
125
+ var _a;
126
+ return __awaiter(this, void 0, void 0, function* () {
127
+ if (!immediate)
128
+ yield this.bot.waitForTicks(3);
129
+ const block = this.bot.findBlock({
130
+ point: (_a = nearbyBlock === null || nearbyBlock === void 0 ? void 0 : nearbyBlock.position) !== null && _a !== void 0 ? _a : this.bot.entity.position,
131
+ matching: (block) => (block.type === 8 || block.type === 9) && block.metadata === 0,
132
+ //@ts-expect-error
133
+ useExtraInfo: (block) => {
134
+ return this.bot.util.world.getBlockAABB(block).distanceTo(this.bot.entity.position, 1.62) < 4;
135
+ },
136
+ maxDistance: maxDistance,
137
+ });
138
+ if (block) {
139
+ this.bot.util.move.forceLookAt(block.position.offset(0.5, 0.5, 0.5), true);
140
+ this.bot.activateItem(this.useOffHand);
141
+ }
142
+ else {
143
+ console.log("didn't get block. fuck.");
144
+ }
145
+ });
146
+ }
147
+ isFallingCheckEasy() {
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ if (!this.checkForFalling)
150
+ return;
151
+ if (this.bot.entity.velocity.y >= -0.6) {
152
+ this.isFalling = false;
153
+ return;
154
+ }
155
+ this.isFalling = true;
156
+ if (!this.MLGing && this.autoRespond) {
157
+ yield this.waterBucket();
158
+ }
159
+ });
160
+ }
161
+ findBlockForWaterPlacement() {
162
+ const pos = this.bot.entity.position.offset(this.bot.entity.velocity.x, 0, this.bot.entity.velocity.z);
163
+ const aabb = this.bot.util.entity.getEntityAABB({
164
+ position: pos,
165
+ height: this.bot.entity.height,
166
+ width: 0.3,
167
+ });
168
+ const spacing = { x0: aabb.minX, z0: aabb.minZ, x1: aabb.maxX, z1: aabb.maxZ };
169
+ const floored = { x0: Math.floor(spacing.x0), z0: Math.floor(spacing.z0), x1: Math.floor(spacing.x1), z1: Math.floor(spacing.z1) };
170
+ let blocks = [];
171
+ const posY = this.bot.entity.position.clone().floored().y;
172
+ loop1: for (let i = floored.x0; i <= floored.x1; i++) {
173
+ loop2: for (let j = floored.z0; j <= floored.z1; j++) {
174
+ loop3: for (let k = posY; k > 0; k--) {
175
+ const block = this.bot.blockAt(new vec3_1.Vec3(i, k, j));
176
+ if (!!block && block.type !== 0) {
177
+ blocks.push(block);
178
+ break loop3;
179
+ }
180
+ }
181
+ }
182
+ }
183
+ const maxY = Math.max(...blocks.map((b) => b.position.y));
184
+ blocks = blocks.filter((b) => b.position.y === maxY);
185
+ const block = blocks.sort((a, b) => this.bot.util.world.getBlockAABB(b).distanceTo(pos) - this.bot.util.world.getBlockAABB(a).distanceTo(pos))[0];
186
+ // console.log(block.position, this.bot.entity.position, this.bot.entity.position.distanceTo(block.position).toFixed(2));
187
+ return block;
188
+ }
189
+ waterBucket() {
190
+ var _a, _b;
191
+ return __awaiter(this, void 0, void 0, function* () {
192
+ if (this.MLGing)
193
+ return true;
194
+ this.MLGing = true;
195
+ const water = this.bot.util.inv.getAllItemsExceptCurrent("off-hand").find((item) => item === null || item === void 0 ? void 0 : item.name.includes("water_bucket"));
196
+ const holdingItem = (_a = this.bot.util.inv.getHandWithItem(true)) === null || _a === void 0 ? void 0 : _a.name.includes("water_bucket");
197
+ if (!water && !holdingItem) {
198
+ this.MLGing = false;
199
+ return false;
200
+ }
201
+ else if (!holdingItem && water)
202
+ yield this.bot.util.inv.customEquip(water, "off-hand");
203
+ for (let i = 0; i < 120; i++) {
204
+ const landingBlock = this.findBlockForWaterPlacement();
205
+ if (landingBlock) {
206
+ yield this.bot.util.move.forceLookAt(landingBlock.position.offset(0.5, 0.5, 0.5), true);
207
+ }
208
+ if (this.bot.entity.position.y <= ((_b = landingBlock === null || landingBlock === void 0 ? void 0 : landingBlock.position.y) !== null && _b !== void 0 ? _b : 0) + 3) {
209
+ this.bot.activateItem(this.useOffHand);
210
+ break;
211
+ }
212
+ yield this.bot.waitForTicks(1);
213
+ }
214
+ yield this.pickUpWater(null, 2);
215
+ this.MLGing = false;
216
+ return true;
217
+ });
218
+ }
219
+ }
220
+ exports.CommonSense = CommonSense;
@@ -0,0 +1,10 @@
1
+ import type { Bot, EquipmentDestination } from "mineflayer";
2
+ import type { Item } from "prismarine-item";
3
+ export declare class CustomInventoryFunctions {
4
+ private bot;
5
+ armorSlots: any;
6
+ constructor(bot: Bot);
7
+ equip(item: Item, destination: EquipmentDestination): Promise<void>;
8
+ setQuickBarSlot(slot: number): void;
9
+ getDestSlot(destination: EquipmentDestination): any;
10
+ }
@@ -0,0 +1,95 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.CustomInventoryFunctions = void 0;
16
+ const assert_1 = __importDefault(require("assert"));
17
+ const util_1 = require("util");
18
+ const sleep = (0, util_1.promisify)(setTimeout);
19
+ const QUICK_BAR_COUNT = 9;
20
+ const QUICK_BAR_START = 36;
21
+ let nextQuickBarSlot = 0;
22
+ //lazy. will fix this later.
23
+ class CustomInventoryFunctions {
24
+ constructor(bot) {
25
+ this.bot = bot;
26
+ this.armorSlots = {
27
+ head: 5,
28
+ torso: 6,
29
+ legs: 7,
30
+ feet: 8,
31
+ };
32
+ if (!bot.supportFeature("doesntHaveOffHandSlot")) {
33
+ this.armorSlots["off-hand"] = 45;
34
+ }
35
+ }
36
+ equip(item, destination) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ if (item == null || typeof item !== "object") {
39
+ throw new Error("Invalid item object in equip (item is null or typeof item is not object)");
40
+ }
41
+ if (!destination || destination === null) {
42
+ destination = "hand";
43
+ }
44
+ const sourceSlot = item.slot;
45
+ let destSlot = this.getDestSlot(destination);
46
+ if (sourceSlot === destSlot) {
47
+ // don't need to do anything
48
+ return;
49
+ }
50
+ if (destination !== "hand") {
51
+ yield this.bot.moveSlotItem(sourceSlot, destSlot);
52
+ return;
53
+ }
54
+ if (destSlot >= QUICK_BAR_START &&
55
+ destSlot < QUICK_BAR_START + QUICK_BAR_COUNT &&
56
+ sourceSlot >= QUICK_BAR_START &&
57
+ sourceSlot < QUICK_BAR_START + QUICK_BAR_COUNT) {
58
+ // all we have to do is change the quick bar selection
59
+ this.bot.setQuickBarSlot(sourceSlot - QUICK_BAR_START);
60
+ return;
61
+ }
62
+ // find an empty slot on the quick bar to put the source item in
63
+ destSlot = this.bot.inventory.firstEmptySlotRange(QUICK_BAR_START, QUICK_BAR_START + QUICK_BAR_COUNT);
64
+ if (destSlot == null) {
65
+ // LRU cache for the quick bar items
66
+ destSlot = QUICK_BAR_START + nextQuickBarSlot;
67
+ nextQuickBarSlot = (nextQuickBarSlot + 1) % QUICK_BAR_COUNT;
68
+ }
69
+ this.setQuickBarSlot(destSlot - QUICK_BAR_START);
70
+ yield this.bot.moveSlotItem(sourceSlot, destSlot);
71
+ });
72
+ }
73
+ setQuickBarSlot(slot) {
74
+ assert_1.default.ok(slot >= 0);
75
+ assert_1.default.ok(slot < 9);
76
+ if (this.bot.quickBarSlot === slot)
77
+ return;
78
+ this.bot.quickBarSlot = slot;
79
+ this.bot._client.write("held_item_slot", {
80
+ slotId: slot,
81
+ });
82
+ this.bot.updateHeldItem();
83
+ }
84
+ getDestSlot(destination) {
85
+ if (destination === "hand") {
86
+ return QUICK_BAR_START + this.bot.quickBarSlot;
87
+ }
88
+ else {
89
+ const destSlot = this.armorSlots[destination];
90
+ assert_1.default.ok(destSlot != null, `invalid destination: ${destination}`);
91
+ return destSlot;
92
+ }
93
+ }
94
+ }
95
+ exports.CustomInventoryFunctions = CustomInventoryFunctions;