@nxg-org/mineflayer-util-plugin 1.0.1 → 1.0.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.
Files changed (38) hide show
  1. package/lib/WorldFunctions.d.ts +10 -0
  2. package/lib/WorldFunctions.js +18 -0
  3. package/lib/calcs/aabb.d.ts +36 -0
  4. package/{src/calcs/aabb.ts → lib/calcs/aabb.js} +52 -76
  5. package/lib/commonSense.d.ts +22 -0
  6. package/lib/commonSense.js +220 -0
  7. package/lib/customImplementations/inventory.d.ts +10 -0
  8. package/lib/customImplementations/inventory.js +95 -0
  9. package/lib/entityFunctions.d.ts +36 -0
  10. package/lib/entityFunctions.js +78 -0
  11. package/lib/filterFunctions.d.ts +23 -0
  12. package/lib/filterFunctions.js +45 -0
  13. package/{src/index.ts → lib/index.d.ts} +7 -10
  14. package/lib/inventoryFunctions.d.ts +45 -0
  15. package/lib/inventoryFunctions.js +208 -0
  16. package/lib/mathUtil.d.ts +23 -0
  17. package/{src/mathUtil.ts → lib/mathUtil.js} +21 -28
  18. package/lib/movementFunctions.d.ts +43 -0
  19. package/{src/movementFunctions.ts → lib/movementFunctions.js} +36 -43
  20. package/lib/predictiveFunctions.d.ts +25 -0
  21. package/{src/predictiveFunctions.ts → lib/predictiveFunctions.js} +62 -77
  22. package/lib/utilFunctions.d.ts +50 -0
  23. package/lib/utilFunctions.js +140 -0
  24. package/lib/worldRelated/predictiveWorld.d.ts +41 -0
  25. package/{src/worldRelated/predictiveWorld.ts → lib/worldRelated/predictiveWorld.js} +39 -40
  26. package/lib/worldRelated/raycastIterator.d.ts +45 -0
  27. package/{src/worldRelated/raycastIterator.ts → lib/worldRelated/raycastIterator.js} +37 -59
  28. package/package.json +2 -1
  29. package/.github/workflows/ci.yml +0 -22
  30. package/.github/workflows/release.yml +0 -37
  31. package/src/WorldFunctions.ts +0 -19
  32. package/src/commonSense.ts +0 -189
  33. package/src/customImplementations/inventory.ts +0 -90
  34. package/src/entityFunctions.ts +0 -71
  35. package/src/filterFunctions.ts +0 -54
  36. package/src/inventoryFunctions.ts +0 -187
  37. package/src/utilFunctions.ts +0 -152
  38. package/tsconfig.json +0 -17
