@nxg-org/mineflayer-util-plugin 1.3.11 → 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.d.ts +9 -0
- package/lib/entityFunctions.js +17 -7
- package/lib/example.d.ts +1 -0
- package/lib/example.js +97 -0
- package/lib/index.d.ts +1 -8
- package/lib/index.js +4 -1
- package/lib/movementFunctions.d.ts +2 -2
- package/lib/movementFunctions.js +6 -10
- package/lib/static/aabbUtil.d.ts +21 -0
- package/lib/static/aabbUtil.js +38 -0
- package/lib/static/index.d.ts +2 -0
- package/lib/static/index.js +14 -0
- package/lib/static/mathUtil.d.ts +24 -0
- package/lib/static/mathUtil.js +75 -0
- package/package.json +3 -2
package/lib/entityFunctions.d.ts
CHANGED
|
@@ -41,6 +41,15 @@ export declare class EntityFunctions {
|
|
|
41
41
|
getDistanceToEntity(entity: Entity): number;
|
|
42
42
|
getDistanceBetweenEntities(first: Entity, second: Entity): number;
|
|
43
43
|
getEntityAABB(entity: {
|
|
44
|
+
type: string;
|
|
45
|
+
position: Vec3;
|
|
46
|
+
height: number;
|
|
47
|
+
width?: number;
|
|
48
|
+
}): AABB;
|
|
49
|
+
getPlayerAABB(entity: {
|
|
50
|
+
position: Vec3;
|
|
51
|
+
}): AABB;
|
|
52
|
+
getEntityAABBRaw(entity: {
|
|
44
53
|
position: Vec3;
|
|
45
54
|
height: number;
|
|
46
55
|
width?: number;
|
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
|
}
|
|
@@ -67,7 +65,7 @@ class EntityFunctions {
|
|
|
67
65
|
*/
|
|
68
66
|
getHealthFromMetadata(metadata) {
|
|
69
67
|
var _a;
|
|
70
|
-
return (_a =
|
|
68
|
+
return (_a = Number(metadata[this.healthSlot]) + Number(metadata[this.healthSlot + 4])) !== null && _a !== void 0 ? _a : undefined;
|
|
71
69
|
}
|
|
72
70
|
/**
|
|
73
71
|
* TODO: Version specific right now. Generalize. Unknown method.
|
|
@@ -87,11 +85,23 @@ class EntityFunctions {
|
|
|
87
85
|
}
|
|
88
86
|
getEntityAABB(entity) {
|
|
89
87
|
var _a;
|
|
90
|
-
|
|
88
|
+
switch (entity.type) {
|
|
89
|
+
case "player":
|
|
90
|
+
return this.getPlayerAABB({ position: entity.position });
|
|
91
|
+
case "mob":
|
|
92
|
+
default:
|
|
93
|
+
//TODO: Implement better AABBs. However, this may just be correct.
|
|
94
|
+
return this.getEntityAABBRaw({ position: entity.position, height: entity.height, width: (_a = entity.width) !== null && _a !== void 0 ? _a : entity.height });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
getPlayerAABB(entity) {
|
|
98
|
+
return this.getEntityAABBRaw({ position: entity.position, height: 1.8, width: 0.6 });
|
|
99
|
+
}
|
|
100
|
+
getEntityAABBRaw(entity) {
|
|
101
|
+
const w = entity.width ? entity.width / 2 : entity.height / 2;
|
|
91
102
|
const { x, y, z } = entity.position;
|
|
92
103
|
return new aabb_1.AABB(-w, 0, -w, w, entity.height, w).offset(x, y, z);
|
|
93
104
|
}
|
|
94
|
-
//Stolen from mineflayer.
|
|
95
105
|
parseMetadata(packetMetadata, entityMetadata = {}) {
|
|
96
106
|
if (packetMetadata !== undefined) {
|
|
97
107
|
for (const { key, value } of packetMetadata) {
|
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
|
+
}));
|
package/lib/index.d.ts
CHANGED
|
@@ -15,15 +15,8 @@ declare module "mineflayer" {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
declare module "prismarine-entity" {
|
|
18
|
-
interface Entity {
|
|
19
|
-
attributes: {
|
|
20
|
-
[index: string]: {
|
|
21
|
-
value: number;
|
|
22
|
-
modifiers: any[];
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
18
|
}
|
|
27
19
|
export default function inject(bot: Bot): void;
|
|
28
20
|
export { AABB } from "./calcs/aabb";
|
|
29
21
|
export { InterceptFunctions } from "./calcs/intercept";
|
|
22
|
+
export { AABBUtils, MathUtils } from "./static";
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InterceptFunctions = exports.AABB = void 0;
|
|
3
|
+
exports.MathUtils = exports.AABBUtils = exports.InterceptFunctions = exports.AABB = void 0;
|
|
4
4
|
const utilFunctions_1 = require("./utilFunctions");
|
|
5
5
|
const mineflayer_pathfinder_1 = require("mineflayer-pathfinder");
|
|
6
6
|
function inject(bot) {
|
|
@@ -13,3 +13,6 @@ var aabb_1 = require("./calcs/aabb");
|
|
|
13
13
|
Object.defineProperty(exports, "AABB", { enumerable: true, get: function () { return aabb_1.AABB; } });
|
|
14
14
|
var intercept_1 = require("./calcs/intercept");
|
|
15
15
|
Object.defineProperty(exports, "InterceptFunctions", { enumerable: true, get: function () { return intercept_1.InterceptFunctions; } });
|
|
16
|
+
var static_1 = require("./static");
|
|
17
|
+
Object.defineProperty(exports, "AABBUtils", { enumerable: true, get: function () { return static_1.AABBUtils; } });
|
|
18
|
+
Object.defineProperty(exports, "MathUtils", { enumerable: true, get: function () { return static_1.MathUtils; } });
|
|
@@ -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, update?: boolean): void;
|
|
41
|
-
forceLookAt(pos: Vec3, update?: boolean): void;
|
|
40
|
+
forceLook(yaw: number, pitch: number, update?: boolean, onGround?: boolean): void;
|
|
41
|
+
forceLookAt(pos: Vec3, update?: boolean, onGround?: boolean): void;
|
|
42
42
|
lazyTeleport(endPos: Vec3): void;
|
|
43
43
|
}
|
package/lib/movementFunctions.js
CHANGED
|
@@ -92,23 +92,19 @@ class MovementFunctions {
|
|
|
92
92
|
}
|
|
93
93
|
return false;
|
|
94
94
|
}
|
|
95
|
-
forceLook(yaw, pitch, update = false) {
|
|
95
|
+
forceLook(yaw, pitch, update = false, onGround) {
|
|
96
96
|
const notchianYawAndPitch = { yaw: this.bot.util.math.toNotchianYaw(yaw), pitch: this.bot.util.math.toNotchianPitch(pitch) };
|
|
97
|
-
this.bot._client.write("look", notchianYawAndPitch);
|
|
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, update = false) {
|
|
102
|
+
forceLookAt(pos, update = false, onGround) {
|
|
105
103
|
const { yaw, pitch } = this.bot.util.math.pointToYawAndPitch(this.bot, pos);
|
|
106
104
|
const nyp = { yaw: this.bot.util.math.toNotchianYaw(yaw), pitch: this.bot.util.math.toNotchianPitch(pitch) };
|
|
107
|
-
this.bot._client.write("look", nyp);
|
|
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) { }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Block } from "prismarine-block";
|
|
2
|
+
import { AABB } from "../calcs/aabb";
|
|
3
|
+
import type { Vec3 } from "vec3";
|
|
4
|
+
export declare namespace AABBUtils {
|
|
5
|
+
function getBlockAABB(block: Block, height?: number): AABB;
|
|
6
|
+
function getBlockPosAABB(block: Vec3, height?: number): AABB;
|
|
7
|
+
function getEntityAABB(entity: {
|
|
8
|
+
type: string;
|
|
9
|
+
position: Vec3;
|
|
10
|
+
height: number;
|
|
11
|
+
width?: number;
|
|
12
|
+
}): AABB;
|
|
13
|
+
function getPlayerAABB(entity: {
|
|
14
|
+
position: Vec3;
|
|
15
|
+
}): AABB;
|
|
16
|
+
function getEntityAABBRaw(entity: {
|
|
17
|
+
position: Vec3;
|
|
18
|
+
height: number;
|
|
19
|
+
width?: number;
|
|
20
|
+
}): AABB;
|
|
21
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AABBUtils = void 0;
|
|
4
|
+
const aabb_1 = require("../calcs/aabb");
|
|
5
|
+
var AABBUtils;
|
|
6
|
+
(function (AABBUtils) {
|
|
7
|
+
function getBlockAABB(block, height = 1) {
|
|
8
|
+
const { x, y, z } = block.position;
|
|
9
|
+
return new aabb_1.AABB(x, y, z, x + 1, y + height, z + 1);
|
|
10
|
+
}
|
|
11
|
+
AABBUtils.getBlockAABB = getBlockAABB;
|
|
12
|
+
function getBlockPosAABB(block, height = 1) {
|
|
13
|
+
const { x, y, z } = block.floored();
|
|
14
|
+
return new aabb_1.AABB(x, y, z, x + 1, y + height, z + 1);
|
|
15
|
+
}
|
|
16
|
+
AABBUtils.getBlockPosAABB = getBlockPosAABB;
|
|
17
|
+
function getEntityAABB(entity) {
|
|
18
|
+
var _a;
|
|
19
|
+
switch (entity.type) {
|
|
20
|
+
case "player":
|
|
21
|
+
return getPlayerAABB({ position: entity.position });
|
|
22
|
+
case "mob":
|
|
23
|
+
default: //TODO: Implement better AABBs. However, this may just be correct.
|
|
24
|
+
return getEntityAABBRaw({ position: entity.position, height: entity.height, width: (_a = entity.width) !== null && _a !== void 0 ? _a : entity.height });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
AABBUtils.getEntityAABB = getEntityAABB;
|
|
28
|
+
function getPlayerAABB(entity) {
|
|
29
|
+
return getEntityAABBRaw({ position: entity.position, height: 1.8, width: 0.6 });
|
|
30
|
+
}
|
|
31
|
+
AABBUtils.getPlayerAABB = getPlayerAABB;
|
|
32
|
+
function getEntityAABBRaw(entity) {
|
|
33
|
+
const w = entity.width ? entity.width / 2 : entity.height / 2;
|
|
34
|
+
const { x, y, z } = entity.position;
|
|
35
|
+
return new aabb_1.AABB(-w, 0, -w, w, entity.height, w).offset(x, y, z);
|
|
36
|
+
}
|
|
37
|
+
AABBUtils.getEntityAABBRaw = getEntityAABBRaw;
|
|
38
|
+
})(AABBUtils = exports.AABBUtils || (exports.AABBUtils = {}));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./aabbUtil"), exports);
|
|
14
|
+
__exportStar(require("./mathUtil"), exports);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Bot } from "mineflayer";
|
|
2
|
+
import { Vec3 } from "vec3";
|
|
3
|
+
export declare namespace MathUtils {
|
|
4
|
+
const toNotchianYaw: (yaw: number) => number;
|
|
5
|
+
const toNotchianPitch: (pitch: number) => number;
|
|
6
|
+
const fromNotchianYawByte: (yaw: number) => number;
|
|
7
|
+
const fromNotchianPitchByte: (pitch: number) => number;
|
|
8
|
+
function euclideanMod(numerator: number, denominator: number): number;
|
|
9
|
+
function toRadians(degrees: number): number;
|
|
10
|
+
function toDegrees(radians: number): number;
|
|
11
|
+
function fromNotchianYaw(yaw: number): number;
|
|
12
|
+
function fromNotchianPitch(pitch: number): number;
|
|
13
|
+
function fromNotchVelocity(vel: Vec3): Vec3;
|
|
14
|
+
function pointToYawAndPitch(bot: Bot, point: Vec3): {
|
|
15
|
+
yaw: number;
|
|
16
|
+
pitch: number;
|
|
17
|
+
};
|
|
18
|
+
function dirToYawAndPitch(dir: Vec3): {
|
|
19
|
+
yaw: number;
|
|
20
|
+
pitch: number;
|
|
21
|
+
};
|
|
22
|
+
function getYaw(origin: Vec3, destination: Vec3): number;
|
|
23
|
+
function yawPitchAndSpeedToDir(yaw: number, pitch: number, speed: number): Vec3;
|
|
24
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MathUtils = void 0;
|
|
4
|
+
const vec3_1 = require("vec3");
|
|
5
|
+
const PI = Math.PI;
|
|
6
|
+
const PI_2 = Math.PI * 2;
|
|
7
|
+
const TO_RAD = PI / 180;
|
|
8
|
+
const TO_DEG = 1 / TO_RAD;
|
|
9
|
+
const FROM_NOTCH_BYTE = 360 / 256;
|
|
10
|
+
// From wiki.vg: Velocity is believed to be in units of 1/8000 of a block per server tick (50ms)
|
|
11
|
+
const FROM_NOTCH_VEL = 1 / 8000;
|
|
12
|
+
var MathUtils;
|
|
13
|
+
(function (MathUtils) {
|
|
14
|
+
MathUtils.toNotchianYaw = (yaw) => toDegrees(PI - yaw);
|
|
15
|
+
MathUtils.toNotchianPitch = (pitch) => toDegrees(-pitch);
|
|
16
|
+
MathUtils.fromNotchianYawByte = (yaw) => fromNotchianYaw(yaw * FROM_NOTCH_BYTE);
|
|
17
|
+
MathUtils.fromNotchianPitchByte = (pitch) => fromNotchianPitch(pitch * FROM_NOTCH_BYTE);
|
|
18
|
+
function euclideanMod(numerator, denominator) {
|
|
19
|
+
const result = numerator % denominator;
|
|
20
|
+
return result < 0 ? result + denominator : result;
|
|
21
|
+
}
|
|
22
|
+
MathUtils.euclideanMod = euclideanMod;
|
|
23
|
+
function toRadians(degrees) {
|
|
24
|
+
return TO_RAD * degrees;
|
|
25
|
+
}
|
|
26
|
+
MathUtils.toRadians = toRadians;
|
|
27
|
+
function toDegrees(radians) {
|
|
28
|
+
return TO_DEG * radians;
|
|
29
|
+
}
|
|
30
|
+
MathUtils.toDegrees = toDegrees;
|
|
31
|
+
function fromNotchianYaw(yaw) {
|
|
32
|
+
return euclideanMod(PI - toRadians(yaw), PI_2);
|
|
33
|
+
}
|
|
34
|
+
MathUtils.fromNotchianYaw = fromNotchianYaw;
|
|
35
|
+
function fromNotchianPitch(pitch) {
|
|
36
|
+
return euclideanMod(toRadians(-pitch) + PI, PI_2) - PI;
|
|
37
|
+
}
|
|
38
|
+
MathUtils.fromNotchianPitch = fromNotchianPitch;
|
|
39
|
+
function fromNotchVelocity(vel) {
|
|
40
|
+
return new vec3_1.Vec3(vel.x * FROM_NOTCH_VEL, vel.y * FROM_NOTCH_VEL, vel.z * FROM_NOTCH_VEL);
|
|
41
|
+
}
|
|
42
|
+
MathUtils.fromNotchVelocity = fromNotchVelocity;
|
|
43
|
+
function pointToYawAndPitch(bot, point) {
|
|
44
|
+
const delta = point.minus(bot.entity.position.offset(0, bot.entity.height, 0));
|
|
45
|
+
return dirToYawAndPitch(delta);
|
|
46
|
+
}
|
|
47
|
+
MathUtils.pointToYawAndPitch = pointToYawAndPitch;
|
|
48
|
+
function dirToYawAndPitch(dir) {
|
|
49
|
+
const yaw = Math.atan2(-dir.x, -dir.z);
|
|
50
|
+
const groundDistance = Math.sqrt(dir.x * dir.x + dir.z * dir.z);
|
|
51
|
+
const pitch = Math.atan2(dir.y, groundDistance);
|
|
52
|
+
return { yaw: yaw, pitch: pitch };
|
|
53
|
+
}
|
|
54
|
+
MathUtils.dirToYawAndPitch = dirToYawAndPitch;
|
|
55
|
+
function getYaw(origin, destination) {
|
|
56
|
+
const xDistance = destination.x - origin.x;
|
|
57
|
+
const zDistance = destination.z - origin.z;
|
|
58
|
+
const yaw = Math.atan2(xDistance, zDistance) + Math.PI;
|
|
59
|
+
return yaw;
|
|
60
|
+
}
|
|
61
|
+
MathUtils.getYaw = getYaw;
|
|
62
|
+
//Scuffed.
|
|
63
|
+
function yawPitchAndSpeedToDir(yaw, pitch, speed) {
|
|
64
|
+
const thetaY = PI + yaw;
|
|
65
|
+
const thetaP = pitch;
|
|
66
|
+
const x = speed * Math.sin(thetaY);
|
|
67
|
+
const y = speed * Math.sin(thetaP);
|
|
68
|
+
const z = speed * Math.cos(thetaY);
|
|
69
|
+
const VxMag = Math.sqrt(x * x + z * z);
|
|
70
|
+
const VxRatio = Math.sqrt(VxMag * VxMag - y * y);
|
|
71
|
+
const allRatio = VxRatio / VxMag;
|
|
72
|
+
return new vec3_1.Vec3(x * allRatio, y, z * allRatio);
|
|
73
|
+
}
|
|
74
|
+
MathUtils.yawPitchAndSpeedToDir = yawPitchAndSpeedToDir;
|
|
75
|
+
})(MathUtils = exports.MathUtils || (exports.MathUtils = {}));
|
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",
|