@nxg-org/mineflayer-util-plugin 1.0.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.
- package/LICENSE +674 -0
- package/lib/WorldFunctions.d.ts +10 -0
- package/lib/WorldFunctions.js +18 -0
- package/lib/calcs/aabb.d.ts +36 -0
- package/lib/calcs/aabb.js +194 -0
- package/lib/commonSense.d.ts +22 -0
- package/lib/commonSense.js +220 -0
- package/lib/customImplementations/inventory.d.ts +10 -0
- package/lib/customImplementations/inventory.js +95 -0
- package/lib/entityFunctions.d.ts +36 -0
- package/lib/entityFunctions.js +78 -0
- package/lib/filterFunctions.d.ts +23 -0
- package/lib/filterFunctions.js +45 -0
- package/lib/index.d.ts +27 -0
- package/lib/index.js +7 -0
- package/lib/inventoryFunctions.d.ts +45 -0
- package/lib/inventoryFunctions.js +208 -0
- package/lib/mathUtil.d.ts +23 -0
- package/lib/mathUtil.js +49 -0
- package/lib/movementFunctions.d.ts +43 -0
- package/lib/movementFunctions.js +109 -0
- package/lib/predictiveFunctions.d.ts +25 -0
- package/lib/predictiveFunctions.js +172 -0
- package/lib/utilFunctions.d.ts +50 -0
- package/lib/utilFunctions.js +140 -0
- package/lib/worldRelated/predictiveWorld.d.ts +41 -0
- package/lib/worldRelated/predictiveWorld.js +108 -0
- package/lib/worldRelated/raycastIterator.d.ts +45 -0
- package/lib/worldRelated/raycastIterator.js +114 -0
- package/package.json +33 -0
- package/src/WorldFunctions.ts +19 -0
- package/src/calcs/aabb.ts +218 -0
- package/src/commonSense.ts +189 -0
- package/src/customImplementations/inventory.ts +90 -0
- package/src/entityFunctions.ts +71 -0
- package/src/filterFunctions.ts +54 -0
- package/src/index.ts +29 -0
- package/src/inventoryFunctions.ts +187 -0
- package/src/mathUtil.ts +56 -0
- package/src/movementFunctions.ts +116 -0
- package/src/predictiveFunctions.ts +187 -0
- package/src/utilFunctions.ts +152 -0
- package/src/worldRelated/predictiveWorld.ts +109 -0
- package/src/worldRelated/raycastIterator.ts +136 -0
- package/tsconfig.json +17 -0
|
@@ -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;
|
|
@@ -0,0 +1,194 @@
|
|
|
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) {
|
|
7
|
+
this.minX = x0;
|
|
8
|
+
this.minY = y0;
|
|
9
|
+
this.minZ = z0;
|
|
10
|
+
this.maxX = x1;
|
|
11
|
+
this.maxY = y1;
|
|
12
|
+
this.maxZ = z1;
|
|
13
|
+
}
|
|
14
|
+
static fromVecs(min, max) {
|
|
15
|
+
return new AABB(min.x, min.y, min.z, max.x, max.y, max.z);
|
|
16
|
+
}
|
|
17
|
+
set(x0, y0, z0, x1, y1, z1) {
|
|
18
|
+
this.minX = x0;
|
|
19
|
+
this.minY = y0;
|
|
20
|
+
this.minZ = z0;
|
|
21
|
+
this.maxX = x1;
|
|
22
|
+
this.maxY = y1;
|
|
23
|
+
this.maxZ = z1;
|
|
24
|
+
}
|
|
25
|
+
clone() {
|
|
26
|
+
return new AABB(this.minX, this.minY, this.minZ, this.maxX, this.maxY, this.maxZ);
|
|
27
|
+
}
|
|
28
|
+
toArray() {
|
|
29
|
+
return [this.minX, this.minY, this.minZ, this.maxX, this.maxY, this.maxZ];
|
|
30
|
+
}
|
|
31
|
+
toMinAndMaxArrays() {
|
|
32
|
+
return { 0: [this.minX, this.minY, this.minZ], 1: [this.maxX, this.maxY, this.maxZ] };
|
|
33
|
+
}
|
|
34
|
+
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) };
|
|
36
|
+
}
|
|
37
|
+
floor() {
|
|
38
|
+
this.minX = Math.floor(this.minX);
|
|
39
|
+
this.minY = Math.floor(this.minY);
|
|
40
|
+
this.minZ = Math.floor(this.minZ);
|
|
41
|
+
this.maxX = Math.floor(this.maxX);
|
|
42
|
+
this.maxY = Math.floor(this.maxY);
|
|
43
|
+
this.maxZ = Math.floor(this.maxZ);
|
|
44
|
+
}
|
|
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;
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
contract(x, y, z) {
|
|
61
|
+
this.minX += x;
|
|
62
|
+
this.minY += y;
|
|
63
|
+
this.minZ += z;
|
|
64
|
+
this.maxX -= x;
|
|
65
|
+
this.maxY -= y;
|
|
66
|
+
this.maxZ -= z;
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
expand(x, y, z) {
|
|
70
|
+
this.minX -= x;
|
|
71
|
+
this.minY -= y;
|
|
72
|
+
this.minZ -= z;
|
|
73
|
+
this.maxX += x;
|
|
74
|
+
this.maxY += y;
|
|
75
|
+
this.maxZ += z;
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
offset(x, y, z) {
|
|
79
|
+
this.minX += x;
|
|
80
|
+
this.minY += y;
|
|
81
|
+
this.minZ += z;
|
|
82
|
+
this.maxX += x;
|
|
83
|
+
this.maxY += y;
|
|
84
|
+
this.maxZ += z;
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
computeOffsetX(other, offsetX) {
|
|
88
|
+
if (other.maxY > this.minY && other.minY < this.maxY && other.maxZ > this.minZ && other.minZ < this.maxZ) {
|
|
89
|
+
if (offsetX > 0.0 && other.maxX <= this.minX) {
|
|
90
|
+
offsetX = Math.min(this.minX - other.maxX, offsetX);
|
|
91
|
+
}
|
|
92
|
+
else if (offsetX < 0.0 && other.minX >= this.maxX) {
|
|
93
|
+
offsetX = Math.max(this.maxX - other.minX, offsetX);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return offsetX;
|
|
97
|
+
}
|
|
98
|
+
computeOffsetY(other, offsetY) {
|
|
99
|
+
if (other.maxX > this.minX && other.minX < this.maxX && other.maxZ > this.minZ && other.minZ < this.maxZ) {
|
|
100
|
+
if (offsetY > 0.0 && other.maxY <= this.minY) {
|
|
101
|
+
offsetY = Math.min(this.minY - other.maxY, offsetY);
|
|
102
|
+
}
|
|
103
|
+
else if (offsetY < 0.0 && other.minY >= this.maxY) {
|
|
104
|
+
offsetY = Math.max(this.maxY - other.minY, offsetY);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return offsetY;
|
|
108
|
+
}
|
|
109
|
+
computeOffsetZ(other, offsetZ) {
|
|
110
|
+
if (other.maxX > this.minX && other.minX < this.maxX && other.maxY > this.minY && other.minY < this.maxY) {
|
|
111
|
+
if (offsetZ > 0.0 && other.maxZ <= this.minZ) {
|
|
112
|
+
offsetZ = Math.min(this.minZ - other.maxZ, offsetZ);
|
|
113
|
+
}
|
|
114
|
+
else if (offsetZ < 0.0 && other.minZ >= this.maxZ) {
|
|
115
|
+
offsetZ = Math.max(this.maxZ - other.minZ, offsetZ);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return offsetZ;
|
|
119
|
+
}
|
|
120
|
+
intersects(other) {
|
|
121
|
+
return (this.minX < other.maxX &&
|
|
122
|
+
this.maxX > other.minX &&
|
|
123
|
+
this.minY < other.maxY &&
|
|
124
|
+
this.maxY > other.minY &&
|
|
125
|
+
this.minZ < other.maxZ &&
|
|
126
|
+
this.maxZ > other.minZ);
|
|
127
|
+
}
|
|
128
|
+
intersectsRay(origin, direction) {
|
|
129
|
+
const d = this.distanceFromRay(origin, direction);
|
|
130
|
+
if (d === Infinity) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
return new vec3_1.Vec3(origin.x + direction.x * d, origin.y + direction.y * d, origin.z + direction.z * d);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
distanceFromRay(origin, direction) {
|
|
138
|
+
const ro = origin.toArray();
|
|
139
|
+
const rd = direction.normalize().toArray();
|
|
140
|
+
const aabb = this.toMinAndMaxArrays();
|
|
141
|
+
const dims = ro.length; // will change later.
|
|
142
|
+
let lo = -Infinity;
|
|
143
|
+
let hi = +Infinity;
|
|
144
|
+
// let test = origin.clone()
|
|
145
|
+
for (let i = 0; i < dims; i++) {
|
|
146
|
+
let dimLo = (aabb[0][i] - ro[i]) / rd[i];
|
|
147
|
+
let dimHi = (aabb[1][i] - ro[i]) / rd[i];
|
|
148
|
+
if (dimLo > dimHi) {
|
|
149
|
+
let tmp = dimLo;
|
|
150
|
+
dimLo = dimHi;
|
|
151
|
+
dimHi = tmp;
|
|
152
|
+
}
|
|
153
|
+
// let num;
|
|
154
|
+
// switch (i) {
|
|
155
|
+
// case 0:
|
|
156
|
+
// num = "x"
|
|
157
|
+
// break;
|
|
158
|
+
// case 1:
|
|
159
|
+
// num = "y"
|
|
160
|
+
// break;
|
|
161
|
+
// case 2:
|
|
162
|
+
// num = "z"
|
|
163
|
+
// break;
|
|
164
|
+
// }
|
|
165
|
+
// console.log(num, aabb[0][i], aabb[1][i], ro[i], "highest overall:", lo, hi )
|
|
166
|
+
if (dimHi < lo || dimLo > hi) {
|
|
167
|
+
console.log("fuck", dimHi < lo, dimLo > hi);
|
|
168
|
+
return Infinity;
|
|
169
|
+
}
|
|
170
|
+
if (dimLo > lo)
|
|
171
|
+
lo = dimLo;
|
|
172
|
+
if (dimHi < hi)
|
|
173
|
+
hi = dimHi;
|
|
174
|
+
}
|
|
175
|
+
return lo > hi ? Infinity : lo;
|
|
176
|
+
}
|
|
177
|
+
equals(other) {
|
|
178
|
+
return (this.minX === other.minX &&
|
|
179
|
+
this.minY === other.minY &&
|
|
180
|
+
this.minZ === other.minZ &&
|
|
181
|
+
this.maxX === other.maxX &&
|
|
182
|
+
this.maxY === other.maxY &&
|
|
183
|
+
this.maxZ === other.maxZ);
|
|
184
|
+
}
|
|
185
|
+
distanceTo(pos, heightOffset = 0) {
|
|
186
|
+
const { x, y, z } = pos.offset(0, heightOffset, 0);
|
|
187
|
+
let dx = Math.max(this.minX - x, 0, x - this.maxX);
|
|
188
|
+
let dy = Math.max(this.minY - y, 0, y - this.maxY);
|
|
189
|
+
let dz = Math.max(this.minZ - z, 0, z - this.maxZ);
|
|
190
|
+
return Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
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;
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
|
27
|
+
*/
|
|
28
|
+
getHealth(entity?: Entity): number;
|
|
29
|
+
getDistanceToEntity(entity: Entity): number;
|
|
30
|
+
getDistanceBetweenEntities(first: Entity, second: Entity): number;
|
|
31
|
+
getEntityAABB(entity: {
|
|
32
|
+
position: Vec3;
|
|
33
|
+
height: number;
|
|
34
|
+
width?: number;
|
|
35
|
+
}): AABB;
|
|
36
|
+
}
|