@nxg-org/mineflayer-util-plugin 1.3.10 → 1.3.14

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.
@@ -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;
@@ -67,7 +67,7 @@ class EntityFunctions {
67
67
  */
68
68
  getHealthFromMetadata(metadata) {
69
69
  var _a;
70
- return (_a = (Number(metadata[this.healthSlot]) + Number(metadata[this.healthSlot + 4]))) !== null && _a !== void 0 ? _a : undefined;
70
+ return (_a = Number(metadata[this.healthSlot]) + Number(metadata[this.healthSlot + 4])) !== null && _a !== void 0 ? _a : undefined;
71
71
  }
72
72
  /**
73
73
  * TODO: Version specific right now. Generalize. Unknown method.
@@ -87,11 +87,23 @@ class EntityFunctions {
87
87
  }
88
88
  getEntityAABB(entity) {
89
89
  var _a;
90
- const w = (_a = entity.width) !== null && _a !== void 0 ? _a : entity.height / 2;
90
+ switch (entity.type) {
91
+ case "player":
92
+ return this.getPlayerAABB({ position: entity.position });
93
+ case "mob":
94
+ default:
95
+ //TODO: Implement better AABBs. However, this may just be correct.
96
+ return this.getEntityAABBRaw({ position: entity.position, height: entity.height, width: (_a = entity.width) !== null && _a !== void 0 ? _a : entity.height });
97
+ }
98
+ }
99
+ getPlayerAABB(entity) {
100
+ return this.getEntityAABBRaw({ position: entity.position, height: 1.8, width: 0.3 });
101
+ }
102
+ getEntityAABBRaw(entity) {
103
+ const w = entity.width ? entity.width / 2 : entity.height / 2;
91
104
  const { x, y, z } = entity.position;
92
105
  return new aabb_1.AABB(-w, 0, -w, w, entity.height, w).offset(x, y, z);
93
106
  }
94
- //Stolen from mineflayer.
95
107
  parseMetadata(packetMetadata, entityMetadata = {}) {
96
108
  if (packetMetadata !== undefined) {
97
109
  for (const { key, value } of packetMetadata) {
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, onGround?: boolean, update?: boolean): void;
41
+ forceLookAt(pos: Vec3, onGround?: boolean, update?: boolean): void;
42
42
  lazyTeleport(endPos: Vec3): void;
43
43
  }
@@ -92,19 +92,19 @@ class MovementFunctions {
92
92
  }
93
93
  return false;
94
94
  }
95
- forceLook(yaw, pitch, update = false) {
95
+ forceLook(yaw, pitch, onGround, update = false) {
96
96
  const notchianYawAndPitch = { yaw: this.bot.util.math.toNotchianYaw(yaw), pitch: this.bot.util.math.toNotchianPitch(pitch) };
97
- this.bot._client.write("look", Object.assign(Object.assign({}, notchianYawAndPitch), { onGround: this.bot.entity.onGround }));
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
99
  this.bot.entity.yaw = yaw;
100
100
  this.bot.entity.pitch = pitch;
101
101
  // this.bot.look(yaw, pitch, true);
102
102
  }
103
103
  }
104
- forceLookAt(pos, update = false) {
104
+ forceLookAt(pos, onGround, update = false) {
105
105
  const { yaw, pitch } = this.bot.util.math.pointToYawAndPitch(this.bot, pos);
106
106
  const nyp = { yaw: this.bot.util.math.toNotchianYaw(yaw), pitch: this.bot.util.math.toNotchianPitch(pitch) };
107
- this.bot._client.write("look", Object.assign(Object.assign({}, nyp), { onGround: this.bot.entity.onGround }));
107
+ this.bot._client.write("look", Object.assign(Object.assign({}, nyp), { onGround: onGround !== null && onGround !== void 0 ? onGround : this.bot.entity.onGround }));
108
108
  if (update) {
109
109
  this.bot.entity.yaw = yaw;
110
110
  this.bot.entity.pitch = pitch;
@@ -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 ? 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,2 @@
1
+ export * from "./aabbUtil";
2
+ export * from "./mathUtil";
@@ -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.10",
3
+ "version": "1.3.14",
4
4
  "description": "mineflayer utils for NextGEN mineflayer plugins.",
5
5
  "keywords": [
6
6
  "mineflayer",