@nxg-org/mineflayer-util-plugin 1.0.0 → 1.2.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.
- package/lib/entityFunctions.d.ts +14 -1
- package/lib/entityFunctions.js +32 -6
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -0
- package/lib/utilFunctions.d.ts +0 -2
- package/lib/utilFunctions.js +0 -2
- package/package-lock.json +1505 -0
- package/package.json +2 -1
- package/lib/commonSense.d.ts +0 -22
- package/lib/commonSense.js +0 -220
- package/src/WorldFunctions.ts +0 -19
- package/src/calcs/aabb.ts +0 -218
- package/src/commonSense.ts +0 -189
- package/src/customImplementations/inventory.ts +0 -90
- package/src/entityFunctions.ts +0 -71
- package/src/filterFunctions.ts +0 -54
- package/src/index.ts +0 -29
- package/src/inventoryFunctions.ts +0 -187
- package/src/mathUtil.ts +0 -56
- package/src/movementFunctions.ts +0 -116
- package/src/predictiveFunctions.ts +0 -187
- package/src/utilFunctions.ts +0 -152
- package/src/worldRelated/predictiveWorld.ts +0 -109
- package/src/worldRelated/raycastIterator.ts +0 -136
- package/tsconfig.json +0 -17
package/lib/entityFunctions.d.ts
CHANGED
|
@@ -23,9 +23,21 @@ export declare class EntityFunctions {
|
|
|
23
23
|
/**
|
|
24
24
|
* TODO: Version specific right now. Generalize. Unknown method.
|
|
25
25
|
* @param metadata metadata from Prismarine-Entity Entity.
|
|
26
|
-
* @returns
|
|
26
|
+
* @returns number
|
|
27
27
|
*/
|
|
28
28
|
getHealth(entity?: Entity): number;
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @param metadata Must be FULL metadata object.
|
|
32
|
+
* @returns number
|
|
33
|
+
*/
|
|
34
|
+
getHealthFromMetadata(metadata: object[]): number;
|
|
35
|
+
/**
|
|
36
|
+
* TODO: Version specific right now. Generalize. Unknown method.
|
|
37
|
+
* @param metadata metadata from Prismarine-Entity Entity.
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
getHealthChange(packetMetadata: any, entity: Entity): number;
|
|
29
41
|
getDistanceToEntity(entity: Entity): number;
|
|
30
42
|
getDistanceBetweenEntities(first: Entity, second: Entity): number;
|
|
31
43
|
getEntityAABB(entity: {
|
|
@@ -33,4 +45,5 @@ export declare class EntityFunctions {
|
|
|
33
45
|
height: number;
|
|
34
46
|
width?: number;
|
|
35
47
|
}): AABB;
|
|
48
|
+
private parseMetadata;
|
|
36
49
|
}
|
package/lib/entityFunctions.js
CHANGED
|
@@ -45,15 +45,13 @@ class EntityFunctions {
|
|
|
45
45
|
/**
|
|
46
46
|
* TODO: Version specific right now. Generalize. Unknown method.
|
|
47
47
|
* @param metadata metadata from Prismarine-Entity Entity.
|
|
48
|
-
* @returns
|
|
48
|
+
* @returns number
|
|
49
49
|
*/
|
|
50
50
|
getHealth(entity) {
|
|
51
51
|
var _a, _b;
|
|
52
|
-
entity
|
|
53
|
-
|
|
54
|
-
//
|
|
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);
|
|
52
|
+
entity !== null && entity !== void 0 ? entity : (entity = this.bot.entity);
|
|
53
|
+
const metadata = entity.metadata;
|
|
54
|
+
const healthSlot = this.healthSlot; //metadata[this.healthSlot] ? this.healthSlot : metadata.findIndex((met) => Number(met) > 1 && Number(met) <= 20);
|
|
57
55
|
let health = Number(metadata[healthSlot]);
|
|
58
56
|
if (!health || health === 0)
|
|
59
57
|
health = entity === this.bot.entity ? (_a = this.bot.entity.health) !== null && _a !== void 0 ? _a : 0 : 0;
|
|
@@ -62,6 +60,25 @@ class EntityFunctions {
|
|
|
62
60
|
// console.log(health + (Number(metadata[this.healthSlot + 4]) ?? 0))
|
|
63
61
|
return health + ((_b = Number(metadata[this.healthSlot + 4])) !== null && _b !== void 0 ? _b : 0);
|
|
64
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
*
|
|
65
|
+
* @param metadata Must be FULL metadata object.
|
|
66
|
+
* @returns number
|
|
67
|
+
*/
|
|
68
|
+
getHealthFromMetadata(metadata) {
|
|
69
|
+
var _a;
|
|
70
|
+
return (_a = (Number(metadata[this.healthSlot]) + Number(metadata[this.healthSlot + 4]))) !== null && _a !== void 0 ? _a : undefined;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* TODO: Version specific right now. Generalize. Unknown method.
|
|
74
|
+
* @param metadata metadata from Prismarine-Entity Entity.
|
|
75
|
+
* @returns
|
|
76
|
+
*/
|
|
77
|
+
getHealthChange(packetMetadata, entity) {
|
|
78
|
+
const oldMetadata = entity.metadata;
|
|
79
|
+
const newMetadata = this.parseMetadata(packetMetadata, oldMetadata);
|
|
80
|
+
return this.getHealthFromMetadata(newMetadata) - this.getHealthFromMetadata(oldMetadata);
|
|
81
|
+
}
|
|
65
82
|
getDistanceToEntity(entity) {
|
|
66
83
|
return this.getDistanceBetweenEntities(this.bot.entity, entity);
|
|
67
84
|
}
|
|
@@ -74,5 +91,14 @@ class EntityFunctions {
|
|
|
74
91
|
const { x, y, z } = entity.position;
|
|
75
92
|
return new aabb_1.AABB(-w, 0, -w, w, entity.height, w).offset(x, y, z);
|
|
76
93
|
}
|
|
94
|
+
//Stolen from mineflayer.
|
|
95
|
+
parseMetadata(metadata, entityMetadata = {}) {
|
|
96
|
+
if (metadata !== undefined) {
|
|
97
|
+
for (const { key, value } of metadata) {
|
|
98
|
+
entityMetadata[key] = value;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return entityMetadata;
|
|
102
|
+
}
|
|
77
103
|
}
|
|
78
104
|
exports.EntityFunctions = EntityFunctions;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AABB = void 0;
|
|
3
4
|
const utilFunctions_1 = require("./utilFunctions");
|
|
4
5
|
function inject(bot) {
|
|
5
6
|
bot.util = new utilFunctions_1.UtilFunctions(bot);
|
|
6
7
|
}
|
|
7
8
|
exports.default = inject;
|
|
9
|
+
var aabb_1 = require("./calcs/aabb");
|
|
10
|
+
Object.defineProperty(exports, "AABB", { enumerable: true, get: function () { return aabb_1.AABB; } });
|
package/lib/utilFunctions.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ import { InventoryFunctions } from "./inventoryFunctions";
|
|
|
6
6
|
import { MovementFunctions } from "./movementFunctions";
|
|
7
7
|
import { PredictiveFunctions } from "./predictiveFunctions";
|
|
8
8
|
import { MathFunctions } from "./mathUtil";
|
|
9
|
-
import { CommonSense } from "./commonSense";
|
|
10
9
|
import { WorldFunctions } from "./WorldFunctions";
|
|
11
10
|
export declare type BuiltInPriorityOptions = {
|
|
12
11
|
group: PrioGroups;
|
|
@@ -28,7 +27,6 @@ export declare class UtilFunctions {
|
|
|
28
27
|
predict: PredictiveFunctions;
|
|
29
28
|
filters: FilterFunctions;
|
|
30
29
|
math: MathFunctions;
|
|
31
|
-
commonSense: CommonSense;
|
|
32
30
|
world: WorldFunctions;
|
|
33
31
|
private builtInsPriorityStore;
|
|
34
32
|
private customPriorityStore;
|
package/lib/utilFunctions.js
CHANGED
|
@@ -17,7 +17,6 @@ const movementFunctions_1 = require("./movementFunctions");
|
|
|
17
17
|
const util_1 = require("util");
|
|
18
18
|
const predictiveFunctions_1 = require("./predictiveFunctions");
|
|
19
19
|
const mathUtil_1 = require("./mathUtil");
|
|
20
|
-
const commonSense_1 = require("./commonSense");
|
|
21
20
|
const WorldFunctions_1 = require("./WorldFunctions");
|
|
22
21
|
class UtilFunctions {
|
|
23
22
|
constructor(bot) {
|
|
@@ -28,7 +27,6 @@ class UtilFunctions {
|
|
|
28
27
|
this.entity = new entityFunctions_1.EntityFunctions(bot);
|
|
29
28
|
this.predict = new predictiveFunctions_1.PredictiveFunctions(bot);
|
|
30
29
|
this.filters = new filterFunctions_1.FilterFunctions(bot);
|
|
31
|
-
this.commonSense = new commonSense_1.CommonSense(bot);
|
|
32
30
|
this.world = new WorldFunctions_1.WorldFunctions(bot);
|
|
33
31
|
this.math = new mathUtil_1.MathFunctions();
|
|
34
32
|
this.builtInsPriorityStore = {};
|