@nxg-org/mineflayer-util-plugin 1.3.7 → 1.3.11

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.
@@ -1,25 +1,20 @@
1
1
  import { Bot } from "mineflayer";
2
2
  import { Block } from "prismarine-block";
3
3
  import { Vec3 } from "vec3";
4
+ declare type Iteration = {
5
+ x: number;
6
+ y: number;
7
+ z: number;
8
+ face: number;
9
+ };
10
+ declare type BlockAndIterations = {
11
+ block: Block | null;
12
+ iterations: Iteration[];
13
+ };
4
14
  export declare class InterceptFunctions {
5
- bot: Bot;
15
+ private bot;
6
16
  constructor(bot: Bot);
7
- check(from: Vec3, to: Vec3): {
8
- block: Block | null;
9
- iterations: {
10
- x: number;
11
- y: number;
12
- z: number;
13
- face: number;
14
- }[];
15
- };
16
- raycast(from: Vec3, direction: Vec3, range: number): {
17
- block: Block | null;
18
- iterations: {
19
- x: number;
20
- y: number;
21
- z: number;
22
- face: number;
23
- }[];
24
- };
17
+ check(from: Vec3, to: Vec3): BlockAndIterations;
18
+ raycast(from: Vec3, direction: Vec3, range: number): BlockAndIterations;
25
19
  }
20
+ export {};
package/lib/index.js CHANGED
@@ -2,7 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InterceptFunctions = exports.AABB = void 0;
4
4
  const utilFunctions_1 = require("./utilFunctions");
5
+ const mineflayer_pathfinder_1 = require("mineflayer-pathfinder");
5
6
  function inject(bot) {
7
+ if (!bot.pathfinder)
8
+ bot.loadPlugin(mineflayer_pathfinder_1.pathfinder);
6
9
  bot.util = new utilFunctions_1.UtilFunctions(bot);
7
10
  }
8
11
  exports.default = inject;
@@ -90,18 +90,17 @@ class InventoryFunctions {
90
90
  }
91
91
  findItemByID(itemId, metadata) {
92
92
  var _a, _b;
93
- const potentialMatches = this.getAllItems().filter((item) => item.type === itemId);
94
93
  if (metadata)
95
- return (_a = potentialMatches.find((item) => item.metadata === metadata)) !== null && _a !== void 0 ? _a : null;
96
- return (_b = potentialMatches[0]) !== null && _b !== void 0 ? _b : null;
94
+ return (_a = this.getAllItems().find((item) => item.type === itemId && item.metadata === metadata)) !== null && _a !== void 0 ? _a : null;
95
+ else
96
+ return (_b = this.getAllItems().find((item) => item.type === itemId)) !== null && _b !== void 0 ? _b : null;
97
97
  }
98
98
  findItem(name, metadata) {
99
99
  var _a, _b;
100
- //[...this.getAllItems(), this.bot.inventory.selectedItem!]
101
- const potentialMatches = this.getAllItems().filter((item) => item === null || item === void 0 ? void 0 : item.name.includes(name));
102
100
  if (metadata)
103
- return (_a = potentialMatches.find((item) => item.metadata === metadata)) !== null && _a !== void 0 ? _a : null;
104
- return (_b = potentialMatches[0]) !== null && _b !== void 0 ? _b : null;
101
+ return (_a = this.getAllItems().find((item) => item.name === name && item.metadata === metadata)) !== null && _a !== void 0 ? _a : null;
102
+ else
103
+ return (_b = this.getAllItems().find((item) => item.name === name)) !== null && _b !== void 0 ? _b : null;
105
104
  }
106
105
  //alias.
