@nxg-org/mineflayer-util-plugin 1.6.0 → 1.6.1

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,10 @@
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
+ }
@@ -0,0 +1,95 @@
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;
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxg-org/mineflayer-util-plugin",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "mineflayer utils for NextGEN mineflayer plugins.",
5
5
  "keywords": [
6
6
  "mineflayer",
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/node": "^17.0.4",
24
- "mineflayer": "^4.4.0",
24
+ "mineflayer": "^4.6.0",
25
25
  "typescript": "^4.5.2",
26
26
  "vec3": "^0.1.7"
27
27
  }
@@ -1,61 +0,0 @@
1
- import { createBot, EquipmentDestination } from "mineflayer";
2
- import shit from "../src/index";
3
- import { Vec3 } from "vec3";
4
- import type { Entity } from "prismarine-entity";
5
-
6
- let target: Entity | null;
7
-
8
- const bot = createBot({
9
- username: "utilTesting",
10
- host: process.argv[2] ?? "localhost",
11
- port: Number(process.argv[3]) ?? 25565,
12
- });
13
-
14
- bot.loadPlugin(shit);
15
-
16
- const emptyVec = new Vec3(0, 0, 0);
17
-
18
- bot.on("chat", async (username, message) => {
19
- const split = message.split(" ");
20
- switch (split[0]) {
21
- case "look":
22
- target = bot.nearestEntity((e) => (e.username ?? e.name) === split[1]);
23
- if (!target) return console.log("no entity");
24
- bot.util.move.forceLookAt(target.position, true);
25
- break;
26
- case "equip":
27
- const item = bot.util.inv.getAllItems().find((i) => i.name.includes(split[1]));
28
- if (!item) return console.log("no item");
29
- if (["hand", "off-hand"].includes(split[2])) {
30
- bot.util.inv.customEquip(item, split[2] as EquipmentDestination);
31
- }
32
-
33
- break;
34
- case "health":
35
- const health = bot.util.entity.getHealth();
36
- bot.chat(`${health}`);
37
- break;
38
-
39
- case "whatAmILookingAt":
40
- target = bot.nearestEntity((e) => (e.username ?? e.name) === username);
41
- if (!target) return console.log("no entity");
42
- const player = bot.util.raytrace.entityAtEntityCursor(target, 256);
43
- if (player) {
44
- console.log(player);
45
- bot.chat(`${player.username ?? player.name} at ${player.position}`);
46
- } else {
47
- const block = bot.util.raytrace.blockAtEntityCursor(target, 256); //includes face and intersect. That's very nice.
48
- if (block) {
49
- console.log(block);
50
- bot.chat(`${block.name} at ${block.position}`);
51
- } else {
52
- bot.chat("You're not looking at anything.");
53
- }
54
- }
55
- break;
56
- default:
57
- console.log(username, bot.entity.username);
58
- if (username !== bot.entity.username) bot.chat("unknown command: " + message);
59
- break;
60
- }
61
- });