@@ -0,0 +1,36 @@
1
+ import type { Bot } from "mineflayer";
2
+ import type { Entity } from "prismarine-entity";
3
+ import type { Vec3 } from "vec3";
4
+ import { AABB } from "./calcs/aabb";
5
+ export declare class EntityFunctions {
6
+ bot: Bot;
7
+ healthSlot: number;
8
+ constructor(bot: Bot);
9
+ /**
10
+ * TODO: Version specific right now. Generalize. Unknown method.
11
+ *
12
+ * Checks if main hand is activated.
13
+ * @returns boolean
14
+ */
15
+ isMainHandActive(entity?: Entity): boolean;
16
+ /**
17
+ * TODO: Version specific right now. Generalize. Unknown method.
18
+ *
19
+ * Checks if offhand is activated.
20
+ * @returns boolean
21
+ */
22
+ isOffHandActive(entity?: Entity): boolean;
23
+ /**
24
+ * TODO: Version specific right now. Generalize. Unknown method.
25
+ * @param metadata metadata from Prismarine-Entity Entity.
26
+ * @returns
27
+ */
28
+ getHealth(entity?: Entity): number;
29
+ getDistanceToEntity(entity: Entity): number;
30
+ getDistanceBetweenEntities(first: Entity, second: Entity): number;
31
+ getEntityAABB(entity: {
32
+ position: Vec3;
33
+ height: number;
34
+ width?: number;
35
+ }): AABB;
36
+ }
@@ -0,0 +1,78 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.EntityFunctions = void 0;
13
+ const aabb_1 = require("./calcs/aabb");
14
+ class EntityFunctions {
15
+ constructor(bot) {
16
+ this.bot = bot;
17
+ this.healthSlot = 7;
18
+ this.bot.on("spawn", () => __awaiter(this, void 0, void 0, function* () {
19
+ // await this.bot.util.sleep(1000)
20
+ // const slot = this.bot.entity.metadata.slice(5).findIndex((data) => Number(data) === 20);
21
+ // if (slot > 0) {
22
+ // this.healthSlot = slot + 5;
23
+ // }
24
+ this.healthSlot = Number(this.bot.version.split(".")[1]) <= 16 ? 7 : 9;
25
+ }));
26
+ }
27
+ /**
28
+ * TODO: Version specific right now. Generalize. Unknown method.
29
+ *
30
+ * Checks if main hand is activated.
31
+ * @returns boolean
32
+ */
33
+ isMainHandActive(entity) {
34
+ return (entity !== null && entity !== void 0 ? entity : this.bot.entity).metadata[6] === 1; //as any & (1 | 0)) === (1 | 0);
35
+ }
36
+ /**
37
+ * TODO: Version specific right now. Generalize. Unknown method.
38
+ *
39
+ * Checks if offhand is activated.
40
+ * @returns boolean
41
+ */
42
+ isOffHandActive(entity) {
43
+ return (entity !== null && entity !== void 0 ? entity : this.bot.entity).metadata[6] === 1; //& (1 | 2)) === (1 | 2);
44
+ }
45
+ /**
46
+ * TODO: Version specific right now. Generalize. Unknown method.
47
+ * @param metadata metadata from Prismarine-Entity Entity.
48
+ * @returns
49
+ */
50
+ getHealth(entity) {
51
+ var _a, _b;
52
+ entity = entity !== null && entity !== void 0 ? entity : this.bot.entity;
53
+ let metadata = entity.metadata;
54
+ //console.log(entity.metadata, this.healthSlot, this.bot.entity.health)
55
+ let healthSlot = this.healthSlot; //metadata[this.healthSlot] ? this.healthSlot : metadata.findIndex((met) => Number(met) > 1 && Number(met) <= 20);
56
+ // return Number(metadata[healthSlot]) + (Number(metadata[healthSlot + 4]) ?? 0);
57
+ let health = Number(metadata[healthSlot]);
58
+ if (!health || health === 0)
59
+ health = entity === this.bot.entity ? (_a = this.bot.entity.health) !== null && _a !== void 0 ? _a : 0 : 0;
60
+ if (health === 0)
61
+ console.log(this.healthSlot, entity.metadata);
62
+ // console.log(health + (Number(metadata[this.healthSlot + 4]) ?? 0))
63
+ return health + ((_b = Number(metadata[this.healthSlot + 4])) !== null && _b !== void 0 ? _b : 0);
64
+ }
65
+ getDistanceToEntity(entity) {
66
+ return this.getDistanceBetweenEntities(this.bot.entity, entity);
67
+ }
68
+ getDistanceBetweenEntities(first, second) {
69
+ return first.position.distanceTo(second.position);
70
+ }
71
+ getEntityAABB(entity) {
72
+ var _a;
73
+ const w = (_a = entity.width) !== null && _a !== void 0 ? _a : entity.height / 2;
74
+ const { x, y, z } = entity.position;
75
+ return new aabb_1.AABB(-w, 0, -w, w, entity.height, w).offset(x, y, z);
76
+ }
77
+ }
78
+ exports.EntityFunctions = EntityFunctions;
@@ -0,0 +1,23 @@
1
+ import type { Entity } from "prismarine-entity";
2
+ import type { Bot } from "mineflayer";
3
+ import type { Vec3 } from "vec3";
4
+ /**
5
+ * TODO: Inherit other bot names. May need to communciate to a server for this one. Or perhaps reference this once?
6
+ */
7
+ export declare class FilterFunctions {
8
+ private bot;
9
+ specificNames: string[];
10
+ botNames: string[];
11
+ constructor(bot: Bot);
12
+ addBotName(name: string): void;
13
+ getNearestEntity(func: (entity: Entity, ...args: any[]) => boolean, ...args: any[]): Entity | null;
14
+ static getNearestEntity(bot: Bot, func: (entity: Entity, ...args: any[]) => boolean, ...args: any[]): Entity | null;
15
+ allButOtherBotsFilter(): Entity | null;
16
+ static allButOtherBotsFilter(bot: Bot, ...names: string[]): Entity | null;
17
+ specificNamesFilter(): Entity | null;
18
+ static specificNamesFilter(bot: Bot, ...names: string[]): Entity | null;
19
+ nearestCrystalFilter(): Entity | null;
20
+ static nearestCrystalFilter(bot: Bot): Entity | null;
21
+ entityAtPosition(position: Vec3): Entity | null;
22
+ static entityAtPosition(bot: Bot, position: Vec3): void;
23
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FilterFunctions = void 0;
4
+ /**
5
+ * TODO: Inherit other bot names. May need to communciate to a server for this one. Or perhaps reference this once?
6
+ */
7
+ class FilterFunctions {
8
+ constructor(bot) {
9
+ this.bot = bot;
10
+ this.specificNames = [];
11
+ this.botNames = [];
12
+ }
13
+ addBotName(name) {
14
+ this.botNames.push(name);
15
+ }
16
+ getNearestEntity(func, ...args) {
17
+ return this.bot.nearestEntity((entity) => func(entity, ...args));
18
+ }
19
+ static getNearestEntity(bot, func, ...args) {
20
+ return bot.nearestEntity((entity) => func(entity, ...args));
21
+ }
22
+ allButOtherBotsFilter() {
23
+ return this.getNearestEntity((e) => { var _a, _b, _c; return e.type === "player" && ((_c = !((_a = this.botNames) === null || _a === void 0 ? void 0 : _a.includes((_b = e.username) !== null && _b !== void 0 ? _b : ""))) !== null && _c !== void 0 ? _c : true); });
24
+ }
25
+ static allButOtherBotsFilter(bot, ...names) {
26
+ return FilterFunctions.getNearestEntity(bot, (e) => { var _a; return e.type === "player" && !names.includes((_a = e.username) !== null && _a !== void 0 ? _a : ""); });
27
+ }
28
+ specificNamesFilter() {
29
+ return this.getNearestEntity((e) => { var _a, _b, _c; return e.type === "player" && ((_c = (_a = this.specificNames) === null || _a === void 0 ? void 0 : _a.includes((_b = e.username) !== null && _b !== void 0 ? _b : "")) !== null && _c !== void 0 ? _c : true); });
30
+ }
31
+ static specificNamesFilter(bot, ...names) {
32
+ return FilterFunctions.getNearestEntity(bot, (e) => { var _a; return e.type === "player" && names.includes((_a = e.username) !== null && _a !== void 0 ? _a : ""); });
33
+ }
34
+ nearestCrystalFilter() {
35
+ return this.getNearestEntity((e) => e.name === "ender_crystal");
36
+ }
37
+ static nearestCrystalFilter(bot) {
38
+ return FilterFunctions.getNearestEntity(bot, (e) => e.name === "ender_crystal");
39
+ }
40
+ entityAtPosition(position) {
41
+ return this.getNearestEntity((entity) => entity.position.offset(-0.5, -1, -0.5).equals(position));
42
+ }
43
+ static entityAtPosition(bot, position) { }
44
+ }
45
+ exports.FilterFunctions = FilterFunctions;
@@ -1,13 +1,10 @@
1
1
  import type { Bot } from "mineflayer";
2
2
  import { UtilFunctions } from "./utilFunctions";
3
- import { PredictiveWorld } from "./worldRelated/predictiveWorld";
4
-
5
3
  declare module "mineflayer" {
6
4
  type PrioGroups = "inventory" | "movement";
7
5
  interface Bot {
8
6
  util: UtilFunctions;
9
7
  }
10
-
11
8
  interface BotEvents {
12
9
  startedEquippingMainHand: () => void;
13
10
  startedEquippingOffHand: () => void;
@@ -17,16 +14,16 @@ declare module "mineflayer" {
17
14
  stoppedEquippingOtherSlot: () => void;
18
15
  }
19
16
  }
20
-
21
17
  declare module "prismarine-entity" {
22
18
  interface Entity {
23
- attributes: { [index: string]: { value: number; modifiers: any[] } };
19
+ attributes: {
20
+ [index: string]: {
21
+ value: number;
22
+ modifiers: any[];
23
+ };
24
+ };
24
25
  }
25
26
  }
26
-
27
- export default function inject(bot: Bot) {
28
- bot.util = new UtilFunctions(bot);
29
- }
30
-
27
+ export default function inject(bot: Bot): void;
31
28
  export { CommonSense } from "./commonSense";
32
29
  export { AABB } from "./calcs/aabb";
@@ -0,0 +1,45 @@
1
+ import { Bot, EquipmentDestination } from "mineflayer";
2
+ import { Item } from "prismarine-item";
3
+ import { BuiltInPriorityOptions } from "./utilFunctions";
4
+ /**
5
+ * Error codes:
6
+ *
7
+ * 0 = completed successfully.
8
+ *
9
+ * 1 = Item is already equipped.
10
+ *
11
+ * 2 = Item could not be found.
12
+ *
13
+ * 3 = We are currently equipping an item.
14
+ */
15
+ export declare class InventoryFunctions {
16
+ bot: Bot;
17
+ private _equippingMainHand;
18
+ private _equippingOffHand;
19
+ private _equippingOtherSlot;
20
+ usingMainHand: boolean;
21
+ usingOffHand: boolean;
22
+ constructor(bot: Bot);
23
+ set equippingOtherSlot(value: boolean);
24
+ get equippingOtherSlot(): boolean;
25
+ set equippingMainHand(value: boolean);
26
+ get equippingMainHand(): boolean;
27
+ set equippingOffHand(value: boolean);
28
+ get equippingOffHand(): boolean;
29
+ getAllItems(): Item[];
30
+ getAllItemsExceptCurrent(current: EquipmentDestination): Item[];
31
+ getHandWithItem(offhand?: boolean): Item | null;
32
+ getHand(offhand?: boolean): "hand" | "off-hand";
33
+ findItemByID(itemId: number, metadata?: number): Item | null;
34
+ findItem(name: string, metadata?: number): Item | null;
35
+ has(name: string, metadata?: number): boolean;
36
+ equipItemRaw(item: Item, dest: EquipmentDestination): Promise<boolean>;
37
+ equipItem(name: string, dest: EquipmentDestination, options: BuiltInPriorityOptions): Promise<number>;
38
+ equipMainHand(name: string, options?: BuiltInPriorityOptions): Promise<number>;
39
+ equipOffHand(name: string, options?: BuiltInPriorityOptions): Promise<number>;
40
+ equipSlot(name: string, destination: EquipmentDestination, options?: BuiltInPriorityOptions): Promise<number>;
41
+ equipMainHandNoWait(name: string, options: BuiltInPriorityOptions): Promise<number>;
42
+ equipOffHandNoWait(name: string, options: BuiltInPriorityOptions): Promise<number>;
43
+ equipSlotNoWait(name: string, dest: EquipmentDestination, options: BuiltInPriorityOptions): Promise<number>;
44
+ customEquip(item: Item, destination: EquipmentDestination, retries?: number): Promise<boolean>;
45
+ }
@@ -0,0 +1,208 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.InventoryFunctions = void 0;
13
+ const util_1 = require("util");
14
+ const sleep = (0, util_1.promisify)(setTimeout);
15
+ /**
16
+ * Error codes:
17
+ *
18
+ * 0 = completed successfully.
19
+ *
20
+ * 1 = Item is already equipped.
21
+ *
22
+ * 2 = Item could not be found.
23
+ *
24
+ * 3 = We are currently equipping an item.
25
+ */
26
+ class InventoryFunctions {
27
+ constructor(bot) {
28
+ this.bot = bot;
29
+ this._equippingMainHand = false;
30
+ this._equippingOffHand = false;
31
+ this._equippingOtherSlot = false;
32
+ this.usingMainHand = false;
33
+ this.usingOffHand = false;
34
+ }
35
+ set equippingOtherSlot(value) {
36
+ if (this._equippingOtherSlot === value)
37
+ return;
38
+ if (value)
39
+ this.bot.emit("startedEquippingOtherSlot");
40
+ else
41
+ this.bot.emit("stoppedEquippingOtherSlot");
42
+ this._equippingOtherSlot = value;
43
+ }
44
+ get equippingOtherSlot() {
45
+ return this._equippingOtherSlot;
46
+ }
47
+ set equippingMainHand(value) {
48
+ if (this._equippingMainHand === value)
49
+ return;
50
+ if (value)
51
+ this.bot.emit("startedEquippingMainHand");
52
+ else
53
+ this.bot.emit("stoppedEquippingMainHand");
54
+ this._equippingMainHand = value;
55
+ }
56
+ get equippingMainHand() {
57
+ return this._equippingMainHand;
58
+ }
59
+ set equippingOffHand(value) {
60
+ if (this._equippingOffHand === value)
61
+ return;
62
+ if (value)
63
+ this.bot.emit("startedEquippingOffHand");
64
+ else
65
+ this.bot.emit("stoppedEquippingOffHand");
66
+ this._equippingOffHand = value;
67
+ }
68
+ get equippingOffHand() {
69
+ return this._equippingOffHand;
70
+ }
71
+ getAllItems() {
72
+ return [
73
+ ...this.bot.inventory.items(),
74
+ ...["hand", "head", "torso", "legs", "feet", "off-hand"].map((name) => this.bot.inventory.slots[this.bot.getEquipmentDestSlot(name)]),
75
+ ].filter((e) => !!e);
76
+ }
77
+ getAllItemsExceptCurrent(current) {
78
+ return [
79
+ ...this.bot.inventory.items(),
80
+ ...["hand", "head", "torso", "legs", "feet", "off-hand"]
81
+ .filter((name) => name !== current)
82
+ .map((name) => this.bot.inventory.slots[this.bot.getEquipmentDestSlot(name)]),
83
+ ].filter((e) => !!e);
84
+ }
85
+ getHandWithItem(offhand) {
86
+ return this.bot.inventory.slots[this.bot.getEquipmentDestSlot(this.getHand(offhand))];
87
+ }
88
+ getHand(offhand = false) {
89
+ return offhand ? "off-hand" : "hand";
90
+ }
91
+ findItemByID(itemId, metadata) {
92
+ var _a, _b;
93
+ const potentialMatches = this.getAllItems().filter((item) => item.type === itemId);
94
+ 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;
97
+ }
98
+ findItem(name, metadata) {
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
+ 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;
105
+ }
106
+ //alias.
107
+ has(name, metadata) {
108
+ return !!this.findItem(name, metadata);
109
+ }
110
+ equipItemRaw(item, dest) {
111
+ return __awaiter(this, void 0, void 0, function* () {
112
+ if (this.bot.inventory.slots[this.bot.getEquipmentDestSlot(dest)] === item)
113
+ return true;
114
+ yield this.bot.equip(item, dest);
115
+ return false;
116
+ });
117
+ }
118
+ equipItem(name, dest, options) {
119
+ var _a;
120
+ return __awaiter(this, void 0, void 0, function* () {
121
+ if ((_a = this.bot.inventory.slots[this.bot.getEquipmentDestSlot(dest)]) === null || _a === void 0 ? void 0 : _a.name.includes(name))
122
+ return 1;
123
+ const item = this.getAllItemsExceptCurrent(dest).find((item) => item === null || item === void 0 ? void 0 : item.name.includes(name));
124
+ if (!!item) {
125
+ yield this.bot.util.builtInsPriority(options, this.bot.equip, item, dest);
126
+ return 0;
127
+ }
128
+ return 2;
129
+ });
130
+ }
131
+ equipMainHand(name, options = { group: "inventory", priority: 1 }) {
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ while (this._equippingMainHand) {
134
+ yield sleep(0);
135
+ }
136
+ return yield this.equipMainHandNoWait(name, options);
137
+ });
138
+ }
139
+ equipOffHand(name, options = { group: "inventory", priority: 1 }) {
140
+ return __awaiter(this, void 0, void 0, function* () {
141
+ while (this._equippingOffHand) {
142
+ yield sleep(0);
143
+ }
144
+ return yield this.equipOffHandNoWait(name, options);
145
+ });
146
+ }
147
+ equipSlot(name, destination, options = { group: "inventory", priority: 1 }) {
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ while (this._equippingOtherSlot) {
150
+ yield sleep(0);
151
+ }
152
+ return yield this.equipSlotNoWait(name, destination, options);
153
+ });
154
+ }
155
+ equipMainHandNoWait(name, options) {
156
+ return __awaiter(this, void 0, void 0, function* () {
157
+ if (this._equippingMainHand)
158
+ return 3;
159
+ this._equippingMainHand = true;
160
+ const result = yield this.equipItem(name, "hand", options);
161
+ this._equippingMainHand = false;
162
+ return result;
163
+ });
164
+ }
165
+ equipOffHandNoWait(name, options) {
166
+ return __awaiter(this, void 0, void 0, function* () {
167
+ if (this._equippingOffHand)
168
+ return 3;
169
+ this.equippingOffHand = true;
170
+ const result = yield this.equipItem(name, "off-hand", options);
171
+ this.equippingOffHand = false;
172
+ return result;
173
+ });
174
+ }
175
+ equipSlotNoWait(name, dest, options) {
176
+ return __awaiter(this, void 0, void 0, function* () {
177
+ if (this._equippingOtherSlot)
178
+ return 3;
179
+ this.equippingOtherSlot = true;
180
+ const result = yield this.equipItem(name, dest, options);
181
+ this.equippingOtherSlot = false;
182
+ return result;
183
+ });
184
+ }
185
+ customEquip(item, destination, retries = 1) {
186
+ return __awaiter(this, void 0, void 0, function* () {
187
+ for (let i = 0; i < retries; i++) {
188
+ try {
189
+ yield this.bot.equip(item, destination);
190
+ return true;
191
+ }
192
+ catch (error) {
193
+ if (this.bot.inventory.selectedItem) {
194
+ const slot = this.bot.inventory.firstEmptyInventorySlot(false) || -999;
195
+ try {
196
+ yield this.bot.clickWindow(slot, 0, 0);
197
+ }
198
+ catch (error) {
199
+ return false;
200
+ }
201
+ }
202
+ }
203
+ }
204
+ return false;
205
+ });
206
+ }
207
+ }
208
+ exports.InventoryFunctions = InventoryFunctions;
@@ -0,0 +1,23 @@
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
+ }
@@ -1,6 +1,7 @@
1
- import { Bot } from "mineflayer";
2
- import { Vec3 } from "vec3";
3
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MathFunctions = void 0;
4
+ const vec3_1 = require("vec3");
4
5
  const PI = Math.PI;