107
106
  has(name, metadata) {
@@ -1,13 +1,13 @@
1
1
  import type { Bot } from "mineflayer";
2
2
  import type { Entity } from "prismarine-entity";
3
3
  import type { Vec3 } from "vec3";
4
- import { goals } from "mineflayer-pathfinder";
4
+ import { goals, Movements } from "mineflayer-pathfinder";
5
5
  export declare class MovementFunctions {
6
- bot: Bot;
6
+ private bot;
7
7
  goalArray: goals.GoalCompositeAll;
8
- lastYaw: number;
9
- lastPitch: number;
10
8
  constructor(bot: Bot);
9
+ set movements(movements: Movements);
10
+ get movements(): Movements;
11
11
  /**
12
12
  * Fuckin' mineflayer-pathfinder still doesn't have typings.
13
13
  * Pain in my goddamn ass.
@@ -38,6 +38,6 @@ export declare class MovementFunctions {
38
38
  */
39
39
  followEntityWithRespectRange(entity: Entity, followDistance: number, invertDistance?: number): boolean;
40
40
  forceLook(yaw: number, pitch: number, update?: boolean): void;
41
- forceLookAt(pos: Vec3, update?: boolean, trueForce?: boolean): void;
41
+ forceLookAt(pos: Vec3, update?: boolean): void;
42
42
  lazyTeleport(endPos: Vec3): void;
43
43
  }
@@ -1,14 +1,23 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.MovementFunctions = void 0;
4
7
  const mineflayer_pathfinder_1 = require("mineflayer-pathfinder");
8
+ const minecraft_data_1 = __importDefault(require("minecraft-data"));
5
9
  const { GoalCompositeAll, GoalInvert, GoalFollow } = mineflayer_pathfinder_1.goals;
6
10
  class MovementFunctions {
7
11
  constructor(bot) {
8
12
  this.bot = bot;
9
13
  this.goalArray = new GoalCompositeAll();
10
- this.lastYaw = 0;
11
- this.lastPitch = 0;
14
+ this.movements = new mineflayer_pathfinder_1.Movements(bot, (0, minecraft_data_1.default)(bot.version));
15
+ }
16
+ set movements(movements) {
17
+ this.bot.pathfinder.setMovements(movements);
18
+ }
19
+ get movements() {
20
+ return this.movements;
12
21
  }
13
22
  /**
14
23
  * Fuckin' mineflayer-pathfinder still doesn't have typings.
@@ -85,23 +94,21 @@ class MovementFunctions {
85
94
  }
86
95
  forceLook(yaw, pitch, update = false) {
87
96
  const notchianYawAndPitch = { yaw: this.bot.util.math.toNotchianYaw(yaw), pitch: this.bot.util.math.toNotchianPitch(pitch) };
88
- this.bot._client.write("look", Object.assign(Object.assign({}, notchianYawAndPitch), { onGround: false }));
97
+ this.bot._client.write("look", notchianYawAndPitch);
89
98
  if (update) {
90
- // this.bot.entity.yaw = yaw;
91
- // this.bot.entity.pitch = pitch
92
- this.bot.look(yaw, pitch, true);
99
+ this.bot.entity.yaw = yaw;
100
+ this.bot.entity.pitch = pitch;
101
+ // this.bot.look(yaw, pitch, true);
93
102
  }
94
103
  }
95
- forceLookAt(pos, update = false, trueForce = false) {
104
+ forceLookAt(pos, update = false) {
96
105
  const { yaw, pitch } = this.bot.util.math.pointToYawAndPitch(this.bot, pos);
97
106
  const nyp = { yaw: this.bot.util.math.toNotchianYaw(yaw), pitch: this.bot.util.math.toNotchianPitch(pitch) };
98
- if (nyp.yaw !== this.lastYaw || nyp.pitch !== this.lastPitch || trueForce) {
99
- this.bot._client.write("look", Object.assign(Object.assign({}, nyp), { onGround: false }));
100
- if (update) {
101
- // this.bot.entity.yaw = yaw;
102
- // this.bot.entity.pitch = pitch
103
- this.bot.lookAt(pos, true);
104
- }
107
+ this.bot._client.write("look", nyp);
108
+ if (update) {
109
+ this.bot.entity.yaw = yaw;
110
+ this.bot.entity.pitch = pitch;
111
+ // this.bot.look(yaw, pitch, true);
105
112
  }
106
113
  }
107
114
  lazyTeleport(endPos) { }
@@ -91,15 +91,21 @@ const AIR_BLOCK = { type: 0 };
91
91
  class PredictiveFunctions {
92
92
  constructor(bot) {
93
93
  this.bot = bot;
94
- this.damageMultiplier = 7; // for 1.12+ 8 for 1.8 TODO check when the change occur (likely 1.9)
95
94
  this.resistanceIndex = "11";
96
- if (require('minecraft-data')(bot.version).isNewerOrEqualTo("1.16")) {
95
+ const version = Number(bot.version.split(".")[1]);
96
+ if (version === 16) {
97
97
  this.armorToughnessKey = "generic.armorToughness";
98
98
  this.armorProtectionKey = "generic.armor";
99
99
  }
100
100
  else {
101
- this.armorToughnessKey = "generic.armorToughness";
102
- this.armorProtectionKey = "generic.armor";
101
+ this.armorToughnessKey = "minecraft:generic.armor_toughness";
102
+ this.armorProtectionKey = "minecraft:generic.armor";
103
+ }
104
+ if (version > 9) {
105
+ this.damageMultiplier = 8;
106
+ }
107
+ else {
108
+ this.damageMultiplier = 7;
103
109
  }
104
110
  const effects = (0, minecraft_data_1.default)(bot.version).effects;
105
111
  for (const effectId in effects) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxg-org/mineflayer-util-plugin",
3
- "version": "1.3.7",
3
+ "version": "1.3.11",
4
4
  "description": "mineflayer utils for NextGEN mineflayer plugins.",
5
5
  "keywords": [
6
6
  "mineflayer",
@@ -28,7 +28,7 @@
28
28
  "vec3": "^0.1.7"
29
29
  },
30
30
  "devDependencies": {
31
- "@types/node": "^16.11.11",
31
+ "@types/node": "^17.0.4",
32
32
  "typescript": "^4.5.2"
33
33
  }
34
34
  }