@nxg-org/mineflayer-util-plugin 1.3.14 → 1.3.15
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/entityFunctions.js +3 -5
- package/lib/example.d.ts +1 -0
- package/lib/example.js +97 -0
- package/lib/movementFunctions.d.ts +2 -2
- package/lib/movementFunctions.js +4 -8
- package/lib/static/aabbUtil.js +1 -1
- package/package.json +3 -2
package/lib/entityFunctions.js
CHANGED
|
@@ -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] ===
|
|
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] ===
|
|
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
|
}
|
|
@@ -97,7 +95,7 @@ class EntityFunctions {
|
|
|
97
95
|
}
|
|
98
96
|
}
|
|
99
97
|
getPlayerAABB(entity) {
|
|
100
|
-
return this.getEntityAABBRaw({ position: entity.position, height: 1.8, width: 0.
|
|
98
|
+
return this.getEntityAABBRaw({ position: entity.position, height: 1.8, width: 0.6 });
|
|
101
99
|
}
|
|
102
100
|
getEntityAABBRaw(entity) {
|
|
103
101
|
const w = entity.width ? entity.width / 2 : entity.height / 2;
|
package/lib/example.d.ts
ADDED
|
@@ -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,
|
|
41
|
-
forceLookAt(pos: Vec3,
|
|
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
|
}
|
package/lib/movementFunctions.js
CHANGED
|
@@ -92,23 +92,19 @@ class MovementFunctions {
|
|
|
92
92
|
}
|
|
93
93
|
return false;
|
|
94
94
|
}
|
|
95
|
-
forceLook(yaw, pitch,
|
|
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.
|
|
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,
|
|
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.
|
|
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) { }
|
package/lib/static/aabbUtil.js
CHANGED
|
@@ -26,7 +26,7 @@ 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.
|
|
29
|
+
return getEntityAABBRaw({ position: entity.position, height: 1.8, width: 0.6 });
|
|
30
30
|
}
|
|
31
31
|
AABBUtils.getPlayerAABB = getPlayerAABB;
|
|
32
32
|
function getEntityAABBRaw(entity) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxg-org/mineflayer-util-plugin",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.15",
|
|
4
4
|
"description": "mineflayer utils for NextGEN mineflayer plugins.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mineflayer",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"types": "lib/index.d.ts",
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "npx tsc",
|
|
19
|
-
"prepublish": "npm run build"
|
|
19
|
+
"prepublish": "npm run build",
|
|
20
|
+
"test": "node --trace-warnings lib/example.js"
|
|
20
21
|
},
|
|
21
22
|
"dependencies": {
|
|
22
23
|
"minecraft-data": "^2.97.0",
|