@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.
- package/lib/WorldFunctions.d.ts +10 -0
- package/lib/WorldFunctions.js +18 -0
- package/lib/calcs/aabb.d.ts +36 -0
- package/{src/calcs/aabb.ts → lib/calcs/aabb.js} +52 -76
- package/lib/commonSense.d.ts +22 -0
- package/lib/commonSense.js +220 -0
- package/lib/customImplementations/inventory.d.ts +10 -0
- package/lib/customImplementations/inventory.js +95 -0
- package/lib/entityFunctions.d.ts +36 -0
- package/lib/entityFunctions.js +78 -0
- package/lib/filterFunctions.d.ts +23 -0
- package/lib/filterFunctions.js +45 -0
- package/{src/index.ts → lib/index.d.ts} +7 -10
- package/lib/inventoryFunctions.d.ts +45 -0
- package/lib/inventoryFunctions.js +208 -0
- package/lib/mathUtil.d.ts +23 -0
- package/{src/mathUtil.ts → lib/mathUtil.js} +21 -28
- package/lib/movementFunctions.d.ts +43 -0
- package/{src/movementFunctions.ts → lib/movementFunctions.js} +36 -43
- package/lib/predictiveFunctions.d.ts +25 -0
- package/{src/predictiveFunctions.ts → lib/predictiveFunctions.js} +62 -77
- package/lib/utilFunctions.d.ts +50 -0
- package/lib/utilFunctions.js +140 -0
- package/lib/worldRelated/predictiveWorld.d.ts +41 -0
- package/{src/worldRelated/predictiveWorld.ts → lib/worldRelated/predictiveWorld.js} +39 -40
- package/lib/worldRelated/raycastIterator.d.ts +45 -0
- package/{src/worldRelated/raycastIterator.ts → lib/worldRelated/raycastIterator.js} +37 -59
- package/package.json +2 -1
- package/.github/workflows/ci.yml +0 -22
- package/.github/workflows/release.yml +0 -37
- package/src/WorldFunctions.ts +0 -19
- 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/inventoryFunctions.ts +0 -187
- package/src/utilFunctions.ts +0 -152
- package/tsconfig.json +0 -17
|
@@ -1,109 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MovementFunctions = void 0;
|
|
4
|
+
const mineflayer_pathfinder_1 = require("mineflayer-pathfinder");
|
|
5
|
+
const { GoalCompositeAll, GoalInvert, GoalFollow } = mineflayer_pathfinder_1.goals;
|
|
6
|
+
class MovementFunctions {
|
|
7
|
+
constructor(bot) {
|
|
8
|
+
this.bot = bot;
|
|
9
|
+
this.goalArray = new GoalCompositeAll();
|
|
10
|
+
this.lastYaw = 0;
|
|
11
|
+
this.lastPitch = 0;
|
|
12
|
+
}
|
|
14
13
|
/**
|
|
15
14
|
* Fuckin' mineflayer-pathfinder still doesn't have typings.
|
|
16
15
|
* Pain in my goddamn ass.
|
|
17
16
|
* @returns have the goal changed
|
|
18
17
|
*/
|
|
19
|
-
addGoal(goal
|
|
20
|
-
if (this.goalArray.goals.find((inGoal) => inGoal === goal))
|
|
18
|
+
addGoal(goal) {
|
|
19
|
+
if (this.goalArray.goals.find((inGoal) => inGoal === goal))
|
|
20
|
+
return false;
|
|
21
21
|
this.goalArray.push(goal);
|
|
22
22
|
return true;
|
|
23
23
|
}
|
|
24
|
-
|
|
25
24
|
/**
|
|
26
25
|
* Sets current goal and clears all others.
|
|
27
26
|
* @param goal any type of mineflayer-pathfinder goal.
|
|
28
27
|
* @returns have the goal changed
|
|
29
28
|
*/
|
|
30
|
-
setOnlyGoal(goal
|
|
29
|
+
setOnlyGoal(goal, dynamic = false) {
|
|
31
30
|
const goalArr = [goal];
|
|
32
|
-
if (this.goalArray.goals === goalArr)
|
|
31
|
+
if (this.goalArray.goals === goalArr)
|
|
32
|
+
return false;
|
|
33
33
|
this.goalArray.goals = goalArr;
|
|
34
34
|
this.bot.pathfinder.setGoal(this.goalArray, dynamic);
|
|
35
35
|
return true;
|
|
36
36
|
}
|
|
37
|
-
|
|
38
37
|
/**
|
|
39
38
|
* Reset all goals inside the goal array to none.
|
|
40
39
|
* @returns have the goals changed
|
|
41
40
|
*/
|
|
42
|
-
stop()
|
|
43
|
-
if (this.goalArray.goals.length === 0)
|
|
41
|
+
stop() {
|
|
42
|
+
if (this.goalArray.goals.length === 0)
|
|
43
|
+
return false;
|
|
44
44
|
this.goalArray.goals = [];
|
|
45
45
|
this.bot.pathfinder.setGoal(null);
|
|
46
46
|
return true;
|
|
47
47
|
}
|
|
48
|
-
|
|
49
48
|
/**
|
|
50
49
|
* Retreat from current entity.
|
|
51
50
|
* @param entity Prismarine-Entity Entity
|
|
52
51
|
* @returns have the goals changed.
|
|
53
52
|
*/
|
|
54
|
-
retreatFromEntity(entity
|
|
53
|
+
retreatFromEntity(entity, distance, dynamic = true) {
|
|
55
54
|
const oldGoals = this.goalArray.goals.length;
|
|
56
|
-
this.goalArray.goals = this.goalArray.goals.filter(
|
|
57
|
-
(goal: any) => goal.goal?.entity?.id === entity.id && goal.goal?.rangeSq === distance * distance
|
|
58
|
-
);
|
|
55
|
+
this.goalArray.goals = this.goalArray.goals.filter((goal) => { var _a, _b, _c; return ((_b = (_a = goal.goal) === null || _a === void 0 ? void 0 : _a.entity) === null || _b === void 0 ? void 0 : _b.id) === entity.id && ((_c = goal.goal) === null || _c === void 0 ? void 0 : _c.rangeSq) === distance * distance; });
|
|
59
56
|
if (oldGoals !== this.goalArray.goals.length || this.goalArray.goals.length === 0) {
|
|
60
|
-
this.goalArray.push(new GoalFollow(entity
|
|
61
|
-
this.goalArray.push(new GoalInvert(new GoalFollow(entity
|
|
57
|
+
this.goalArray.push(new GoalFollow(entity, distance));
|
|
58
|
+
this.goalArray.push(new GoalInvert(new GoalFollow(entity, distance - 1)));
|
|
62
59
|
this.bot.pathfinder.setGoal(this.goalArray, dynamic);
|
|
63
60
|
return true;
|
|
64
61
|
}
|
|
65
62
|
return false;
|
|
66
63
|
}
|
|
67
|
-
|
|
68
64
|
/**
|
|
69
65
|
* Follow entity with a specific range. Will not approach past a certain distance either.
|
|
70
66
|
* @param entity Prismarine-Entity Entity
|
|
71
67
|
* @returns have the goals changed
|
|
72
68
|
*/
|
|
73
|
-
followEntityWithRespectRange(entity
|
|
69
|
+
followEntityWithRespectRange(entity, followDistance, invertDistance) {
|
|
74
70
|
const oldGoals = this.goalArray.goals.length;
|
|
75
|
-
this.goalArray.goals =
|
|
76
|
-
|
|
71
|
+
this.goalArray.goals = this.goalArray.goals.filter((goal) => {
|
|
72
|
+
var _a;
|
|
73
|
+
return ((_a = goal.entity) === null || _a === void 0 ? void 0 : _a.id) === entity.id && goal.rangeSq === followDistance * followDistance;
|
|
77
74
|
});
|
|
78
|
-
|
|
79
75
|
if (oldGoals !== this.goalArray.goals.length || !this.bot.pathfinder.isMoving() || this.goalArray.goals.length === 0) {
|
|
80
76
|
if (this.goalArray.goals.length > 0) {
|
|
81
77
|
this.goalArray.goals = [];
|
|
82
78
|
}
|
|
83
79
|
this.goalArray.push(new GoalFollow(entity, followDistance));
|
|
84
|
-
this.goalArray.push(new GoalInvert(new GoalFollow(entity, invertDistance
|
|
80
|
+
this.goalArray.push(new GoalInvert(new GoalFollow(entity, invertDistance !== null && invertDistance !== void 0 ? invertDistance : followDistance - 0.5)));
|
|
85
81
|
this.bot.pathfinder.setGoal(this.goalArray, true);
|
|
86
82
|
return true;
|
|
87
83
|
}
|
|
88
|
-
|
|
89
84
|
return false;
|
|
90
85
|
}
|
|
91
|
-
|
|
92
|
-
forceLook(yaw: number, pitch: number, update: boolean = false) {
|
|
86
|
+
forceLook(yaw, pitch, update = false) {
|
|
93
87
|
const notchianYawAndPitch = { yaw: this.bot.util.math.toNotchianYaw(yaw), pitch: this.bot.util.math.toNotchianPitch(pitch) };
|
|
94
|
-
this.bot._client.write("look", {
|
|
88
|
+
this.bot._client.write("look", Object.assign(Object.assign({}, notchianYawAndPitch), { onGround: false }));
|
|
95
89
|
if (update) {
|
|
96
90
|
// this.bot.entity.yaw = yaw;
|
|
97
91
|
// this.bot.entity.pitch = pitch
|
|
98
92
|
this.bot.look(yaw, pitch, true);
|
|
99
93
|
}
|
|
100
94
|
}
|
|
101
|
-
|
|
102
|
-
forceLookAt(pos: Vec3, update: boolean = false, trueForce: boolean = false) {
|
|
95
|
+
forceLookAt(pos, update = false, trueForce = false) {
|
|
103
96
|
const { yaw, pitch } = this.bot.util.math.pointToYawAndPitch(this.bot, pos);
|
|
104
97
|
const nyp = { yaw: this.bot.util.math.toNotchianYaw(yaw), pitch: this.bot.util.math.toNotchianPitch(pitch) };
|
|
105
98
|
if (nyp.yaw !== this.lastYaw || nyp.pitch !== this.lastPitch || trueForce) {
|
|
106
|
-
this.bot._client.write("look", {
|
|
99
|
+
this.bot._client.write("look", Object.assign(Object.assign({}, nyp), { onGround: false }));
|
|
107
100
|
if (update) {
|
|
108
101
|
// this.bot.entity.yaw = yaw;
|
|
109
102
|
// this.bot.entity.pitch = pitch
|
|
@@ -111,6 +104,6 @@ export class MovementFunctions {
|
|
|
111
104
|
}
|
|
112
105
|
}
|
|
113
106
|
}
|
|
114
|
-
|
|
115
|
-
lazyTeleport(endPos: Vec3) {}
|
|
107
|
+
lazyTeleport(endPos) { }
|
|
116
108
|
}
|
|
109
|
+
exports.MovementFunctions = MovementFunctions;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Bot } from "mineflayer";
|
|
2
|
+
import type { Entity } from "prismarine-entity";
|
|
3
|
+
import { Vec3 } from "vec3";
|
|
4
|
+
import { Overwrites, PredictiveWorld } from "./worldRelated/predictiveWorld";
|
|
5
|
+
export declare const ARMOR_THOUGHNESS_KEY = "generic.armorToughness";
|
|
6
|
+
export declare class PredictiveFunctions {
|
|
7
|
+
private bot;
|
|
8
|
+
private damageMultiplier;
|
|
9
|
+
private armorToughnessKey;
|
|
10
|
+
private armorProtectionKey;
|
|
11
|
+
private resistanceIndex;
|
|
12
|
+
world: PredictiveWorld;
|
|
13
|
+
constructor(bot: Bot);
|
|
14
|
+
getDamageWithEffects(damage: number, effects: {
|
|
15
|
+
[id: string]: {
|
|
16
|
+
id: number;
|
|
17
|
+
amplifier: number;
|
|
18
|
+
duration: number;
|
|
19
|
+
};
|
|
20
|
+
}): number;
|
|
21
|
+
placeBlocks(blocks: Overwrites): void;
|
|
22
|
+
removePredictedBlocks(positions: Vec3[], force?: boolean): void;
|
|
23
|
+
selfExplosionDamage(sourcePos: Vec3, power: number, rawDamages?: boolean): number;
|
|
24
|
+
getExplosionDamage(targetEntity: Entity, sourcePos: Vec3, power: number, rawDamages?: boolean): number;
|
|
25
|
+
}
|
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PredictiveFunctions = exports.ARMOR_THOUGHNESS_KEY = void 0;
|
|
7
|
+
const minecraft_data_1 = __importDefault(require("minecraft-data"));
|
|
8
|
+
const vec3_1 = require("vec3");
|
|
9
|
+
const predictiveWorld_1 = require("./worldRelated/predictiveWorld");
|
|
10
10
|
const armorPieces = ["head", "torso", "legs", "feet"];
|
|
11
|
-
|
|
12
11
|
// https://minecraft.fandom.com/wiki/Explosion
|
|
13
12
|
// Use bot.world, there's no typing yet.
|
|
14
|
-
function calcExposure(playerPos
|
|
13
|
+
function calcExposure(playerPos, explosionPos, world) {
|
|
15
14
|
const dx = 1 / (0.6 * 2 + 1);
|
|
16
15
|
const dy = 1 / (1.8 * 2 + 1);
|
|
17
16
|
const dz = 1 / (0.6 * 2 + 1);
|
|
18
|
-
|
|
19
17
|
const d3 = (1 - Math.floor(1 / dx) * dx) / 2;
|
|
20
18
|
const d4 = (1 - Math.floor(1 / dz) * dz) / 2;
|
|
21
|
-
|
|
22
19
|
let sampled = 0;
|
|
23
20
|
let exposed = 0;
|
|
24
|
-
const pos = new Vec3(0, 0, 0);
|
|
21
|
+
const pos = new vec3_1.Vec3(0, 0, 0);
|
|
25
22
|
for (pos.y = playerPos.y; pos.y <= playerPos.y + 1.8; pos.y += 1.8 * dy) {
|
|
26
23
|
for (pos.x = playerPos.x - 0.3 + d3; pos.x <= playerPos.x + 0.3; pos.x += 0.6 * dx) {
|
|
27
24
|
for (pos.z = playerPos.z - 0.3 + d4; pos.z <= playerPos.z + 0.3; pos.z += 0.6 * dz) {
|
|
@@ -36,84 +33,75 @@ function calcExposure(playerPos: Vec3, explosionPos: Vec3, world: any) {
|
|
|
36
33
|
}
|
|
37
34
|
return exposed / sampled;
|
|
38
35
|
}
|
|
39
|
-
|
|
40
36
|
// https://minecraft.fandom.com/wiki/Armor#Damage_protection
|
|
41
|
-
function getDamageAfterAbsorb(damages
|
|
37
|
+
function getDamageAfterAbsorb(damages, armorValue, toughness) {
|
|
42
38
|
const var3 = 2 + toughness / 4;
|
|
43
39
|
const var4 = Math.min(Math.max(armorValue - damages / var3, armorValue * 0.2), 20);
|
|
44
40
|
return damages * (1 - var4 / 25);
|
|
45
41
|
}
|
|
46
|
-
|
|
47
42
|
// https://minecraft.fandom.com/wiki/Attribute#Operations
|
|
48
|
-
function getAttributeValue(prop
|
|
43
|
+
function getAttributeValue(prop) {
|
|
49
44
|
let X = prop.value;
|
|
50
45
|
for (const mod of prop.modifiers) {
|
|
51
|
-
if (mod.operation !== 0)
|
|
46
|
+
if (mod.operation !== 0)
|
|
47
|
+
continue;
|
|
52
48
|
X += mod.amount;
|
|
53
49
|
}
|
|
54
50
|
let Y = X;
|
|
55
51
|
for (const mod of prop.modifiers) {
|
|
56
|
-
if (mod.operation !== 1)
|
|
52
|
+
if (mod.operation !== 1)
|
|
53
|
+
continue;
|
|
57
54
|
Y += X * mod.amount;
|
|
58
55
|
}
|
|
59
56
|
for (const mod of prop.modifiers) {
|
|
60
|
-
if (mod.operation !== 2)
|
|
57
|
+
if (mod.operation !== 2)
|
|
58
|
+
continue;
|
|
61
59
|
Y += Y * mod.amount;
|
|
62
60
|
}
|
|
63
61
|
return Y;
|
|
64
62
|
}
|
|
65
|
-
|
|
66
|
-
function getDamageWithEnchantments(damage: number, equipment: Item[]) {
|
|
63
|
+
function getDamageWithEnchantments(damage, equipment) {
|
|
67
64
|
const enchantments = equipment.some((e) => !!e)
|
|
68
65
|
? equipment
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
)
|
|
84
|
-
.reduce((b: number, a: number) => b + a, 0)
|
|
66
|
+
.map((armor) => {
|
|
67
|
+
var _a;
|
|
68
|
+
return (_a = armor === null || armor === void 0 ? void 0 : armor.enchants.map((enchant) => {
|
|
69
|
+
switch (enchant === null || enchant === void 0 ? void 0 : enchant.name) {
|
|
70
|
+
case "protection":
|
|
71
|
+
return enchant.lvl;
|
|
72
|
+
case "blast_protection":
|
|
73
|
+
return enchant.lvl * 2;
|
|
74
|
+
default:
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
}).reduce((b, a) => b + a, 0)) !== null && _a !== void 0 ? _a : [0];
|
|
78
|
+
})
|
|
79
|
+
.reduce((b, a) => b + a, 0)
|
|
85
80
|
: 0;
|
|
86
81
|
return damage * (1 - Math.min(enchantments, 20) / 25);
|
|
87
82
|
}
|
|
88
|
-
|
|
89
83
|
const DIFFICULTY_VALUES = {
|
|
90
84
|
peaceful: 0,
|
|
91
85
|
easy: 1,
|
|
92
86
|
normal: 2,
|
|
93
87
|
hard: 3,
|
|
94
88
|
};
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
private resistanceIndex = "11";
|
|
105
|
-
|
|
106
|
-
public world: PredictiveWorld;
|
|
107
|
-
|
|
108
|
-
constructor(private bot: Bot) {
|
|
109
|
-
if ((require('minecraft-data') as (typeof import('minecraft-data')))(bot.version).isNewerOrEqualTo("1.16")){
|
|
89
|
+
exports.ARMOR_THOUGHNESS_KEY = "generic.armorToughness";
|
|
90
|
+
const AIR_BLOCK = { type: 0 };
|
|
91
|
+
class PredictiveFunctions {
|
|
92
|
+
constructor(bot) {
|
|
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
|
+
this.resistanceIndex = "11";
|
|
96
|
+
if (require('minecraft-data')(bot.version).isNewerOrEqualTo("1.16")) {
|
|
110
97
|
this.armorToughnessKey = "generic.armorToughness";
|
|
111
98
|
this.armorProtectionKey = "generic.armor";
|
|
112
|
-
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
113
101
|
this.armorToughnessKey = "generic.armorToughness";
|
|
114
102
|
this.armorProtectionKey = "generic.armor";
|
|
115
103
|
}
|
|
116
|
-
const effects =
|
|
104
|
+
const effects = (0, minecraft_data_1.default)(bot.version).effects;
|
|
117
105
|
for (const effectId in effects) {
|
|
118
106
|
const effect = effects[effectId];
|
|
119
107
|
if (effect.name.includes("resistance")) {
|
|
@@ -121,28 +109,25 @@ export class PredictiveFunctions {
|
|
|
121
109
|
break;
|
|
122
110
|
}
|
|
123
111
|
}
|
|
124
|
-
|
|
125
|
-
this.world = new PredictiveWorld(bot);
|
|
112
|
+
this.world = new predictiveWorld_1.PredictiveWorld(bot);
|
|
126
113
|
}
|
|
127
|
-
|
|
128
114
|
//There's a mistyping in mineflayer. Effect[] is not accurate. You cannot map over it.
|
|
129
|
-
getDamageWithEffects(damage
|
|
130
|
-
|
|
115
|
+
getDamageWithEffects(damage, effects) {
|
|
116
|
+
var _a, _b;
|
|
117
|
+
const resistanceLevel = (_b = (_a = effects === null || effects === void 0 ? void 0 : effects[this.resistanceIndex]) === null || _a === void 0 ? void 0 : _a.amplifier) !== null && _b !== void 0 ? _b : 0;
|
|
131
118
|
return damage * (1 - resistanceLevel / 5);
|
|
132
119
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
this.world.setBlocks(blocks)
|
|
120
|
+
placeBlocks(blocks) {
|
|
121
|
+
this.world.setBlocks(blocks);
|
|
136
122
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
this.world.removeBlocks(positions, force)
|
|
123
|
+
removePredictedBlocks(positions, force = false) {
|
|
124
|
+
this.world.removeBlocks(positions, force);
|
|
140
125
|
}
|
|
141
|
-
|
|
142
|
-
selfExplosionDamage(sourcePos: Vec3, power: number, rawDamages = false) {
|
|
126
|
+
selfExplosionDamage(sourcePos, power, rawDamages = false) {
|
|
143
127
|
const distance = this.bot.entity.position.distanceTo(sourcePos);
|
|
144
128
|
const radius = 2 * power;
|
|
145
|
-
if (distance >= radius)
|
|
129
|
+
if (distance >= radius)
|
|
130
|
+
return 0;
|
|
146
131
|
const exposure = calcExposure(this.bot.entity.position, sourcePos, this.world);
|
|
147
132
|
const impact = (1 - distance / radius) * exposure;
|
|
148
133
|
let damages = Math.floor((impact * impact + impact) * this.damageMultiplier * power + 1);
|
|
@@ -155,16 +140,16 @@ export class PredictiveFunctions {
|
|
|
155
140
|
damages = getDamageAfterAbsorb(damages, armor, armorToughness);
|
|
156
141
|
const equipment = armorPieces.map((piece) => this.bot.inventory.slots[this.bot.getEquipmentDestSlot(piece)]);
|
|
157
142
|
damages = getDamageWithEnchantments(damages, equipment);
|
|
158
|
-
damages = this.getDamageWithEffects(damages, this.bot.entity.effects
|
|
143
|
+
damages = this.getDamageWithEffects(damages, this.bot.entity.effects);
|
|
159
144
|
damages *= DIFFICULTY_VALUES[this.bot.game.difficulty] * 0.5;
|
|
160
145
|
}
|
|
161
146
|
return Math.floor(damages);
|
|
162
147
|
}
|
|
163
|
-
|
|
164
|
-
getExplosionDamage(targetEntity: Entity, sourcePos: Vec3, power: number, rawDamages = false) {
|
|
148
|
+
getExplosionDamage(targetEntity, sourcePos, power, rawDamages = false) {
|
|
165
149
|
const distance = targetEntity.position.distanceTo(sourcePos);
|
|
166
150
|
const radius = 2 * power;
|
|
167
|
-
if (distance >= radius)
|
|
151
|
+
if (distance >= radius)
|
|
152
|
+
return 0;
|
|
168
153
|
const exposure = calcExposure(targetEntity.position, sourcePos, this.world);
|
|
169
154
|
const impact = (1 - distance / radius) * exposure;
|
|
170
155
|
let damages = Math.floor((impact * impact + impact) * this.damageMultiplier * power + 1);
|
|
@@ -176,8 +161,7 @@ export class PredictiveFunctions {
|
|
|
176
161
|
const armorToughness = getAttributeValue(targetEntity.attributes[this.armorToughnessKey]);
|
|
177
162
|
damages = getDamageAfterAbsorb(damages, armor, armorToughness);
|
|
178
163
|
damages = getDamageWithEnchantments(damages, targetEntity.equipment);
|
|
179
|
-
damages = this.getDamageWithEffects(damages, targetEntity.effects
|
|
180
|
-
|
|
164
|
+
damages = this.getDamageWithEffects(damages, targetEntity.effects);
|
|
181
165
|
if (targetEntity.type === "player") {
|
|
182
166
|
damages *= DIFFICULTY_VALUES[this.bot.game.difficulty] * 0.5;
|
|
183
167
|
}
|
|
@@ -185,3 +169,4 @@ export class PredictiveFunctions {
|
|
|
185
169
|
return Math.floor(damages);
|
|
186
170
|
}
|
|
187
171
|
}
|
|
172
|
+
exports.PredictiveFunctions = PredictiveFunctions;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Bot, PrioGroups } from "mineflayer";
|
|
3
|
+
import { EntityFunctions } from "./entityFunctions";
|
|
4
|
+
import { FilterFunctions } from "./filterFunctions";
|
|
5
|
+
import { InventoryFunctions } from "./inventoryFunctions";
|
|
6
|
+
import { MovementFunctions } from "./movementFunctions";
|
|
7
|
+
import { PredictiveFunctions } from "./predictiveFunctions";
|
|
8
|
+
import { MathFunctions } from "./mathUtil";
|
|
9
|
+
import { CommonSense } from "./commonSense";
|
|
10
|
+
import { WorldFunctions } from "./WorldFunctions";
|
|
11
|
+
export declare type BuiltInPriorityOptions = {
|
|
12
|
+
group: PrioGroups;
|
|
13
|
+
priority: number;
|
|
14
|
+
returnIfRunning?: boolean;
|
|
15
|
+
errCancel?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare type CustomPriorityOptions = {
|
|
18
|
+
priority: number;
|
|
19
|
+
group?: PrioGroups;
|
|
20
|
+
returnIfRunning?: boolean;
|
|
21
|
+
errCancel?: boolean;
|
|
22
|
+
};
|
|
23
|
+
export declare class UtilFunctions {
|
|
24
|
+
bot: Bot;
|
|
25
|
+
inv: InventoryFunctions;
|
|
26
|
+
move: MovementFunctions;
|
|
27
|
+
entity: EntityFunctions;
|
|
28
|
+
predict: PredictiveFunctions;
|
|
29
|
+
filters: FilterFunctions;
|
|
30
|
+
math: MathFunctions;
|
|
31
|
+
commonSense: CommonSense;
|
|
32
|
+
world: WorldFunctions;
|
|
33
|
+
private builtInsPriorityStore;
|
|
34
|
+
private customPriorityStore;
|
|
35
|
+
private builtInCurrentExecuting;
|
|
36
|
+
private customCurrentExecuting;
|
|
37
|
+
constructor(bot: Bot);
|
|
38
|
+
sleep: typeof import("timers/promises").setTimeout;
|
|
39
|
+
isBuiltInsEmpty(name?: string): boolean;
|
|
40
|
+
isCustomEmpty(name?: string): boolean;
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
* @param object \{priority, errCancel} => priority of function (highest order first), throw error if already running a function.
|
|
44
|
+
* @param func any custom function.
|
|
45
|
+
* @param args the arguments of passed in function.
|
|
46
|
+
* @returns Error if errCancel and already executing, otherwise result of function.
|
|
47
|
+
*/
|
|
48
|
+
customPriority<K extends (...args: any) => any>({ priority, group, returnIfRunning, errCancel }: CustomPriorityOptions, func: K, ...args: Parameters<K>): number | Promise<ReturnType<K> | Error>;
|
|
49
|
+
builtInsPriority<K extends (...args: any) => any>({ group, priority, returnIfRunning, errCancel }: BuiltInPriorityOptions, func: K, ...args: Parameters<K>): number | Promise<ReturnType<K> | Error>;
|
|
50
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
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.UtilFunctions = void 0;
|
|
13
|
+
const entityFunctions_1 = require("./entityFunctions");
|
|
14
|
+
const filterFunctions_1 = require("./filterFunctions");
|
|
15
|
+
const inventoryFunctions_1 = require("./inventoryFunctions");
|
|
16
|
+
const movementFunctions_1 = require("./movementFunctions");
|
|
17
|
+
const util_1 = require("util");
|
|
18
|
+
const predictiveFunctions_1 = require("./predictiveFunctions");
|
|
19
|
+
const mathUtil_1 = require("./mathUtil");
|
|
20
|
+
const commonSense_1 = require("./commonSense");
|
|
21
|
+
const WorldFunctions_1 = require("./WorldFunctions");
|
|
22
|
+
class UtilFunctions {
|
|
23
|
+
constructor(bot) {
|
|
24
|
+
this.bot = bot;
|
|
25
|
+
this.sleep = (0, util_1.promisify)(setTimeout);
|
|
26
|
+
this.inv = new inventoryFunctions_1.InventoryFunctions(bot);
|
|
27
|
+
this.move = new movementFunctions_1.MovementFunctions(bot);
|
|
28
|
+
this.entity = new entityFunctions_1.EntityFunctions(bot);
|
|
29
|
+
this.predict = new predictiveFunctions_1.PredictiveFunctions(bot);
|
|
30
|
+
this.filters = new filterFunctions_1.FilterFunctions(bot);
|
|
31
|
+
this.commonSense = new commonSense_1.CommonSense(bot);
|
|
32
|
+
this.world = new WorldFunctions_1.WorldFunctions(bot);
|
|
33
|
+
this.math = new mathUtil_1.MathFunctions();
|
|
34
|
+
this.builtInsPriorityStore = {};
|
|
35
|
+
this.customPriorityStore = {};
|
|
36
|
+
this.builtInCurrentExecuting = {};
|
|
37
|
+
this.customCurrentExecuting = {};
|
|
38
|
+
}
|
|
39
|
+
isBuiltInsEmpty(name) {
|
|
40
|
+
var _a;
|
|
41
|
+
if (name) {
|
|
42
|
+
return !((_a = this.builtInsPriorityStore[name]) === null || _a === void 0 ? void 0 : _a.length) || !this.builtInCurrentExecuting[name];
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return !Object.values(this.builtInsPriorityStore).length || !Object.values(this.builtInCurrentExecuting).length;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
isCustomEmpty(name) {
|
|
49
|
+
var _a;
|
|
50
|
+
if (name) {
|
|
51
|
+
return !((_a = this.customPriorityStore[name]) === null || _a === void 0 ? void 0 : _a.length) && !this.customCurrentExecuting[name];
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return !Object.values(this.customPriorityStore).length && !Object.values(this.customCurrentExecuting).length;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* @param object \{priority, errCancel} => priority of function (highest order first), throw error if already running a function.
|
|
60
|
+
* @param func any custom function.
|
|
61
|
+
* @param args the arguments of passed in function.
|
|
62
|
+
* @returns Error if errCancel and already executing, otherwise result of function.
|
|
63
|
+
*/
|
|
64
|
+
customPriority({ priority, group, returnIfRunning, errCancel }, func, ...args) {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
var _c;
|
|
67
|
+
const name = (_a = group !== null && group !== void 0 ? group : func.name) !== null && _a !== void 0 ? _a : "anonymous";
|
|
68
|
+
const actionQueue = ((_b = (_c = this.customPriorityStore)[name]) !== null && _b !== void 0 ? _b : (_c[name] = []));
|
|
69
|
+
// console.log("custom", group ?? func.name ?? "anonymous", actionQueue, this.isCustomEmpty(name))
|
|
70
|
+
if (errCancel && actionQueue.length > 1)
|
|
71
|
+
throw "already executing";
|
|
72
|
+
if (returnIfRunning && !this.isCustomEmpty(name))
|
|
73
|
+
return 1;
|
|
74
|
+
// console.log("running.")
|
|
75
|
+
return new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
var _d, _e;
|
|
77
|
+
const currentlyExecuting = actionQueue.shift();
|
|
78
|
+
if (currentlyExecuting)
|
|
79
|
+
this.customCurrentExecuting[(_d = group !== null && group !== void 0 ? group : currentlyExecuting[1].name) !== null && _d !== void 0 ? _d : "anonymous"] = currentlyExecuting;
|
|
80
|
+
const index = actionQueue.findIndex(([prio]) => priority > prio);
|
|
81
|
+
actionQueue.splice(index === -1 ? actionQueue.length : index, 0, [
|
|
82
|
+
priority,
|
|
83
|
+
() => __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
var _f;
|
|
85
|
+
try {
|
|
86
|
+
res(yield func(...args));
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
rej(e);
|
|
90
|
+
}
|
|
91
|
+
actionQueue.shift();
|
|
92
|
+
yield ((_f = actionQueue[0]) === null || _f === void 0 ? void 0 : _f[1]());
|
|
93
|
+
}),
|
|
94
|
+
]);
|
|
95
|
+
if (currentlyExecuting) {
|
|
96
|
+
actionQueue.unshift(currentlyExecuting);
|
|
97
|
+
this.customCurrentExecuting[(_e = group !== null && group !== void 0 ? group : currentlyExecuting[1].name) !== null && _e !== void 0 ? _e : "anonymous"] = undefined;
|
|
98
|
+
}
|
|
99
|
+
else
|
|
100
|
+
yield actionQueue[0][1]();
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
builtInsPriority({ group, priority, returnIfRunning, errCancel }, func, ...args) {
|
|
104
|
+
var _a;
|
|
105
|
+
var _b;
|
|
106
|
+
const actionQueue = ((_a = (_b = this.builtInsPriorityStore)[group]) !== null && _a !== void 0 ? _a : (_b[group] = []));
|
|
107
|
+
// console.log("builtin", group, actionQueue)
|
|
108
|
+
if (errCancel && !this.isBuiltInsEmpty(group))
|
|
109
|
+
throw "already executing";
|
|
110
|
+
if (returnIfRunning && !this.isBuiltInsEmpty(group))
|
|
111
|
+
return 1;
|
|
112
|
+
return new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
const currentlyExecuting = actionQueue.shift();
|
|
114
|
+
if (currentlyExecuting)
|
|
115
|
+
this.customCurrentExecuting[group] = currentlyExecuting;
|
|
116
|
+
const index = actionQueue.findIndex(([prio]) => priority > prio);
|
|
117
|
+
actionQueue.splice(index === -1 ? actionQueue.length : index, 0, [
|
|
118
|
+
priority,
|
|
119
|
+
() => __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
var _c;
|
|
121
|
+
try {
|
|
122
|
+
res(yield func.bind(this.bot)(...args));
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
rej(e);
|
|
126
|
+
}
|
|
127
|
+
actionQueue.shift();
|
|
128
|
+
yield ((_c = actionQueue[0]) === null || _c === void 0 ? void 0 : _c[1]());
|
|
129
|
+
}),
|
|
130
|
+
]);
|
|
131
|
+
if (currentlyExecuting) {
|
|
132
|
+
actionQueue.unshift(currentlyExecuting);
|
|
133
|
+
this.builtInCurrentExecuting[group] = undefined;
|
|
134
|
+
}
|
|
135
|
+
else
|
|
136
|
+
yield actionQueue[0][1]();
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.UtilFunctions = UtilFunctions;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Bot } from "mineflayer";
|
|
2
|
+
import type { Block } from "prismarine-block";
|
|
3
|
+
import { Vec3 } from "vec3";
|
|
4
|
+
export declare type Overwrites = {
|
|
5
|
+
[coord: string]: Block | null;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* A class dedicated to predictive logic.
|
|
9
|
+
*
|
|
10
|
+
* Currently, this class can predict explosion damages of crystals using a custom world.
|
|
11
|
+
*/
|
|
12
|
+
export declare class PredictiveWorld {
|
|
13
|
+
bot: Bot;
|
|
14
|
+
private blocks;
|
|
15
|
+
constructor(bot: Bot);
|
|
16
|
+
raycast(from: Vec3, direction: Vec3, range: number, matcher?: ((block: Block) => boolean) | null): Block | null;
|
|
17
|
+
/**
|
|
18
|
+
* this works
|
|
19
|
+
* @param {Block} block
|
|
20
|
+
*/
|
|
21
|
+
setBlock(pos: Vec3, block: Block): void;
|
|
22
|
+
/**
|
|
23
|
+
* @param {Overwrites} blocks Blocks indexed by position.toString()
|
|
24
|
+
*/
|
|
25
|
+
setBlocks(blocks: Overwrites): void;
|
|
26
|
+
/**
|
|
27
|
+
* @param {Vec3} pos
|
|
28
|
+
* @returns {Block} Block at position.
|
|
29
|
+
*/
|
|
30
|
+
getBlock(pos: Vec3): Block | null;
|
|
31
|
+
removeBlock(pos: Vec3, force: boolean): void;
|
|
32
|
+
removeBlocks(positions: Vec3[], force: boolean): void;
|
|
33
|
+
/**
|
|
34
|
+
* @param playerPos Position of effected entity.
|
|
35
|
+
* @param explosionPos Position of explosion origin.
|
|
36
|
+
* @param block bot.block
|
|
37
|
+
* @returns List of affected blocks that potentially protect the entity.
|
|
38
|
+
*/
|
|
39
|
+
getExplosionAffectedBlocks(playerPos: Vec3, explosionPos: Vec3): Overwrites;
|
|
40
|
+
loadExplosionAffectedBlocks(playerPos: Vec3, explosionPos: Vec3): void;
|
|
41
|
+
}
|