@nxg-org/mineflayer-util-plugin 1.0.1 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/WorldFunctions.d.ts +10 -0
- package/lib/WorldFunctions.js +18 -0
- package/lib/calcs/aabb.d.ts +36 -0
- package/{src/calcs/aabb.ts → lib/calcs/aabb.js} +52 -76
- package/lib/customImplementations/inventory.d.ts +10 -0
- package/lib/customImplementations/inventory.js +95 -0
- package/lib/entityFunctions.d.ts +49 -0
- package/lib/entityFunctions.js +104 -0
- package/lib/filterFunctions.d.ts +23 -0
- package/lib/filterFunctions.js +45 -0
- package/{src/index.ts → lib/index.d.ts} +7 -11
- package/lib/index.js +1 -3
- package/lib/inventoryFunctions.d.ts +45 -0
- package/lib/inventoryFunctions.js +208 -0
- package/lib/mathUtil.d.ts +23 -0
- package/{src/mathUtil.ts → lib/mathUtil.js} +21 -28
- package/lib/movementFunctions.d.ts +43 -0
- package/{src/movementFunctions.ts → lib/movementFunctions.js} +36 -43
- package/lib/predictiveFunctions.d.ts +25 -0
- package/{src/predictiveFunctions.ts → lib/predictiveFunctions.js} +62 -77
- package/lib/utilFunctions.d.ts +48 -0
- package/lib/utilFunctions.js +138 -0
- package/lib/worldRelated/predictiveWorld.d.ts +41 -0
- package/{src/worldRelated/predictiveWorld.ts → lib/worldRelated/predictiveWorld.js} +39 -40
- package/lib/worldRelated/raycastIterator.d.ts +45 -0
- package/{src/worldRelated/raycastIterator.ts → lib/worldRelated/raycastIterator.js} +37 -59
- package/package.json +2 -1
- package/.github/workflows/ci.yml +0 -22
- package/.github/workflows/release.yml +0 -37
- package/src/WorldFunctions.ts +0 -19
- package/src/commonSense.ts +0 -189
- package/src/customImplementations/inventory.ts +0 -90
- package/src/entityFunctions.ts +0 -71
- package/src/filterFunctions.ts +0 -54
- package/src/inventoryFunctions.ts +0 -187
- package/src/utilFunctions.ts +0 -152
- 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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
else
|
|
61
|
-
|
|
62
|
-
if (dy < 0)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
}
|
|
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
|
-
}
|
|
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
|
-
}
|
|
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
|
-
|
|
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
|
-
}
|
|
150
|
-
|
|
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
|
-
|
|
192
|
-
if (dimHi < hi)
|
|
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
|
-
|
|
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
|
-
|
|
193
|
+
exports.AABB = AABB;
|
|
194
|
+
exports.default = AABB;
|
|
@@ -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;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Bot } from "mineflayer";
|
|
2
|
+
import type { Entity } from "prismarine-entity";
|
|
3
|
+
import type { Vec3 } from "vec3";
|
|
4
|
+
import { AABB } from "./calcs/aabb";
|
|
5
|
+
export declare class EntityFunctions {
|
|
6
|
+
bot: Bot;
|
|
7
|
+
healthSlot: number;
|
|
8
|
+
constructor(bot: Bot);
|
|
9
|
+
/**
|
|
10
|
+
* TODO: Version specific right now. Generalize. Unknown method.
|
|
11
|
+
*
|
|
12
|
+
* Checks if main hand is activated.
|
|
13
|
+
* @returns boolean
|
|
14
|
+
*/
|
|
15
|
+
isMainHandActive(entity?: Entity): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* TODO: Version specific right now. Generalize. Unknown method.
|
|
18
|
+
*
|
|
19
|
+
* Checks if offhand is activated.
|
|
20
|
+
* @returns boolean
|
|
21
|
+
*/
|
|
22
|
+
isOffHandActive(entity?: Entity): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* TODO: Version specific right now. Generalize. Unknown method.
|
|
25
|
+
* @param metadata metadata from Prismarine-Entity Entity.
|
|
26
|
+
* @returns number
|
|
27
|
+
*/
|
|
28
|
+
getHealth(entity?: Entity): number;
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @param metadata Must be FULL metadata object.
|
|
32
|
+
* @returns number
|
|
33
|
+
*/
|
|
34
|
+
getHealthFromMetadata(metadata: object[]): number;
|
|
35
|
+
/**
|
|
36
|
+
* TODO: Version specific right now. Generalize. Unknown method.
|
|
37
|
+
* @param metadata metadata from Prismarine-Entity Entity.
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
getHealthChange(packetMetadata: any, entity: Entity): number;
|
|
41
|
+
getDistanceToEntity(entity: Entity): number;
|
|
42
|
+
getDistanceBetweenEntities(first: Entity, second: Entity): number;
|
|
43
|
+
getEntityAABB(entity: {
|
|
44
|
+
position: Vec3;
|
|
45
|
+
height: number;
|
|
46
|
+
width?: number;
|
|
47
|
+
}): AABB;
|
|
48
|
+
private parseMetadata;
|
|
49
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
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.EntityFunctions = void 0;
|
|
13
|
+
const aabb_1 = require("./calcs/aabb");
|
|
14
|
+
class EntityFunctions {
|
|
15
|
+
constructor(bot) {
|
|
16
|
+
this.bot = bot;
|
|
17
|
+
this.healthSlot = 7;
|
|
18
|
+
this.bot.on("spawn", () => __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
// await this.bot.util.sleep(1000)
|
|
20
|
+
// const slot = this.bot.entity.metadata.slice(5).findIndex((data) => Number(data) === 20);
|
|
21
|
+
// if (slot > 0) {
|
|
22
|
+
// this.healthSlot = slot + 5;
|
|
23
|
+
// }
|
|
24
|
+
this.healthSlot = Number(this.bot.version.split(".")[1]) <= 16 ? 7 : 9;
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* TODO: Version specific right now. Generalize. Unknown method.
|
|
29
|
+
*
|
|
30
|
+
* Checks if main hand is activated.
|
|
31
|
+
* @returns boolean
|
|
32
|
+
*/
|
|
33
|
+
isMainHandActive(entity) {
|
|
34
|
+
return (entity !== null && entity !== void 0 ? entity : this.bot.entity).metadata[6] === 1; //as any & (1 | 0)) === (1 | 0);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* TODO: Version specific right now. Generalize. Unknown method.
|
|
38
|
+
*
|
|
39
|
+
* Checks if offhand is activated.
|
|
40
|
+
* @returns boolean
|
|
41
|
+
*/
|
|
42
|
+
isOffHandActive(entity) {
|
|
43
|
+
return (entity !== null && entity !== void 0 ? entity : this.bot.entity).metadata[6] === 1; //& (1 | 2)) === (1 | 2);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* TODO: Version specific right now. Generalize. Unknown method.
|
|
47
|
+
* @param metadata metadata from Prismarine-Entity Entity.
|
|
48
|
+
* @returns number
|
|
49
|
+
*/
|
|
50
|
+
getHealth(entity) {
|
|
51
|
+
var _a, _b;
|
|
52
|
+
entity !== null && entity !== void 0 ? entity : (entity = this.bot.entity);
|
|
53
|
+
const metadata = entity.metadata;
|
|
54
|
+
const healthSlot = this.healthSlot; //metadata[this.healthSlot] ? this.healthSlot : metadata.findIndex((met) => Number(met) > 1 && Number(met) <= 20);
|
|
55
|
+
let health = Number(metadata[healthSlot]);
|
|
56
|
+
if (!health || health === 0)
|
|
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
|
+
// console.log(health + (Number(metadata[this.healthSlot + 4]) ?? 0))
|
|
61
|
+
return health + ((_b = Number(metadata[this.healthSlot + 4])) !== null && _b !== void 0 ? _b : 0);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
*
|
|
65
|
+
* @param metadata Must be FULL metadata object.
|
|
66
|
+
* @returns number
|
|
67
|
+
*/
|
|
68
|
+
getHealthFromMetadata(metadata) {
|
|
69
|
+
var _a;
|
|
70
|
+
return (_a = (Number(metadata[this.healthSlot]) + Number(metadata[this.healthSlot + 4]))) !== null && _a !== void 0 ? _a : undefined;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* TODO: Version specific right now. Generalize. Unknown method.
|
|
74
|
+
* @param metadata metadata from Prismarine-Entity Entity.
|
|
75
|
+
* @returns
|
|
76
|
+
*/
|
|
77
|
+
getHealthChange(packetMetadata, entity) {
|
|
78
|
+
const oldMetadata = entity.metadata;
|
|
79
|
+
const newMetadata = this.parseMetadata(packetMetadata, oldMetadata);
|
|
80
|
+
return this.getHealthFromMetadata(newMetadata) - this.getHealthFromMetadata(oldMetadata);
|
|
81
|
+
}
|
|
82
|
+
getDistanceToEntity(entity) {
|
|
83
|
+
return this.getDistanceBetweenEntities(this.bot.entity, entity);
|
|
84
|
+
}
|
|
85
|
+
getDistanceBetweenEntities(first, second) {
|
|
86
|
+
return first.position.distanceTo(second.position);
|
|
87
|
+
}
|
|
88
|
+
getEntityAABB(entity) {
|
|
89
|
+
var _a;
|
|
90
|
+
const w = (_a = entity.width) !== null && _a !== void 0 ? _a : entity.height / 2;
|
|
91
|
+
const { x, y, z } = entity.position;
|
|
92
|
+
return new aabb_1.AABB(-w, 0, -w, w, entity.height, w).offset(x, y, z);
|
|
93
|
+
}
|
|
94
|
+
//Stolen from mineflayer.
|
|
95
|
+
parseMetadata(packetMetadata, entityMetadata = {}) {
|
|
96
|
+
if (packetMetadata !== undefined) {
|
|
97
|
+
for (const { key, value } of packetMetadata) {
|
|
98
|
+
entityMetadata[key] = value;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return entityMetadata;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.EntityFunctions = EntityFunctions;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Entity } from "prismarine-entity";
|
|
2
|
+
import type { Bot } from "mineflayer";
|
|
3
|
+
import type { Vec3 } from "vec3";
|
|
4
|
+
/**
|
|
5
|
+
* TODO: Inherit other bot names. May need to communciate to a server for this one. Or perhaps reference this once?
|
|
6
|
+
*/
|
|
7
|
+
export declare class FilterFunctions {
|
|
8
|
+
private bot;
|
|
9
|
+
specificNames: string[];
|
|
10
|
+
botNames: string[];
|
|
11
|
+
constructor(bot: Bot);
|
|
12
|
+
addBotName(name: string): void;
|
|
13
|
+
getNearestEntity(func: (entity: Entity, ...args: any[]) => boolean, ...args: any[]): Entity | null;
|
|
14
|
+
static getNearestEntity(bot: Bot, func: (entity: Entity, ...args: any[]) => boolean, ...args: any[]): Entity | null;
|
|
15
|
+
allButOtherBotsFilter(): Entity | null;
|
|
16
|
+
static allButOtherBotsFilter(bot: Bot, ...names: string[]): Entity | null;
|
|
17
|
+
specificNamesFilter(): Entity | null;
|
|
18
|
+
static specificNamesFilter(bot: Bot, ...names: string[]): Entity | null;
|
|
19
|
+
nearestCrystalFilter(): Entity | null;
|
|
20
|
+
static nearestCrystalFilter(bot: Bot): Entity | null;
|
|
21
|
+
entityAtPosition(position: Vec3): Entity | null;
|
|
22
|
+
static entityAtPosition(bot: Bot, position: Vec3): void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FilterFunctions = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* TODO: Inherit other bot names. May need to communciate to a server for this one. Or perhaps reference this once?
|
|
6
|
+
*/
|
|
7
|
+
class FilterFunctions {
|
|
8
|
+
constructor(bot) {
|
|
9
|
+
this.bot = bot;
|
|
10
|
+
this.specificNames = [];
|
|
11
|
+
this.botNames = [];
|
|
12
|
+
}
|
|
13
|
+
addBotName(name) {
|
|
14
|
+
this.botNames.push(name);
|
|
15
|
+
}
|
|
16
|
+
getNearestEntity(func, ...args) {
|
|
17
|
+
return this.bot.nearestEntity((entity) => func(entity, ...args));
|
|
18
|
+
}
|
|
19
|
+
static getNearestEntity(bot, func, ...args) {
|
|
20
|
+
return bot.nearestEntity((entity) => func(entity, ...args));
|
|
21
|
+
}
|
|
22
|
+
allButOtherBotsFilter() {
|
|
23
|
+
return this.getNearestEntity((e) => { var _a, _b, _c; return e.type === "player" && ((_c = !((_a = this.botNames) === null || _a === void 0 ? void 0 : _a.includes((_b = e.username) !== null && _b !== void 0 ? _b : ""))) !== null && _c !== void 0 ? _c : true); });
|
|
24
|
+
}
|
|
25
|
+
static allButOtherBotsFilter(bot, ...names) {
|
|
26
|
+
return FilterFunctions.getNearestEntity(bot, (e) => { var _a; return e.type === "player" && !names.includes((_a = e.username) !== null && _a !== void 0 ? _a : ""); });
|
|
27
|
+
}
|
|
28
|
+
specificNamesFilter() {
|
|
29
|
+
return this.getNearestEntity((e) => { var _a, _b, _c; return e.type === "player" && ((_c = (_a = this.specificNames) === null || _a === void 0 ? void 0 : _a.includes((_b = e.username) !== null && _b !== void 0 ? _b : "")) !== null && _c !== void 0 ? _c : true); });
|
|
30
|
+
}
|
|
31
|
+
static specificNamesFilter(bot, ...names) {
|
|
32
|
+
return FilterFunctions.getNearestEntity(bot, (e) => { var _a; return e.type === "player" && names.includes((_a = e.username) !== null && _a !== void 0 ? _a : ""); });
|
|
33
|
+
}
|
|
34
|
+
nearestCrystalFilter() {
|
|
35
|
+
return this.getNearestEntity((e) => e.name === "ender_crystal");
|
|
36
|
+
}
|
|
37
|
+
static nearestCrystalFilter(bot) {
|
|
38
|
+
return FilterFunctions.getNearestEntity(bot, (e) => e.name === "ender_crystal");
|
|
39
|
+
}
|
|
40
|
+
entityAtPosition(position) {
|
|
41
|
+
return this.getNearestEntity((entity) => entity.position.offset(-0.5, -1, -0.5).equals(position));
|
|
42
|
+
}
|
|
43
|
+
static entityAtPosition(bot, position) { }
|
|
44
|
+
}
|
|
45
|
+
exports.FilterFunctions = FilterFunctions;
|