@nxg-org/mineflayer-util-plugin 1.3.12 → 1.3.13
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 +13 -1
- package/lib/index.d.ts +1 -8
- package/lib/index.js +4 -1
- 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 +1 -1
package/lib/entityFunctions.d.ts
CHANGED
|
@@ -41,9 +41,18 @@ 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;
|
|
44
45
|
position: Vec3;
|
|
45
46
|
height: number;
|
|
46
47
|
width?: number;
|
|
47
48
|
}): AABB;
|
|
49
|
+
getPlayerAABB(entity: {
|
|
50
|
+
position: Vec3;
|
|
51
|
+
}): AABB;
|
|
52
|
+
getEntityAABBRaw(entity: {
|
|
53
|
+
position: Vec3;
|
|
54
|
+
height: number;
|
|
55
|
+
width: number;
|
|
56
|
+
}): AABB;
|
|
48
57
|
private parseMetadata;
|
|
49
58
|
}
|
package/lib/entityFunctions.js
CHANGED
|
@@ -87,7 +87,19 @@ class EntityFunctions {
|
|
|
87
87
|
}
|
|
88
88
|
getEntityAABB(entity) {
|
|
89
89
|
var _a;
|
|
90
|
-
|
|
90
|
+
switch (entity.type) {
|
|
91
|
+
case "player":
|
|
92
|
+
return this.getPlayerAABB({ position: entity.position });
|
|
93
|
+
case "mob":
|
|
94
|
+
default: //TODO: Implement better AABBs. However, this may just be correct.
|
|
95
|
+
return this.getEntityAABBRaw({ position: entity.position, height: entity.height, width: (_a = entity.width) !== null && _a !== void 0 ? _a : entity.height });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
getPlayerAABB(entity) {
|
|
99
|
+
return this.getEntityAABBRaw({ position: entity.position, height: 1.8, width: 0.3 });
|
|
100
|
+
}
|
|
101
|
+
getEntityAABBRaw(entity) {
|
|
102
|
+
const w = entity.width / 2;
|
|
91
103
|
const { x, y, z } = entity.position;
|
|
92
104
|
return new aabb_1.AABB(-w, 0, -w, w, entity.height, w).offset(x, y, z);
|
|
93
105
|
}
|
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; } });
|
|
@@ -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.3 });
|
|
30
|
+
}
|
|
31
|
+
AABBUtils.getPlayerAABB = getPlayerAABB;
|
|
32
|
+
function getEntityAABBRaw(entity) {
|
|
33
|
+
const w = entity.width / 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 = {}));
|