@nxg-org/mineflayer-util-plugin 1.8.0 → 1.8.2

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,3 @@
1
+ {
2
+ "print.colourScheme": "GitHub"
3
+ }
@@ -14,7 +14,7 @@ import { RayTraceFunctions } from "./rayTracingFunctions";
14
14
  *
15
15
  */
16
16
  export declare class UtilFunctions {
17
- bot: Bot;
17
+ private bot;
18
18
  inv: InventoryFunctions;
19
19
  move: MovementFunctions;
20
20
  entity: EntityFunctions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxg-org/mineflayer-util-plugin",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "description": "mineflayer utils for NextGEN mineflayer plugins.",
5
5
  "keywords": [
6
6
  "mineflayer",
@@ -22,7 +22,7 @@
22
22
  "dependencies": {},
23
23
  "devDependencies": {
24
24
  "@types/node": "^17.0.4",
25
- "mineflayer": "^4.8.1",
25
+ "mineflayer": "^4.17.0",
26
26
  "typescript": "^4.5.2",
27
27
  "vec3": "^0.1.7"
28
28
  }
@@ -1,10 +0,0 @@
1
- import type { Bot } from "mineflayer";
2
- import type { Block } from "prismarine-block";
3
- import { AABB } from "./calcs/aabb";
4
- import type { Vec3 } from "vec3";
5
- export declare class WorldFunctions {
6
- private bot;
7
- constructor(bot: Bot);
8
- getBlockAABB(block: Block, height?: number): AABB;
9
- getBlockPosAABB(block: Vec3, height?: number): AABB;
10
- }
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WorldFunctions = void 0;
4
- const aabb_1 = require("./calcs/aabb");
5
- class WorldFunctions {
6
- constructor(bot) {
7
- this.bot = bot;
8
- }
9
- getBlockAABB(block, height = 1) {
10
- const { x, y, z } = block.position;
11
- return new aabb_1.AABB(x, y, z, x + 1, y + height, z + 1);
12
- }
13
- getBlockPosAABB(block, height = 1) {
14
- const { x, y, z } = block.floored();
15
- return new aabb_1.AABB(x, y, z, x + 1, y + height, z + 1);
16
- }
17
- }
18
- exports.WorldFunctions = WorldFunctions;
@@ -1,10 +0,0 @@
1
- import type { Bot, EquipmentDestination } from "mineflayer";
2
- import type { Item } from "prismarine-item";
3
- export declare class CustomInventoryFunctions {
4
- private bot;
5
- armorSlots: any;
6
- constructor(bot: Bot);
7
- equip(item: Item, destination: EquipmentDestination): Promise<void>;
8
- setQuickBarSlot(slot: number): void;
9
- getDestSlot(destination: EquipmentDestination): any;
10
- }
@@ -1,95 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.CustomInventoryFunctions = void 0;
16
- const assert_1 = __importDefault(require("assert"));
17
- const util_1 = require("util");
18
- const sleep = (0, util_1.promisify)(setTimeout);
19
- const QUICK_BAR_COUNT = 9;
20
- const QUICK_BAR_START = 36;
21
- let nextQuickBarSlot = 0;
22
- //lazy. will fix this later.
23
- class CustomInventoryFunctions {
24
- constructor(bot) {
25
- this.bot = bot;
26
- this.armorSlots = {
27
- head: 5,
28
- torso: 6,
29
- legs: 7,
30
- feet: 8,
31
- };
32
- if (!bot.supportFeature("doesntHaveOffHandSlot")) {
33
- this.armorSlots["off-hand"] = 45;
34
- }
35
- }
36
- equip(item, destination) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- if (item == null || typeof item !== "object") {
39
- throw new Error("Invalid item object in equip (item is null or typeof item is not object)");
40
- }
41
- if (!destination || destination === null) {
42
- destination = "hand";
43
- }
44
- const sourceSlot = item.slot;
45
- let destSlot = this.getDestSlot(destination);
46
- if (sourceSlot === destSlot) {
47
- // don't need to do anything
48
- return;
49
- }
50
- if (destination !== "hand") {
51
- yield this.bot.moveSlotItem(sourceSlot, destSlot);
52
- return;
53
- }
54
- if (destSlot >= QUICK_BAR_START &&
55
- destSlot < QUICK_BAR_START + QUICK_BAR_COUNT &&
56
- sourceSlot >= QUICK_BAR_START &&
57
- sourceSlot < QUICK_BAR_START + QUICK_BAR_COUNT) {
58
- // all we have to do is change the quick bar selection
59
- this.bot.setQuickBarSlot(sourceSlot - QUICK_BAR_START);
60
- return;
61
- }
62
- // find an empty slot on the quick bar to put the source item in
63
- destSlot = this.bot.inventory.firstEmptySlotRange(QUICK_BAR_START, QUICK_BAR_START + QUICK_BAR_COUNT);
64
- if (destSlot == null) {
65
- // LRU cache for the quick bar items
66
- destSlot = QUICK_BAR_START + nextQuickBarSlot;
67
- nextQuickBarSlot = (nextQuickBarSlot + 1) % QUICK_BAR_COUNT;
68
- }
69
- this.setQuickBarSlot(destSlot - QUICK_BAR_START);
70
- yield this.bot.moveSlotItem(sourceSlot, destSlot);
71
- });
72
- }
73
- setQuickBarSlot(slot) {
74
- assert_1.default.ok(slot >= 0);
75
- assert_1.default.ok(slot < 9);
76
- if (this.bot.quickBarSlot === slot)
77
- return;
78
- this.bot.quickBarSlot = slot;
79
- this.bot._client.write("held_item_slot", {
80
- slotId: slot,
81
- });
82
- this.bot.updateHeldItem();
83
- }
84
- getDestSlot(destination) {
85
- if (destination === "hand") {
86
- return QUICK_BAR_START + this.bot.quickBarSlot;
87
- }
88
- else {
89
- const destSlot = this.armorSlots[destination];
90
- assert_1.default.ok(destSlot != null, `invalid destination: ${destination}`);
91
- return destSlot;
92
- }
93
- }
94
- }
95
- exports.CustomInventoryFunctions = CustomInventoryFunctions;
package/lib/mathUtil.d.ts DELETED
@@ -1,23 +0,0 @@
1
- import { Bot } from "mineflayer";
2
- import { Vec3 } from "vec3";
3
- export declare class MathFunctions {
4
- constructor();
5
- toNotchianYaw: (yaw: number) => number;
6
- toNotchianPitch: (pitch: number) => number;
7
- fromNotchianYawByte: (yaw: number) => number;
8
- fromNotchianPitchByte: (pitch: number) => number;
9
- euclideanMod(numerator: number, denominator: number): number;
10
- toRadians(degrees: number): number;
11
- toDegrees(radians: number): number;
12
- fromNotchianYaw(yaw: number): number;
13
- fromNotchianPitch(pitch: number): number;
14
- fromNotchVelocity(vel: Vec3): Vec3;
15
- pointToYawAndPitch(bot: Bot, point: Vec3): {
16
- yaw: number;
17
- pitch: number;
18
- };
19
- dirToYawAndPitch(dir: Vec3): {
20
- yaw: number;
21
- pitch: number;
22
- };
23
- }
package/lib/mathUtil.js DELETED
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MathFunctions = 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
- class MathFunctions {
13
- constructor() {
14
- this.toNotchianYaw = (yaw) => this.toDegrees(PI - yaw);
15
- this.toNotchianPitch = (pitch) => this.toDegrees(-pitch);
16
- this.fromNotchianYawByte = (yaw) => this.fromNotchianYaw(yaw * FROM_NOTCH_BYTE);
17
- this.fromNotchianPitchByte = (pitch) => this.fromNotchianPitch(pitch * FROM_NOTCH_BYTE);
18
- }
19
- euclideanMod(numerator, denominator) {
20
- const result = numerator % denominator;
21
- return result < 0 ? result + denominator : result;
22
- }
23
- toRadians(degrees) {
24
- return TO_RAD * degrees;
25
- }
26
- toDegrees(radians) {
27
- return TO_DEG * radians;
28
- }
29
- fromNotchianYaw(yaw) {
30
- return this.euclideanMod(PI - this.toRadians(yaw), PI_2);
31
- }
32
- fromNotchianPitch(pitch) {
33
- return this.euclideanMod(this.toRadians(-pitch) + PI, PI_2) - PI;
34
- }
35
- fromNotchVelocity(vel) {
36
- return new vec3_1.Vec3(vel.x * FROM_NOTCH_VEL, vel.y * FROM_NOTCH_VEL, vel.z * FROM_NOTCH_VEL);
37
- }
38
- pointToYawAndPitch(bot, point) {
39
- const delta = point.minus(bot.entity.position.offset(0, bot.entity.height, 0));
40
- return this.dirToYawAndPitch(delta);
41
- }
42
- dirToYawAndPitch(dir) {
43
- const yaw = Math.atan2(-dir.x, -dir.z);
44
- const groundDistance = Math.sqrt(dir.x * dir.x + dir.z * dir.z);
45
- const pitch = Math.atan2(dir.y, groundDistance);
46
- return { yaw: yaw, pitch: pitch };
47
- }
48
- }
49
- exports.MathFunctions = MathFunctions;
File without changes
@@ -1 +0,0 @@
1
- "use strict";