5
6
  const PI_2 = Math.PI * 2;
6
7
  const TO_RAD = PI / 180;
@@ -8,49 +9,41 @@ const TO_DEG = 1 / TO_RAD;
8
9
  const FROM_NOTCH_BYTE = 360 / 256;
9
10
  // From wiki.vg: Velocity is believed to be in units of 1/8000 of a block per server tick (50ms)
10
11
  const FROM_NOTCH_VEL = 1 / 8000;
11
-
12
- export class MathFunctions {
13
- constructor() {}
14
-
15
- toNotchianYaw = (yaw: number) => this.toDegrees(PI - yaw);
16
- toNotchianPitch = (pitch: number) => this.toDegrees(-pitch);
17
- fromNotchianYawByte = (yaw: number) => this.fromNotchianYaw(yaw * FROM_NOTCH_BYTE);
18
- fromNotchianPitchByte = (pitch: number) => this.fromNotchianPitch(pitch * FROM_NOTCH_BYTE);
19
-
20
- euclideanMod(numerator: number, denominator: number) {
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) {
21
20
  const result = numerator % denominator;
22
21
  return result < 0 ? result + denominator : result;
23
22
  }
24
-
25
- toRadians(degrees: number) {
23
+ toRadians(degrees) {
26
24
  return TO_RAD * degrees;
27
25
  }
28
-
29
- toDegrees(radians: number) {
26
+ toDegrees(radians) {
30
27
  return TO_DEG * radians;
31
28
  }
32
-
33
- fromNotchianYaw(yaw: number) {
29
+ fromNotchianYaw(yaw) {
34
30
  return this.euclideanMod(PI - this.toRadians(yaw), PI_2);
35
31
  }
36
-
37
- fromNotchianPitch(pitch: number) {
32
+ fromNotchianPitch(pitch) {
38
33
  return this.euclideanMod(this.toRadians(-pitch) + PI, PI_2) - PI;
39
34
  }
40
-
41
- fromNotchVelocity(vel: Vec3) {
42
- return new Vec3(vel.x * FROM_NOTCH_VEL, vel.y * FROM_NOTCH_VEL, vel.z * FROM_NOTCH_VEL);
35
+ fromNotchVelocity(vel) {
36
+ return new vec3_1.Vec3(vel.x * FROM_NOTCH_VEL, vel.y * FROM_NOTCH_VEL, vel.z * FROM_NOTCH_VEL);
43
37
  }
44
-
45
- pointToYawAndPitch(bot: Bot, point: Vec3) {
38
+ pointToYawAndPitch(bot, point) {
46
39
  const delta = point.minus(bot.entity.position.offset(0, bot.entity.height, 0));
47
40
  return this.dirToYawAndPitch(delta);
48
41
  }
49
-
50
- dirToYawAndPitch(dir: Vec3) {
42
+ dirToYawAndPitch(dir) {
51
43
  const yaw = Math.atan2(-dir.x, -dir.z);
52
44
  const groundDistance = Math.sqrt(dir.x * dir.x + dir.z * dir.z);
53
45
  const pitch = Math.atan2(dir.y, groundDistance);
54
46
  return { yaw: yaw, pitch: pitch };
55
47
  }
56
48
  }
49
+ exports.MathFunctions = MathFunctions;
@@ -0,0 +1,43 @@
1
+ import type { Bot } from "mineflayer";
2
+ import type { Entity } from "prismarine-entity";
3
+ import type { Vec3 } from "vec3";
4
+ import { goals } from "mineflayer-pathfinder";
5
+ export declare class MovementFunctions {
6
+ bot: Bot;
7
+ goalArray: goals.GoalCompositeAll;
8
+ lastYaw: number;
9
+ lastPitch: number;
10
+ constructor(bot: Bot);
11
+ /**
12
+ * Fuckin' mineflayer-pathfinder still doesn't have typings.
13
+ * Pain in my goddamn ass.
14
+ * @returns have the goal changed
15
+ */
16
+ addGoal(goal: any): boolean;
17
+ /**
18
+ * Sets current goal and clears all others.
19
+ * @param goal any type of mineflayer-pathfinder goal.
20
+ * @returns have the goal changed
21
+ */
22
+ setOnlyGoal(goal: any, dynamic?: boolean): boolean;
23
+ /**
24
+ * Reset all goals inside the goal array to none.
25
+ * @returns have the goals changed
26
+ */
27
+ stop(): boolean;
28
+ /**
29
+ * Retreat from current entity.
30
+ * @param entity Prismarine-Entity Entity
31
+ * @returns have the goals changed.
32
+ */
33
+ retreatFromEntity(entity: Entity, distance: number, dynamic?: boolean): boolean;
34
+ /**
35
+ * Follow entity with a specific range. Will not approach past a certain distance either.
36
+ * @param entity Prismarine-Entity Entity
37
+ * @returns have the goals changed
38
+ */
39
+ followEntityWithRespectRange(entity: Entity, followDistance: number, invertDistance?: number): boolean;
40
+ forceLook(yaw: number, pitch: number, update?: boolean): void;
41
+ forceLookAt(pos: Vec3, update?: boolean, trueForce?: boolean): void;
42
+ lazyTeleport(endPos: Vec3): void;
43
+ }