@nxg-org/mineflayer-util-plugin 1.2.6 → 1.3.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.
@@ -0,0 +1,15 @@
1
+ import { Bot } from "mineflayer";
2
+ import { Vec3 } from "vec3";
3
+ import type { Entity } from "prismarine-entity";
4
+ export declare class RayTraceFunctions {
5
+ private bot;
6
+ constructor(bot: Bot);
7
+ blockAtEntityCursor({ position, height, yaw, pitch }: {
8
+ position: Vec3;
9
+ height: number;
10
+ yaw: number;
11
+ pitch: number;
12
+ }, maxDistance?: number, matcher?: null): any;
13
+ entityAtCursor(maxDistance?: number): Entity | null;
14
+ entityAtEntityCursor(entity: Entity, maxDistance?: number): Entity | null;
15
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RayTraceFunctions = void 0;
4
+ const vec3_1 = require("vec3");
5
+ const iterators_1 = require("./calcs/iterators");
6
+ function getViewDirection(pitch, yaw) {
7
+ const csPitch = Math.cos(pitch);
8
+ const snPitch = Math.sin(pitch);
9
+ const csYaw = Math.cos(yaw);
10
+ const snYaw = Math.sin(yaw);
11
+ return new vec3_1.Vec3(-snYaw * csPitch, snPitch, -csYaw * csPitch);
12
+ }
13
+ class RayTraceFunctions {
14
+ constructor(bot) {
15
+ this.bot = bot;
16
+ }
17
+ blockAtEntityCursor({ position, height, yaw, pitch }, maxDistance = 256, matcher = null) {
18
+ const eyePosition = position.offset(0, height, 0);
19
+ const viewDirection = getViewDirection(pitch, yaw);
20
+ return this.bot.world.raycast(eyePosition, viewDirection, maxDistance, matcher);
21
+ }
22
+ entityAtCursor(maxDistance = 3.5) {
23
+ return this.entityAtEntityCursor(this.bot.entity, maxDistance);
24
+ }
25
+ entityAtEntityCursor(entity, maxDistance = 3.5) {
26
+ var _a;
27
+ const block = this.blockAtEntityCursor(entity, maxDistance);
28
+ maxDistance = (_a = block === null || block === void 0 ? void 0 : block.intersect.distanceTo(this.bot.entity.position)) !== null && _a !== void 0 ? _a : maxDistance;
29
+ const entities = Object.values(this.bot.entities).filter((e) => e.type !== "object" && e.username !== entity.username && e.position.distanceTo(entity.position) <= maxDistance);
30
+ const dir = new vec3_1.Vec3(-Math.sin(entity.yaw) * Math.cos(entity.pitch), Math.sin(entity.pitch), -Math.cos(entity.yaw) * Math.cos(entity.pitch));
31
+ const iterator = new iterators_1.RaycastIterator(entity.position.offset(0, entity.height, 0), dir.normalize(), maxDistance);
32
+ let targetEntity = null;
33
+ let targetDist = maxDistance;
34
+ for (let i = 0; i < entities.length; i++) {
35
+ const e = entities[i];
36
+ const w = e.height === 1.62 ? 0.3 : e.height / 2;
37
+ const shapes = [[-w, 0, -w, w, e.height + (e.height === 1.62 ? 0.18 : 0), w]];
38
+ const intersect = iterator.intersect(shapes, e.position);
39
+ if (intersect) {
40
+ const entityDir = e.position.minus(entity.position); // Can be combined into 1 line
41
+ const sign = Math.sign(entityDir.dot(dir));
42
+ if (sign !== -1) {
43
+ const dist = entity.position.distanceTo(intersect.pos);
44
+ if (dist < targetDist) {
45
+ targetEntity = e;
46
+ targetDist = dist;
47
+ }
48
+ }
49
+ }
50
+ }
51
+ return targetEntity;
52
+ }
53
+ }
54
+ exports.RayTraceFunctions = RayTraceFunctions;
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -7,6 +7,7 @@ import { MovementFunctions } from "./movementFunctions";
7
7
  import { PredictiveFunctions } from "./predictiveFunctions";
8
8
  import { MathFunctions } from "./mathUtil";
9
9
  import { WorldFunctions } from "./WorldFunctions";
10
+ import { RayTraceFunctions } from "./rayTracingFunctions";
10
11
  export declare type BuiltInPriorityOptions = {
11
12
  group: PrioGroups;
12
13
  priority: number;
@@ -28,6 +29,7 @@ export declare class UtilFunctions {
28
29
  filters: FilterFunctions;
29
30
  math: MathFunctions;
30
31
  world: WorldFunctions;
32
+ raytrace: RayTraceFunctions;
31
33
  private builtInsPriorityStore;
32
34
  private customPriorityStore;
33
35
  private builtInCurrentExecuting;
@@ -18,6 +18,7 @@ const util_1 = require("util");
18
18
  const predictiveFunctions_1 = require("./predictiveFunctions");
19
19
  const mathUtil_1 = require("./mathUtil");
20
20
  const WorldFunctions_1 = require("./WorldFunctions");
21
+ const rayTracingFunctions_1 = require("./rayTracingFunctions");
21
22
  class UtilFunctions {
22
23
  constructor(bot) {
23
24
  this.bot = bot;
@@ -28,6 +29,7 @@ class UtilFunctions {
28
29
  this.predict = new predictiveFunctions_1.PredictiveFunctions(bot);
29
30
  this.filters = new filterFunctions_1.FilterFunctions(bot);
30
31
  this.world = new WorldFunctions_1.WorldFunctions(bot);
32
+ this.raytrace = new rayTracingFunctions_1.RayTraceFunctions(bot);
31
33
  this.math = new mathUtil_1.MathFunctions();
32
34
  this.builtInsPriorityStore = {};
33
35
  this.customPriorityStore = {};
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PredictiveWorld = void 0;
4
4
  const vec3_1 = require("vec3");
5
- const raycastIterator_1 = require("./raycastIterator");
5
+ const iterators_1 = require("../calcs/iterators");
6
6
  /**
7
7
  * A class dedicated to predictive logic.
8
8
  *
@@ -14,7 +14,7 @@ class PredictiveWorld {
14
14
  this.blocks = {};
15
15
  }
16
16
  raycast(from, direction, range, matcher = null) {
17
- const iter = new raycastIterator_1.RaycastIterator(from, direction, range);
17
+ const iter = new iterators_1.RaycastIterator(from, direction, range);
18
18
  let pos = iter.next();
19
19
  while (pos) {
20
20
  const position = new vec3_1.Vec3(pos.x, pos.y, pos.z);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxg-org/mineflayer-util-plugin",
3
- "version": "1.2.6",
3
+ "version": "1.3.0",
4
4
  "description": "mineflayer utils for NextGEN mineflayer plugins.",
5
5
  "keywords": [
6
6
  "mineflayer",
@@ -23,6 +23,7 @@
23
23
  "mineflayer": "^3.11.2",
24
24
  "mineflayer-pathfinder": "^1.8.0",
25
25
  "prismarine-block": "^1.10.3",
26
+ "prismarine-entity": "^1.2.0",
26
27
  "prismarine-item": "^1.11.1",
27
28
  "vec3": "^0.1.7"
28
29
  },