@nxg-org/mineflayer-ender 1.0.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.
- package/lib/calc/aabbUtil.d.ts +10 -0
- package/lib/calc/aabbUtil.js +21 -0
- package/lib/calc/constants.d.ts +26 -0
- package/lib/calc/constants.js +36 -0
- package/lib/calc/mathUtilts.d.ts +48 -0
- package/lib/calc/mathUtilts.js +158 -0
- package/lib/enderPlanner.d.ts +41 -0
- package/lib/enderPlanner.js +210 -0
- package/lib/enderShot.d.ts +43 -0
- package/lib/enderShot.js +108 -0
- package/lib/enderShotFactory.d.ts +9 -0
- package/lib/enderShotFactory.js +22 -0
- package/lib/example.d.ts +1 -0
- package/lib/example.js +60 -0
- package/lib/index.d.ts +18 -0
- package/lib/index.js +17 -0
- package/lib/types.d.ts +36 -0
- package/lib/types.js +13 -0
- package/package.json +38 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AABB } from "@nxg-org/mineflayer-util-plugin";
|
|
2
|
+
import type { Block } from "prismarine-block";
|
|
3
|
+
import type { Vec3 } from "vec3";
|
|
4
|
+
export declare function getEntityAABB(entity: {
|
|
5
|
+
position: Vec3;
|
|
6
|
+
height: number;
|
|
7
|
+
width?: number;
|
|
8
|
+
}): AABB;
|
|
9
|
+
export declare function getBlockAABB(block: Block, height?: number): AABB;
|
|
10
|
+
export declare function getBlockPosAABB(block: Vec3, height?: number): AABB;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBlockPosAABB = exports.getBlockAABB = exports.getEntityAABB = void 0;
|
|
4
|
+
const mineflayer_util_plugin_1 = require("@nxg-org/mineflayer-util-plugin");
|
|
5
|
+
function getEntityAABB(entity) {
|
|
6
|
+
var _a;
|
|
7
|
+
const w = (_a = entity.width) !== null && _a !== void 0 ? _a : (entity.height / 2);
|
|
8
|
+
const { x, y, z } = entity.position;
|
|
9
|
+
return new mineflayer_util_plugin_1.AABB(-w, 0, -w, w, entity.height, w).offset(x, y, z);
|
|
10
|
+
}
|
|
11
|
+
exports.getEntityAABB = getEntityAABB;
|
|
12
|
+
function getBlockAABB(block, height = 1) {
|
|
13
|
+
const { x, y, z } = block.position;
|
|
14
|
+
return new mineflayer_util_plugin_1.AABB(x, y, z, x + 1, y + height, z + 1);
|
|
15
|
+
}
|
|
16
|
+
exports.getBlockAABB = getBlockAABB;
|
|
17
|
+
function getBlockPosAABB(block, height = 1) {
|
|
18
|
+
const { x, y, z } = block.floored();
|
|
19
|
+
return new mineflayer_util_plugin_1.AABB(x, y, z, x + 1, y + height, z + 1);
|
|
20
|
+
}
|
|
21
|
+
exports.getBlockPosAABB = getBlockPosAABB;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
declare type ProjectileInfo = {
|
|
2
|
+
v0: number;
|
|
3
|
+
g: number;
|
|
4
|
+
};
|
|
5
|
+
declare type ProjectileInfos = {
|
|
6
|
+
[name: string]: ProjectileInfo;
|
|
7
|
+
};
|
|
8
|
+
declare type ProjectileGravity = {
|
|
9
|
+
[name: string]: number;
|
|
10
|
+
};
|
|
11
|
+
export declare const trajectoryInfo: ProjectileInfos;
|
|
12
|
+
export declare const projectileGravity: ProjectileGravity;
|
|
13
|
+
export declare const airResistance: {
|
|
14
|
+
y: number;
|
|
15
|
+
h: number;
|
|
16
|
+
};
|
|
17
|
+
export declare enum BlockFace {
|
|
18
|
+
UNKNOWN = -999,
|
|
19
|
+
BOTTOM = 0,
|
|
20
|
+
TOP = 1,
|
|
21
|
+
NORTH = 2,
|
|
22
|
+
SOUTH = 3,
|
|
23
|
+
WEST = 4,
|
|
24
|
+
EAST = 5
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BlockFace = exports.airResistance = exports.projectileGravity = exports.trajectoryInfo = void 0;
|
|
4
|
+
exports.trajectoryInfo = {
|
|
5
|
+
bow: { v0: 3, g: 0.05 },
|
|
6
|
+
crossbow: { v0: 3.15, g: 0.05 },
|
|
7
|
+
crossbow_firework: { v0: 1.6, g: 0.00 },
|
|
8
|
+
trident: { v0: 2.5, g: 0.05 },
|
|
9
|
+
snowball: { v0: 1.5, g: 0.04 },
|
|
10
|
+
egg: { v0: 1.5, g: 0.04 },
|
|
11
|
+
ender_pearl: { v0: 1.5, g: 0.0375 },
|
|
12
|
+
splash_potion: { v0: 0.4, g: 0.03 },
|
|
13
|
+
};
|
|
14
|
+
exports.projectileGravity = {
|
|
15
|
+
arrow: 0.05,
|
|
16
|
+
trident: 0.05,
|
|
17
|
+
egg: 0.04,
|
|
18
|
+
snowball: 0.04,
|
|
19
|
+
ender_pearl: 0.04,
|
|
20
|
+
splash_potion: 0.03,
|
|
21
|
+
firework_rocket: 0.00,
|
|
22
|
+
};
|
|
23
|
+
exports.airResistance = {
|
|
24
|
+
y: 0.01,
|
|
25
|
+
h: 0.01
|
|
26
|
+
};
|
|
27
|
+
var BlockFace;
|
|
28
|
+
(function (BlockFace) {
|
|
29
|
+
BlockFace[BlockFace["UNKNOWN"] = -999] = "UNKNOWN";
|
|
30
|
+
BlockFace[BlockFace["BOTTOM"] = 0] = "BOTTOM";
|
|
31
|
+
BlockFace[BlockFace["TOP"] = 1] = "TOP";
|
|
32
|
+
BlockFace[BlockFace["NORTH"] = 2] = "NORTH";
|
|
33
|
+
BlockFace[BlockFace["SOUTH"] = 3] = "SOUTH";
|
|
34
|
+
BlockFace[BlockFace["WEST"] = 4] = "WEST";
|
|
35
|
+
BlockFace[BlockFace["EAST"] = 5] = "EAST";
|
|
36
|
+
})(BlockFace = exports.BlockFace || (exports.BlockFace = {}));
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Vec3 } from "vec3";
|
|
2
|
+
export declare const toNotchianYaw: (yaw: number) => number;
|
|
3
|
+
export declare const toNotchianPitch: (pitch: number) => number;
|
|
4
|
+
export declare const fromNotchianYawByte: (yaw: number) => number;
|
|
5
|
+
export declare const fromNotchianPitchByte: (pitch: number) => number;
|
|
6
|
+
export declare function euclideanMod(numerator: number, denominator: number): number;
|
|
7
|
+
export declare function toRadians(degrees: number): number;
|
|
8
|
+
export declare function toDegrees(radians: number): number;
|
|
9
|
+
export declare function fromNotchianYaw(yaw: number): number;
|
|
10
|
+
export declare function fromNotchianPitch(pitch: number): number;
|
|
11
|
+
export declare function fromNotchVelocity(vel: Vec3): Vec3;
|
|
12
|
+
export declare function pointToYawAndPitch(org: Vec3, point: Vec3): {
|
|
13
|
+
yaw: number;
|
|
14
|
+
pitch: number;
|
|
15
|
+
};
|
|
16
|
+
export declare function dirToYawAndPitch(dir: Vec3): {
|
|
17
|
+
yaw: number;
|
|
18
|
+
pitch: number;
|
|
19
|
+
};
|
|
20
|
+
export declare function getTargetDistance(origin: Vec3, destination: Vec3): {
|
|
21
|
+
distance: number;
|
|
22
|
+
hDistance: number;
|
|
23
|
+
yDistance: number;
|
|
24
|
+
};
|
|
25
|
+
export declare function getTargetYaw(origin: Vec3, destination: Vec3): number;
|
|
26
|
+
export declare function getPremonition(startPosition: Vec3, targetPosition: Vec3, speed: Vec3, totalTicks: number): {
|
|
27
|
+
distances: {
|
|
28
|
+
distance: number;
|
|
29
|
+
hDistance: number;
|
|
30
|
+
yDistance: number;
|
|
31
|
+
};
|
|
32
|
+
newTarget: Vec3;
|
|
33
|
+
};
|
|
34
|
+
export declare function degreesToRadians(degrees: number): number;
|
|
35
|
+
export declare function radiansToDegrees(radians: number): number;
|
|
36
|
+
export declare function getVox(Vo: number, Alfa: number, Resistance?: number): number;
|
|
37
|
+
export declare function getVoy(Vo: number, Alfa: number, Resistance?: number): number;
|
|
38
|
+
export declare function getVo(Vox: number, Voy: number, G: number): number;
|
|
39
|
+
export declare function getGrades(Vo: number, Voy: number, Gravity: number): number;
|
|
40
|
+
export declare function vectorMagnitude(vec: Vec3): number;
|
|
41
|
+
export declare function VoToVox(vec: Vec3, mag?: number): number;
|
|
42
|
+
export declare function yawPitchAndSpeedToDir(yaw: number, pitch: number, speed: number): Vec3;
|
|
43
|
+
export declare function notchianVel(vec: Vec3, Vo?: number, Vox?: number): {
|
|
44
|
+
Vo: number;
|
|
45
|
+
Vox: number;
|
|
46
|
+
vel: Vec3;
|
|
47
|
+
};
|
|
48
|
+
export declare function applyVec3Gravity(currentVel: Vec3, gravity: Vec3): Vec3;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyVec3Gravity = exports.notchianVel = exports.yawPitchAndSpeedToDir = exports.VoToVox = exports.vectorMagnitude = exports.getGrades = exports.getVo = exports.getVoy = exports.getVox = exports.radiansToDegrees = exports.degreesToRadians = exports.getPremonition = exports.getTargetYaw = exports.getTargetDistance = exports.dirToYawAndPitch = exports.pointToYawAndPitch = exports.fromNotchVelocity = exports.fromNotchianPitch = exports.fromNotchianYaw = exports.toDegrees = exports.toRadians = exports.euclideanMod = exports.fromNotchianPitchByte = exports.fromNotchianYawByte = exports.toNotchianPitch = exports.toNotchianYaw = 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
|
+
const toNotchianYaw = (yaw) => toDegrees(PI - yaw);
|
|
13
|
+
exports.toNotchianYaw = toNotchianYaw;
|
|
14
|
+
const toNotchianPitch = (pitch) => toDegrees(-pitch);
|
|
15
|
+
exports.toNotchianPitch = toNotchianPitch;
|
|
16
|
+
const fromNotchianYawByte = (yaw) => fromNotchianYaw(yaw * FROM_NOTCH_BYTE);
|
|
17
|
+
exports.fromNotchianYawByte = fromNotchianYawByte;
|
|
18
|
+
const fromNotchianPitchByte = (pitch) => fromNotchianPitch(pitch * FROM_NOTCH_BYTE);
|
|
19
|
+
exports.fromNotchianPitchByte = fromNotchianPitchByte;
|
|
20
|
+
function euclideanMod(numerator, denominator) {
|
|
21
|
+
const result = numerator % denominator;
|
|
22
|
+
return result < 0 ? result + denominator : result;
|
|
23
|
+
}
|
|
24
|
+
exports.euclideanMod = euclideanMod;
|
|
25
|
+
function toRadians(degrees) {
|
|
26
|
+
return TO_RAD * degrees;
|
|
27
|
+
}
|
|
28
|
+
exports.toRadians = toRadians;
|
|
29
|
+
function toDegrees(radians) {
|
|
30
|
+
return TO_DEG * radians;
|
|
31
|
+
}
|
|
32
|
+
exports.toDegrees = toDegrees;
|
|
33
|
+
function fromNotchianYaw(yaw) {
|
|
34
|
+
return euclideanMod(PI - toRadians(yaw), PI_2);
|
|
35
|
+
}
|
|
36
|
+
exports.fromNotchianYaw = fromNotchianYaw;
|
|
37
|
+
function fromNotchianPitch(pitch) {
|
|
38
|
+
return euclideanMod(toRadians(-pitch) + PI, PI_2) - PI;
|
|
39
|
+
}
|
|
40
|
+
exports.fromNotchianPitch = fromNotchianPitch;
|
|
41
|
+
function fromNotchVelocity(vel) {
|
|
42
|
+
return new vec3_1.Vec3(vel.x * FROM_NOTCH_VEL, vel.y * FROM_NOTCH_VEL, vel.z * FROM_NOTCH_VEL);
|
|
43
|
+
}
|
|
44
|
+
exports.fromNotchVelocity = fromNotchVelocity;
|
|
45
|
+
function pointToYawAndPitch(org, point) {
|
|
46
|
+
const delta = point.minus(org);
|
|
47
|
+
return dirToYawAndPitch(delta);
|
|
48
|
+
}
|
|
49
|
+
exports.pointToYawAndPitch = pointToYawAndPitch;
|
|
50
|
+
function dirToYawAndPitch(dir) {
|
|
51
|
+
const yaw = Math.atan2(dir.x, dir.z) + Math.PI;
|
|
52
|
+
const groundDistance = Math.sqrt(dir.x * dir.x + dir.z * dir.z);
|
|
53
|
+
const pitch = Math.atan2(dir.y, groundDistance);
|
|
54
|
+
return { yaw: yaw, pitch: pitch };
|
|
55
|
+
}
|
|
56
|
+
exports.dirToYawAndPitch = dirToYawAndPitch;
|
|
57
|
+
function getTargetDistance(origin, destination) {
|
|
58
|
+
const xDistance = Math.pow(origin.x - destination.x, 2);
|
|
59
|
+
const zDistance = Math.pow(origin.z - destination.z, 2);
|
|
60
|
+
const hDistance = Math.sqrt(xDistance + zDistance);
|
|
61
|
+
const yDistance = destination.y - origin.y;
|
|
62
|
+
const distance = Math.sqrt(Math.pow(yDistance, 2) + xDistance + zDistance);
|
|
63
|
+
return {
|
|
64
|
+
distance,
|
|
65
|
+
hDistance,
|
|
66
|
+
yDistance,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
exports.getTargetDistance = getTargetDistance;
|
|
70
|
+
function getTargetYaw(origin, destination) {
|
|
71
|
+
const xDistance = destination.x - origin.x;
|
|
72
|
+
const zDistance = destination.z - origin.z;
|
|
73
|
+
const yaw = Math.atan2(xDistance, zDistance) + Math.PI;
|
|
74
|
+
return yaw;
|
|
75
|
+
}
|
|
76
|
+
exports.getTargetYaw = getTargetYaw;
|
|
77
|
+
function getPremonition(startPosition, targetPosition, speed, totalTicks) {
|
|
78
|
+
totalTicks = totalTicks + Math.ceil(totalTicks / 10);
|
|
79
|
+
const newTarget = targetPosition;
|
|
80
|
+
for (let i = 0; i < totalTicks; i++) {
|
|
81
|
+
newTarget.add(speed);
|
|
82
|
+
}
|
|
83
|
+
const distances = getTargetDistance(startPosition, newTarget);
|
|
84
|
+
return {
|
|
85
|
+
distances,
|
|
86
|
+
newTarget,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
exports.getPremonition = getPremonition;
|
|
90
|
+
function degreesToRadians(degrees) {
|
|
91
|
+
const pi = Math.PI;
|
|
92
|
+
return degrees * (pi / 180);
|
|
93
|
+
}
|
|
94
|
+
exports.degreesToRadians = degreesToRadians;
|
|
95
|
+
function radiansToDegrees(radians) {
|
|
96
|
+
const pi = Math.PI;
|
|
97
|
+
return radians * (180 / pi);
|
|
98
|
+
}
|
|
99
|
+
exports.radiansToDegrees = radiansToDegrees;
|
|
100
|
+
function getVox(Vo, Alfa, Resistance = 0) {
|
|
101
|
+
return Vo * Math.cos(Alfa) - Resistance;
|
|
102
|
+
}
|
|
103
|
+
exports.getVox = getVox;
|
|
104
|
+
function getVoy(Vo, Alfa, Resistance = 0) {
|
|
105
|
+
return Vo * Math.sin(Alfa) - Resistance;
|
|
106
|
+
}
|
|
107
|
+
exports.getVoy = getVoy;
|
|
108
|
+
function getVo(Vox, Voy, G) {
|
|
109
|
+
return Math.sqrt(Math.pow(Vox, 2) + Math.pow(Voy - G, 2)); // New Total Velocity - Gravity
|
|
110
|
+
}
|
|
111
|
+
exports.getVo = getVo;
|
|
112
|
+
function getGrades(Vo, Voy, Gravity) {
|
|
113
|
+
return radiansToDegrees(Math.asin((Voy - Gravity) / Vo));
|
|
114
|
+
}
|
|
115
|
+
exports.getGrades = getGrades;
|
|
116
|
+
function vectorMagnitude(vec) {
|
|
117
|
+
return Math.sqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z);
|
|
118
|
+
}
|
|
119
|
+
exports.vectorMagnitude = vectorMagnitude;
|
|
120
|
+
function VoToVox(vec, mag) {
|
|
121
|
+
return mag ? Math.sqrt(mag * mag - vec.y * vec.y) : Math.sqrt(Math.pow(vectorMagnitude(vec), 2) - vec.y * vec.y);
|
|
122
|
+
}
|
|
123
|
+
exports.VoToVox = VoToVox;
|
|
124
|
+
//Scuffed.
|
|
125
|
+
function yawPitchAndSpeedToDir(yaw, pitch, speed) {
|
|
126
|
+
const thetaY = Math.PI + yaw;
|
|
127
|
+
const thetaP = pitch;
|
|
128
|
+
const x = speed * Math.sin(thetaY);
|
|
129
|
+
const y = speed * Math.sin(thetaP);
|
|
130
|
+
const z = speed * Math.cos(thetaY);
|
|
131
|
+
const VxMag = Math.sqrt(x * x + z * z);
|
|
132
|
+
const VxRatio = Math.sqrt(VxMag * VxMag - y * y);
|
|
133
|
+
const allRatio = VxRatio / VxMag;
|
|
134
|
+
return new vec3_1.Vec3(x * allRatio, y, z * allRatio);
|
|
135
|
+
}
|
|
136
|
+
exports.yawPitchAndSpeedToDir = yawPitchAndSpeedToDir;
|
|
137
|
+
// TODO: make it not throw NaN.
|
|
138
|
+
function notchianVel(vec, Vo, Vox) {
|
|
139
|
+
if (Vo && Vox) {
|
|
140
|
+
return { Vo, Vox, vel: new vec3_1.Vec3(vec.x * (Vox / Vo), vec.y, vec.z * (Vox / Vo)) };
|
|
141
|
+
}
|
|
142
|
+
else if (Vo) {
|
|
143
|
+
const Vox = VoToVox(vec, Vo);
|
|
144
|
+
return { Vo, Vox, vel: new vec3_1.Vec3(vec.x * (Vox / Vo), vec.y, vec.z * (Vox / Vo)) };
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
// console.log(vec)
|
|
148
|
+
const Vo = vectorMagnitude(vec);
|
|
149
|
+
const Vox = VoToVox(vec);
|
|
150
|
+
// console.log(Math.pow(Vo, 2), vec.y * vec.y)
|
|
151
|
+
return { Vo, Vox, vel: new vec3_1.Vec3(vec.x * (Vox / Vo), vec.y, vec.z * (Vox / Vo)) };
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.notchianVel = notchianVel;
|
|
155
|
+
function applyVec3Gravity(currentVel, gravity) {
|
|
156
|
+
return currentVel.plus(gravity);
|
|
157
|
+
}
|
|
158
|
+
exports.applyVec3Gravity = applyVec3Gravity;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Bot } from "mineflayer";
|
|
2
|
+
import { Vec3 } from "vec3";
|
|
3
|
+
import { BasicShotInfo } from "./types";
|
|
4
|
+
import { Block } from "prismarine-block";
|
|
5
|
+
declare type CheckShotInfo = {
|
|
6
|
+
yaw: number;
|
|
7
|
+
pitch: number;
|
|
8
|
+
ticks: number;
|
|
9
|
+
shift?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare type CheckedShot = {
|
|
12
|
+
hit: boolean;
|
|
13
|
+
yaw: number;
|
|
14
|
+
pitch: number;
|
|
15
|
+
ticks: number;
|
|
16
|
+
shotInfo: BasicShotInfo | null;
|
|
17
|
+
};
|
|
18
|
+
export declare class EnderShotPlanner {
|
|
19
|
+
private bot;
|
|
20
|
+
private intercepter;
|
|
21
|
+
constructor(bot: Bot);
|
|
22
|
+
get originVel(): Vec3;
|
|
23
|
+
private isShotValid;
|
|
24
|
+
/**
|
|
25
|
+
* Better optimization. Still about 5x more expensive than hawkeye (no clue what I did) but its more accurate so whatever.
|
|
26
|
+
*
|
|
27
|
+
* Note: The increased cost comes from the increased checks made (1440 vs 100). This will be fixed.
|
|
28
|
+
*
|
|
29
|
+
* @param target
|
|
30
|
+
* @param avgSpeed
|
|
31
|
+
* @param pitch
|
|
32
|
+
* @returns {CheckedShot} the shot.
|
|
33
|
+
*/
|
|
34
|
+
shotToBlock(target: Block | Vec3, face?: number, avgSpeed?: Vec3, pitch?: number): CheckedShot | null;
|
|
35
|
+
private shiftTargetPositions;
|
|
36
|
+
checkForBlockIntercepts(target: Block | Vec3, ...shots: CheckShotInfo[]): CheckedShot;
|
|
37
|
+
getNextShot(target: Block, yaw: number, face?: number, minPitch?: number): CheckShotInfo;
|
|
38
|
+
getAlternativeYawShots(target: Block | Vec3, face?: number, ...shots: CheckShotInfo[]): CheckedShot;
|
|
39
|
+
getAllPossibleShots(target: Block | Vec3, yaw: number, face?: number): CheckShotInfo[];
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EnderShotPlanner = void 0;
|
|
4
|
+
const enderShotFactory_1 = require("./enderShotFactory");
|
|
5
|
+
const mathUtilts_1 = require("./calc/mathUtilts");
|
|
6
|
+
const vec3_1 = require("vec3");
|
|
7
|
+
const mineflayer_util_plugin_1 = require("@nxg-org/mineflayer-util-plugin");
|
|
8
|
+
const aabbUtil_1 = require("./calc/aabbUtil");
|
|
9
|
+
const emptyVec = new vec3_1.Vec3(0, 0, 0);
|
|
10
|
+
const dv = Math.PI / 2880;
|
|
11
|
+
const PIOver2 = Math.PI / 2;
|
|
12
|
+
const PIOver3 = Math.PI / 3;
|
|
13
|
+
class EnderShotPlanner {
|
|
14
|
+
constructor(bot) {
|
|
15
|
+
this.bot = bot;
|
|
16
|
+
this.intercepter = new mineflayer_util_plugin_1.InterceptFunctions(bot);
|
|
17
|
+
}
|
|
18
|
+
get originVel() {
|
|
19
|
+
return this.bot.entity.velocity;
|
|
20
|
+
}
|
|
21
|
+
isShotValid(shotInfo1, target, pitch, face) {
|
|
22
|
+
if (!(target instanceof vec3_1.Vec3)) {
|
|
23
|
+
target = target.position;
|
|
24
|
+
}
|
|
25
|
+
let shotInfo = shotInfo1.shotInfo;
|
|
26
|
+
if (!shotInfo)
|
|
27
|
+
shotInfo = shotInfo1;
|
|
28
|
+
//@ts-expect-error
|
|
29
|
+
if (shotInfo.shotInfo)
|
|
30
|
+
shotInfo = shotInfo.shotInfo;
|
|
31
|
+
if (!shotInfo)
|
|
32
|
+
return false;
|
|
33
|
+
if (shotInfo.block && pitch > PIOver3) {
|
|
34
|
+
// console.log("final check", pitch, shotInfo.landingDistance, target, shotInfo.block.position, (!face || face === shotInfo.blockFace));
|
|
35
|
+
return shotInfo.landingDistance <= 1 && shotInfo.block.position.y === target.y && (!face || face === shotInfo.blockFace);
|
|
36
|
+
}
|
|
37
|
+
else if (shotInfo.block) {
|
|
38
|
+
// console.log("final check", pitch, shotInfo.landingDistance === 0, (!face || face === shotInfo.blockFace));
|
|
39
|
+
return shotInfo.landingDistance <= 1 && shotInfo.block.position.y === target.y && (!face || face === shotInfo.blockFace);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Better optimization. Still about 5x more expensive than hawkeye (no clue what I did) but its more accurate so whatever.
|
|
47
|
+
*
|
|
48
|
+
* Note: The increased cost comes from the increased checks made (1440 vs 100). This will be fixed.
|
|
49
|
+
*
|
|
50
|
+
* @param target
|
|
51
|
+
* @param avgSpeed
|
|
52
|
+
* @param pitch
|
|
53
|
+
* @returns {CheckedShot} the shot.
|
|
54
|
+
*/
|
|
55
|
+
shotToBlock(target, face, avgSpeed = emptyVec, pitch = -PIOver2) {
|
|
56
|
+
if (target instanceof vec3_1.Vec3) {
|
|
57
|
+
const tmp = this.bot.blockAt(target);
|
|
58
|
+
if (!tmp)
|
|
59
|
+
throw "couldn't find block.";
|
|
60
|
+
target = tmp;
|
|
61
|
+
}
|
|
62
|
+
const yaw = (0, mathUtilts_1.getTargetYaw)(this.bot.entity.position, target.position);
|
|
63
|
+
while (pitch < PIOver2) {
|
|
64
|
+
const initInfo = this.getNextShot(target, yaw, face, pitch);
|
|
65
|
+
if (isNaN(initInfo.pitch)) {
|
|
66
|
+
console.log("shit...");
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
pitch = initInfo.pitch;
|
|
70
|
+
// if (avgSpeed.equals(emptyVec)) {
|
|
71
|
+
const correctShot = this.checkForBlockIntercepts(target, initInfo);
|
|
72
|
+
if (this.isShotValid(correctShot, target.position, pitch))
|
|
73
|
+
return correctShot;
|
|
74
|
+
const yawShot = this.getAlternativeYawShots(target, face, initInfo);
|
|
75
|
+
if (this.isShotValid(yawShot, target.position, pitch))
|
|
76
|
+
return yawShot;
|
|
77
|
+
// } else {
|
|
78
|
+
// const newInfo = this.shiftTargetPositions(target.position, avgSpeed,face, initInfo);
|
|
79
|
+
// for (const i of newInfo) {
|
|
80
|
+
// const correctShot = this.checkForBlockIntercepts(i.target, ...i.info);
|
|
81
|
+
// if (!correctShot.shotInfo) continue;
|
|
82
|
+
// if (this.isShotValid(correctShot, i.target, pitch)) return correctShot;
|
|
83
|
+
// const yawShot = this.getAlternativeYawShots(i.target, face,initInfo);
|
|
84
|
+
// if (this.isShotValid(yawShot, i.target, pitch)) return yawShot;
|
|
85
|
+
// }
|
|
86
|
+
// }
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
shiftTargetPositions(target, avgSpeed, face, ...shotInfo) {
|
|
91
|
+
const newInfo = shotInfo.map((i) => (i.shift ? target.clone().add(avgSpeed.clone().scale(Math.ceil(i.ticks) + 5)) : target)); //weird monkey patch.
|
|
92
|
+
const allInfo = [];
|
|
93
|
+
for (const position of newInfo) {
|
|
94
|
+
const yaw = (0, mathUtilts_1.getTargetYaw)(this.bot.entity.position, position);
|
|
95
|
+
const res = this.getAllPossibleShots(target, yaw, face);
|
|
96
|
+
const info = res.map((i) => {
|
|
97
|
+
return { yaw, pitch: i.pitch, ticks: i.ticks };
|
|
98
|
+
});
|
|
99
|
+
allInfo.push({ target: target, info });
|
|
100
|
+
}
|
|
101
|
+
return allInfo;
|
|
102
|
+
}
|
|
103
|
+
checkForBlockIntercepts(target, ...shots) {
|
|
104
|
+
if (!(target instanceof vec3_1.Vec3))
|
|
105
|
+
target = target.position;
|
|
106
|
+
for (const { pitch, ticks, yaw } of shots) {
|
|
107
|
+
const initShot = enderShotFactory_1.EnderShotFactory.fromPlayer({ position: this.bot.entity.position, yaw, pitch, velocity: this.originVel, }, this.bot, this.intercepter);
|
|
108
|
+
const shot = initShot.calcToBlock(target, true, true);
|
|
109
|
+
if (this.isShotValid(shot, target, pitch))
|
|
110
|
+
return { hit: true, yaw, pitch, ticks, shotInfo: shot };
|
|
111
|
+
}
|
|
112
|
+
return { hit: false, yaw: NaN, pitch: NaN, ticks: NaN, shotInfo: null };
|
|
113
|
+
}
|
|
114
|
+
getNextShot(target, yaw, face, minPitch = -PIOver2) {
|
|
115
|
+
let isHitting = false;
|
|
116
|
+
let initHit = false;
|
|
117
|
+
let shiftPos = true;
|
|
118
|
+
let hittingData = [];
|
|
119
|
+
for (let pitch = minPitch + dv; pitch < PIOver2; pitch += dv) {
|
|
120
|
+
const initShot = enderShotFactory_1.EnderShotFactory.fromPlayer({ position: this.bot.entity.position, yaw, pitch, velocity: this.originVel }, this.bot, this.intercepter);
|
|
121
|
+
const shot = initShot.calcToBlock(target);
|
|
122
|
+
// console.log(face, shot.blockFace, pitch.toFixed(4), shot.landingDistance)
|
|
123
|
+
// console.log(pitch.toFixed(4), shot.landingDistance, shot.totalTicks, shot.blockFace)
|
|
124
|
+
if (!this.isShotValid(shot, target, pitch)) {
|
|
125
|
+
isHitting = false;
|
|
126
|
+
if (hittingData.length !== 0) {
|
|
127
|
+
const avgPitch = hittingData.map((e) => e.pitch).reduce((a, b) => a + b) / hittingData.length; //monkeypatch to hit feet.
|
|
128
|
+
const avgTicks = hittingData.map((e) => e.ticks).reduce((a, b) => a + b) / hittingData.length;
|
|
129
|
+
return { yaw, pitch: avgPitch, ticks: Math.floor(avgTicks), shift: shiftPos };
|
|
130
|
+
}
|
|
131
|
+
else if (pitch > PIOver3 && shot.landingDistance <= 1 && (!face || face === shot.blockFace)) {
|
|
132
|
+
shiftPos = false;
|
|
133
|
+
hittingData.push({ pitch, ticks: shot.totalTicks });
|
|
134
|
+
}
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
initHit = hittingData.length === 0;
|
|
138
|
+
hittingData.push({ pitch, ticks: shot.totalTicks });
|
|
139
|
+
if (initHit)
|
|
140
|
+
isHitting = true;
|
|
141
|
+
if (isHitting)
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
return { yaw: NaN, pitch: NaN, ticks: NaN };
|
|
145
|
+
}
|
|
146
|
+
getAlternativeYawShots(target, face, ...shots) {
|
|
147
|
+
if (!(target instanceof vec3_1.Vec3))
|
|
148
|
+
target = target.position;
|
|
149
|
+
for (const { pitch, yaw: orgYaw } of shots) {
|
|
150
|
+
const yaws = (0, aabbUtil_1.getBlockPosAABB)(target)
|
|
151
|
+
.toVertices()
|
|
152
|
+
.map((p) => (0, mathUtilts_1.getTargetYaw)(this.bot.entity.position, p))
|
|
153
|
+
.sort((a, b) => orgYaw - Math.abs(a) - (orgYaw - Math.abs(b)));
|
|
154
|
+
let inbetween = [yaws.pop(), yaws.pop()];
|
|
155
|
+
inbetween = inbetween.map((y) => y + Math.sign(orgYaw - y) * 0.02);
|
|
156
|
+
for (const yaw of inbetween) {
|
|
157
|
+
const initShot = enderShotFactory_1.EnderShotFactory.fromPlayer({ position: this.bot.entity.position, yaw, pitch, velocity: this.originVel, }, this.bot, this.intercepter);
|
|
158
|
+
const shot = initShot.calcToBlock(target, true);
|
|
159
|
+
if (this.isShotValid(shot, target, pitch)) {
|
|
160
|
+
return { hit: true, yaw, pitch, ticks: shot.totalTicks, shotInfo: shot };
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return { hit: false, yaw: NaN, pitch: NaN, ticks: NaN, shotInfo: null };
|
|
165
|
+
}
|
|
166
|
+
//TODO: This is too expensive. Will aim at offset off foot instead of calc'ing all hits and averaging.
|
|
167
|
+
getAllPossibleShots(target, yaw, face) {
|
|
168
|
+
if (target instanceof vec3_1.Vec3) {
|
|
169
|
+
const tmp = this.bot.blockAt(target);
|
|
170
|
+
if (!tmp)
|
|
171
|
+
throw "couldn't find block.";
|
|
172
|
+
target = tmp;
|
|
173
|
+
}
|
|
174
|
+
let possibleShotData = [];
|
|
175
|
+
let isHitting = false;
|
|
176
|
+
let initHit = false;
|
|
177
|
+
let shiftPos = true;
|
|
178
|
+
let hittingData = [];
|
|
179
|
+
for (let pitch = -PIOver2; pitch < PIOver2; pitch += dv) {
|
|
180
|
+
const initShot = enderShotFactory_1.EnderShotFactory.fromPlayer({ position: this.bot.entity.position, yaw, pitch, velocity: this.originVel }, this.bot, this.intercepter);
|
|
181
|
+
const shot = initShot.calcToBlock(target, false);
|
|
182
|
+
if (shot.block !== target || shot.blockFace !== face) {
|
|
183
|
+
isHitting = false;
|
|
184
|
+
if (hittingData.length !== 0) {
|
|
185
|
+
const avgPitch = hittingData.map((e) => e.pitch).reduce((a, b) => a + b) / hittingData.length; //monkeypatch to hit feet.
|
|
186
|
+
const avgTicks = hittingData.map((e) => e.ticks).reduce((a, b) => a + b) / hittingData.length;
|
|
187
|
+
possibleShotData.push({ yaw, pitch: avgPitch, ticks: Math.floor(avgTicks), shift: shiftPos });
|
|
188
|
+
hittingData = [];
|
|
189
|
+
shiftPos = true;
|
|
190
|
+
}
|
|
191
|
+
else if (pitch > PIOver3 && shot.landingDistance <= 1 && (!face || face === shot.blockFace)) {
|
|
192
|
+
// console.log(pitch, shot.nearestDistance)
|
|
193
|
+
shiftPos = false;
|
|
194
|
+
hittingData.push({ pitch, ticks: shot.totalTicks });
|
|
195
|
+
// possibleShotData.push({ yaw, pitch, ticks: shot.totalTicks, shift: true });
|
|
196
|
+
}
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
initHit = hittingData.length === 0;
|
|
200
|
+
hittingData.push({ pitch, ticks: shot.totalTicks });
|
|
201
|
+
if (initHit)
|
|
202
|
+
isHitting = true;
|
|
203
|
+
if (isHitting)
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
// console.log(possibleShotData)
|
|
207
|
+
return possibleShotData;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.EnderShotPlanner = EnderShotPlanner;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Vec3 } from "vec3";
|
|
2
|
+
import type { Bot } from "mineflayer";
|
|
3
|
+
import { Block } from "prismarine-block";
|
|
4
|
+
import { InterceptFunctions } from "@nxg-org/mineflayer-util-plugin";
|
|
5
|
+
import { BasicShotInfo, ProjectileMotion } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* TODO: Change hit detection from AABB -> Ray to AABB -> Moving AABB of 0.5h, 0.5w.
|
|
8
|
+
* ! We are "missing" shots due to this miscalculation.
|
|
9
|
+
* * DONE! WOOOOOOOOOO
|
|
10
|
+
*
|
|
11
|
+
* TODO: Completely rewrite arrow trajectory calculation. Currently using assumptions, can be much better.
|
|
12
|
+
* ! It is very fast; I will have to optimize even more.
|
|
13
|
+
* * DONE! WOOOOOOOOOO
|
|
14
|
+
*
|
|
15
|
+
* TODO: Work on caching arrow trajectories. This will speed up repeated look-ups and encourage reuse of classes to save RAM/CPU.
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* uses:
|
|
20
|
+
* (a) calculate shot based off current entities yaw and target
|
|
21
|
+
* (b) calculate correct yaw and target
|
|
22
|
+
* (c) better block detection
|
|
23
|
+
* (d) velocity checks
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Purposely left off prediction.
|
|
27
|
+
* You can handle that outside of the Shot class.
|
|
28
|
+
*/
|
|
29
|
+
export declare class EnderShot {
|
|
30
|
+
readonly initialPos: Vec3;
|
|
31
|
+
readonly initialVel: Vec3;
|
|
32
|
+
readonly initialYaw: number;
|
|
33
|
+
readonly initialPitch: number;
|
|
34
|
+
readonly gravity: number;
|
|
35
|
+
private points;
|
|
36
|
+
private pointVelocities;
|
|
37
|
+
private blockHit;
|
|
38
|
+
private bot;
|
|
39
|
+
interceptCalcs: InterceptFunctions;
|
|
40
|
+
blockCheck: boolean;
|
|
41
|
+
constructor(originVel: Vec3, { position: pPos, velocity: pVel, gravity }: Required<ProjectileMotion>, bot: Bot, interceptCalcs?: InterceptFunctions);
|
|
42
|
+
calcToBlock(target: Block | Vec3, blockChecking?: boolean, log?: boolean): BasicShotInfo;
|
|
43
|
+
}
|
package/lib/enderShot.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EnderShot = void 0;
|
|
4
|
+
const vec3_1 = require("vec3");
|
|
5
|
+
const mathUtilts_1 = require("./calc/mathUtilts");
|
|
6
|
+
const constants_1 = require("./calc/constants");
|
|
7
|
+
const aabbUtil_1 = require("./calc/aabbUtil");
|
|
8
|
+
const mineflayer_util_plugin_1 = require("@nxg-org/mineflayer-util-plugin");
|
|
9
|
+
const emptyVec = new vec3_1.Vec3(0, 0, 0);
|
|
10
|
+
/**
|
|
11
|
+
* TODO: Change hit detection from AABB -> Ray to AABB -> Moving AABB of 0.5h, 0.5w.
|
|
12
|
+
* ! We are "missing" shots due to this miscalculation.
|
|
13
|
+
* * DONE! WOOOOOOOOOO
|
|
14
|
+
*
|
|
15
|
+
* TODO: Completely rewrite arrow trajectory calculation. Currently using assumptions, can be much better.
|
|
16
|
+
* ! It is very fast; I will have to optimize even more.
|
|
17
|
+
* * DONE! WOOOOOOOOOO
|
|
18
|
+
*
|
|
19
|
+
* TODO: Work on caching arrow trajectories. This will speed up repeated look-ups and encourage reuse of classes to save RAM/CPU.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* uses:
|
|
24
|
+
* (a) calculate shot based off current entities yaw and target
|
|
25
|
+
* (b) calculate correct yaw and target
|
|
26
|
+
* (c) better block detection
|
|
27
|
+
* (d) velocity checks
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* Purposely left off prediction.
|
|
31
|
+
* You can handle that outside of the Shot class.
|
|
32
|
+
*/
|
|
33
|
+
class EnderShot {
|
|
34
|
+
constructor(originVel, { position: pPos, velocity: pVel, gravity }, bot, interceptCalcs) {
|
|
35
|
+
this.blockHit = false;
|
|
36
|
+
this.blockCheck = false;
|
|
37
|
+
const { yaw, pitch } = (0, mathUtilts_1.dirToYawAndPitch)(pVel);
|
|
38
|
+
this.initialPos = pPos.clone();
|
|
39
|
+
this.initialVel = pVel.clone().add(originVel);
|
|
40
|
+
this.gravity = gravity;
|
|
41
|
+
this.initialYaw = yaw;
|
|
42
|
+
this.initialPitch = pitch;
|
|
43
|
+
this.points = [];
|
|
44
|
+
this.pointVelocities = [];
|
|
45
|
+
this.bot = bot;
|
|
46
|
+
this.interceptCalcs = interceptCalcs !== null && interceptCalcs !== void 0 ? interceptCalcs : new mineflayer_util_plugin_1.InterceptFunctions(bot);
|
|
47
|
+
}
|
|
48
|
+
calcToBlock(target, blockChecking = true, log = false) {
|
|
49
|
+
const targetPos = target instanceof vec3_1.Vec3 ? target : target.position;
|
|
50
|
+
const targetAABB = (0, aabbUtil_1.getBlockPosAABB)(targetPos);
|
|
51
|
+
let currentVelocity = this.initialVel.clone();
|
|
52
|
+
// if (log) console.log(currentVelocity)
|
|
53
|
+
let currentPosition = this.initialPos.clone();
|
|
54
|
+
let nextPosition = currentPosition.clone().add(currentVelocity);
|
|
55
|
+
let nearestDistance = targetAABB.distanceTo(this.initialPos); // initial distance.
|
|
56
|
+
let currentDistance = nearestDistance;
|
|
57
|
+
let landingDistance = 100000; //todo, make cleaner.
|
|
58
|
+
let blockInfo;
|
|
59
|
+
let closestPoint = null;
|
|
60
|
+
let blockHit = null;
|
|
61
|
+
let blockHitFace;
|
|
62
|
+
let totalTicks = 0;
|
|
63
|
+
const gravity = this.gravity; //this.gravity * airResistance.y;
|
|
64
|
+
let offsetX;
|
|
65
|
+
let offsetY;
|
|
66
|
+
let offsetZ;
|
|
67
|
+
while (totalTicks < 300) {
|
|
68
|
+
totalTicks++;
|
|
69
|
+
offsetX = -currentVelocity.x * constants_1.airResistance.h;
|
|
70
|
+
offsetY = -currentVelocity.y * constants_1.airResistance.y - gravity;
|
|
71
|
+
offsetZ = -currentVelocity.z * constants_1.airResistance.h;
|
|
72
|
+
const posDistance = targetPos.distanceTo(currentPosition);
|
|
73
|
+
if (nearestDistance > posDistance) {
|
|
74
|
+
nearestDistance = posDistance;
|
|
75
|
+
closestPoint = currentPosition.clone();
|
|
76
|
+
}
|
|
77
|
+
if (blockChecking) {
|
|
78
|
+
blockInfo = this.interceptCalcs.check(currentPosition, nextPosition);
|
|
79
|
+
if (blockInfo.block) {
|
|
80
|
+
blockHit = blockInfo.block;
|
|
81
|
+
blockHitFace = blockInfo.iterations[0].face; //todo, make cleaner.
|
|
82
|
+
landingDistance = targetPos.distanceTo(blockInfo.block.position); //todo: get block interception point.
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const intersection = targetAABB.intersectsSegment(currentPosition, nextPosition);
|
|
87
|
+
if (intersection) {
|
|
88
|
+
blockHit = this.bot.blockAt(intersection);
|
|
89
|
+
closestPoint = intersection.clone();
|
|
90
|
+
nearestDistance = 0;
|
|
91
|
+
landingDistance = 0;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
// console.log(currentPosition, nextPosition, totalTicks)
|
|
95
|
+
currentPosition.add(currentVelocity);
|
|
96
|
+
currentVelocity.translate(offsetX, offsetY, offsetZ);
|
|
97
|
+
nextPosition.add(currentVelocity);
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
landingDistance,
|
|
101
|
+
block: blockHit,
|
|
102
|
+
blockFace: blockHitFace,
|
|
103
|
+
closestPoint,
|
|
104
|
+
totalTicks
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.EnderShot = EnderShot;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { InterceptFunctions } from "@nxg-org/mineflayer-util-plugin";
|
|
2
|
+
import { Bot } from "mineflayer";
|
|
3
|
+
import { EnderShot } from "./enderShot";
|
|
4
|
+
import { ProjectileMotion, ShotEntity } from "./types";
|
|
5
|
+
export declare class EnderShotFactory {
|
|
6
|
+
static fromPlayer({ position, yaw, pitch, velocity, heldItem }: ShotEntity, bot: Bot, interceptCalcs?: InterceptFunctions): EnderShot;
|
|
7
|
+
static withoutGravity({ position, velocity }: ProjectileMotion, bot: Bot, interceptCalcs?: InterceptFunctions): EnderShot;
|
|
8
|
+
static customGravity({ position, velocity }: ProjectileMotion, gravity: number, bot: Bot, interceptCalcs?: InterceptFunctions): EnderShot;
|
|
9
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EnderShotFactory = void 0;
|
|
4
|
+
const vec3_1 = require("vec3");
|
|
5
|
+
const constants_1 = require("./calc/constants");
|
|
6
|
+
const mathUtilts_1 = require("./calc/mathUtilts");
|
|
7
|
+
const enderShot_1 = require("./enderShot");
|
|
8
|
+
const emptyVec = new vec3_1.Vec3(0, 0, 0);
|
|
9
|
+
class EnderShotFactory {
|
|
10
|
+
static fromPlayer({ position, yaw, pitch, velocity, heldItem }, bot, interceptCalcs) {
|
|
11
|
+
const info = constants_1.trajectoryInfo["ender_pearl"];
|
|
12
|
+
const projVel = (0, mathUtilts_1.yawPitchAndSpeedToDir)(yaw, pitch, info.v0);
|
|
13
|
+
return new enderShot_1.EnderShot(velocity, { position: position.offset(0, 1.62, 0), velocity: projVel, gravity: info.g }, bot, interceptCalcs);
|
|
14
|
+
}
|
|
15
|
+
static withoutGravity({ position, velocity }, bot, interceptCalcs) {
|
|
16
|
+
return new enderShot_1.EnderShot(emptyVec, { position, velocity, gravity: 0.00 }, bot, interceptCalcs);
|
|
17
|
+
}
|
|
18
|
+
static customGravity({ position, velocity }, gravity, bot, interceptCalcs) {
|
|
19
|
+
return new enderShot_1.EnderShot(emptyVec, { position, velocity, gravity }, bot, interceptCalcs);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.EnderShotFactory = EnderShotFactory;
|
package/lib/example.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/example.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
var _a, _b;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
const mineflayer_1 = require("mineflayer");
|
|
17
|
+
const index_1 = __importDefault(require("./index"));
|
|
18
|
+
let target = null;
|
|
19
|
+
let targetBlock = null;
|
|
20
|
+
const bot = (0, mineflayer_1.createBot)({
|
|
21
|
+
username: "ender-testing",
|
|
22
|
+
host: (_a = process.argv[2]) !== null && _a !== void 0 ? _a : "localhost",
|
|
23
|
+
port: (_b = Number(process.argv[3])) !== null && _b !== void 0 ? _b : 25565,
|
|
24
|
+
});
|
|
25
|
+
bot.loadPlugin(index_1.default);
|
|
26
|
+
//lazy implementation. Will automate throwing later.
|
|
27
|
+
bot.on("chat", (username, message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
var _c;
|
|
29
|
+
const split = message.split(" ");
|
|
30
|
+
switch (split[0]) {
|
|
31
|
+
case "pearl":
|
|
32
|
+
target = bot.nearestEntity((e) => { var _a; return ((_a = e.username) !== null && _a !== void 0 ? _a : e.name) === split[1]; });
|
|
33
|
+
if (!target) {
|
|
34
|
+
console.log("no entity");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
targetBlock = bot.blockAt(target.position.offset(0, -1, 0));
|
|
38
|
+
if (!targetBlock) {
|
|
39
|
+
console.log("no block under entity");
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const test = bot.ender.shotToBlock(targetBlock, 1);
|
|
43
|
+
// console.log("fuck", test)
|
|
44
|
+
if (!test || !(test === null || test === void 0 ? void 0 : test.hit))
|
|
45
|
+
return console.log("shit");
|
|
46
|
+
const item = bot.inventory.items().find(i => i.name === "ender_pearl");
|
|
47
|
+
if (!item)
|
|
48
|
+
return console.log("no ender pearl.");
|
|
49
|
+
yield bot.equip(item, "hand");
|
|
50
|
+
yield bot.look(test.yaw, test.pitch);
|
|
51
|
+
yield bot.waitForTicks(1);
|
|
52
|
+
console.log(test.yaw, test.pitch, (_c = test.shotInfo) === null || _c === void 0 ? void 0 : _c.landingDistance);
|
|
53
|
+
bot.swingArm(undefined);
|
|
54
|
+
bot.activateItem();
|
|
55
|
+
bot.deactivateItem();
|
|
56
|
+
break;
|
|
57
|
+
default:
|
|
58
|
+
console.log("hi");
|
|
59
|
+
}
|
|
60
|
+
}));
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { EnderShotFactory } from "./enderShotFactory";
|
|
2
|
+
import { Bot } from "mineflayer";
|
|
3
|
+
import { Entity } from "prismarine-entity";
|
|
4
|
+
import { EnderShotPlanner } from "./enderPlanner";
|
|
5
|
+
declare module "mineflayer" {
|
|
6
|
+
interface Bot {
|
|
7
|
+
ender: EnderShotPlanner;
|
|
8
|
+
}
|
|
9
|
+
interface BotEvents {
|
|
10
|
+
attackedTarget: (target: Entity) => void;
|
|
11
|
+
stoppedAttacking: () => void;
|
|
12
|
+
startedAttacking: (target: Entity) => void;
|
|
13
|
+
targetBlockingUpdate: (target: Entity, blocking: boolean) => void;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export default function plugin(bot: Bot): void;
|
|
17
|
+
export { EnderShotFactory };
|
|
18
|
+
export { EnderShotPlanner };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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.EnderShotPlanner = exports.EnderShotFactory = void 0;
|
|
7
|
+
const enderShotFactory_1 = require("./enderShotFactory");
|
|
8
|
+
Object.defineProperty(exports, "EnderShotFactory", { enumerable: true, get: function () { return enderShotFactory_1.EnderShotFactory; } });
|
|
9
|
+
const mineflayer_util_plugin_1 = __importDefault(require("@nxg-org/mineflayer-util-plugin"));
|
|
10
|
+
const enderPlanner_1 = require("./enderPlanner");
|
|
11
|
+
Object.defineProperty(exports, "EnderShotPlanner", { enumerable: true, get: function () { return enderPlanner_1.EnderShotPlanner; } });
|
|
12
|
+
function plugin(bot) {
|
|
13
|
+
if (!bot.util)
|
|
14
|
+
bot.loadPlugin(mineflayer_util_plugin_1.default);
|
|
15
|
+
bot.ender = new enderPlanner_1.EnderShotPlanner(bot);
|
|
16
|
+
}
|
|
17
|
+
exports.default = plugin;
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Block } from "prismarine-block";
|
|
2
|
+
import type { Item } from "prismarine-item";
|
|
3
|
+
import type { Vec3 } from "vec3";
|
|
4
|
+
export declare type ShotEntity = {
|
|
5
|
+
position: Vec3;
|
|
6
|
+
velocity: Vec3;
|
|
7
|
+
yaw?: number;
|
|
8
|
+
pitch?: number;
|
|
9
|
+
heldItem?: Item | null;
|
|
10
|
+
};
|
|
11
|
+
export declare type AABBComponents = {
|
|
12
|
+
position: Vec3;
|
|
13
|
+
height: number;
|
|
14
|
+
width?: number;
|
|
15
|
+
};
|
|
16
|
+
export declare type ProjectileMotion = {
|
|
17
|
+
position: Vec3;
|
|
18
|
+
velocity: Vec3;
|
|
19
|
+
gravity?: number;
|
|
20
|
+
};
|
|
21
|
+
export declare type BasicShotInfo = {
|
|
22
|
+
landingDistance: number;
|
|
23
|
+
block: Block | null;
|
|
24
|
+
blockFace?: BlockFace;
|
|
25
|
+
closestPoint: Vec3 | null;
|
|
26
|
+
totalTicks: number;
|
|
27
|
+
};
|
|
28
|
+
export declare enum BlockFace {
|
|
29
|
+
UNKNOWN = -999,
|
|
30
|
+
BOTTOM = 0,
|
|
31
|
+
TOP = 1,
|
|
32
|
+
NORTH = 2,
|
|
33
|
+
SOUTH = 3,
|
|
34
|
+
WEST = 4,
|
|
35
|
+
EAST = 5
|
|
36
|
+
}
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BlockFace = void 0;
|
|
4
|
+
var BlockFace;
|
|
5
|
+
(function (BlockFace) {
|
|
6
|
+
BlockFace[BlockFace["UNKNOWN"] = -999] = "UNKNOWN";
|
|
7
|
+
BlockFace[BlockFace["BOTTOM"] = 0] = "BOTTOM";
|
|
8
|
+
BlockFace[BlockFace["TOP"] = 1] = "TOP";
|
|
9
|
+
BlockFace[BlockFace["NORTH"] = 2] = "NORTH";
|
|
10
|
+
BlockFace[BlockFace["SOUTH"] = 3] = "SOUTH";
|
|
11
|
+
BlockFace[BlockFace["WEST"] = 4] = "WEST";
|
|
12
|
+
BlockFace[BlockFace["EAST"] = 5] = "EAST";
|
|
13
|
+
})(BlockFace = exports.BlockFace || (exports.BlockFace = {}));
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nxg-org/mineflayer-ender",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "A plugin dedicated to bots being like endermen.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"mineflayer",
|
|
7
|
+
"mineflayer-util",
|
|
8
|
+
"mineflayer-plugin",
|
|
9
|
+
"mineflayer-ender"
|
|
10
|
+
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/nxg-org/mineflayer-ender.git"
|
|
14
|
+
},
|
|
15
|
+
"license": "GPL-3.0",
|
|
16
|
+
"author": "generel_schwerz",
|
|
17
|
+
"main": "lib/index.js",
|
|
18
|
+
"types": "lib/index.d.ts",
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "npx tsc",
|
|
21
|
+
"prepublish": "npm run build",
|
|
22
|
+
"test": "node --trace-warnings lib/example.js"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@nxg-org/mineflayer-trajectories": "^1.0.4",
|
|
26
|
+
"@nxg-org/mineflayer-util-plugin": "^1.3.8",
|
|
27
|
+
"minecraft-data": "^2.97.0",
|
|
28
|
+
"mineflayer": "^3.11.2",
|
|
29
|
+
"mineflayer-pathfinder": "^1.8.0",
|
|
30
|
+
"prismarine-block": "^1.10.3",
|
|
31
|
+
"prismarine-item": "^1.11.1",
|
|
32
|
+
"vec3": "^0.1.7"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^16.11.11",
|
|
36
|
+
"typescript": "^4.5.2"
|
|
37
|
+
}
|
|
38
|
+
}
|