@nxg-org/mineflayer-util-plugin 1.5.1 → 1.6.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/examples/example.ts +61 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +0 -3
- package/lib/movementFunctions.d.ts +0 -33
- package/lib/movementFunctions.js +0 -87
- package/lib/rayTracingFunctions.d.ts +1 -1
- package/lib/static/aabbUtil.d.ts +1 -1
- package/lib/static/mathUtil.js +1 -9
- package/package.json +4 -7
- package/lib/example.d.ts +0 -1
- package/lib/example.js +0 -96
- package/lib/types/entities.d.ts +0 -0
- package/lib/types/entities.js +0 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { createBot, EquipmentDestination } from "mineflayer";
|
|
2
|
+
import shit from "../src/index";
|
|
3
|
+
import { Vec3 } from "vec3";
|
|
4
|
+
import type { Entity } from "prismarine-entity";
|
|
5
|
+
|
|
6
|
+
let target: Entity | null;
|
|
7
|
+
|
|
8
|
+
const bot = createBot({
|
|
9
|
+
username: "utilTesting",
|
|
10
|
+
host: process.argv[2] ?? "localhost",
|
|
11
|
+
port: Number(process.argv[3]) ?? 25565,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
bot.loadPlugin(shit);
|
|
15
|
+
|
|
16
|
+
const emptyVec = new Vec3(0, 0, 0);
|
|
17
|
+
|
|
18
|
+
bot.on("chat", async (username, message) => {
|
|
19
|
+
const split = message.split(" ");
|
|
20
|
+
switch (split[0]) {
|
|
21
|
+
case "look":
|
|
22
|
+
target = bot.nearestEntity((e) => (e.username ?? e.name) === split[1]);
|
|
23
|
+
if (!target) return console.log("no entity");
|
|
24
|
+
bot.util.move.forceLookAt(target.position, true);
|
|
25
|
+
break;
|
|
26
|
+
case "equip":
|
|
27
|
+
const item = bot.util.inv.getAllItems().find((i) => i.name.includes(split[1]));
|
|
28
|
+
if (!item) return console.log("no item");
|
|
29
|
+
if (["hand", "off-hand"].includes(split[2])) {
|
|
30
|
+
bot.util.inv.customEquip(item, split[2] as EquipmentDestination);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
break;
|
|
34
|
+
case "health":
|
|
35
|
+
const health = bot.util.entity.getHealth();
|
|
36
|
+
bot.chat(`${health}`);
|
|
37
|
+
break;
|
|
38
|
+
|
|
39
|
+
case "whatAmILookingAt":
|
|
40
|
+
target = bot.nearestEntity((e) => (e.username ?? e.name) === username);
|
|
41
|
+
if (!target) return console.log("no entity");
|
|
42
|
+
const player = bot.util.raytrace.entityAtEntityCursor(target, 256);
|
|
43
|
+
if (player) {
|
|
44
|
+
console.log(player);
|
|
45
|
+
bot.chat(`${player.username ?? player.name} at ${player.position}`);
|
|
46
|
+
} else {
|
|
47
|
+
const block = bot.util.raytrace.blockAtEntityCursor(target, 256); //includes face and intersect. That's very nice.
|
|
48
|
+
if (block) {
|
|
49
|
+
console.log(block);
|
|
50
|
+
bot.chat(`${block.name} at ${block.position}`);
|
|
51
|
+
} else {
|
|
52
|
+
bot.chat("You're not looking at anything.");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
56
|
+
default:
|
|
57
|
+
console.log(username, bot.entity.username);
|
|
58
|
+
if (username !== bot.entity.username) bot.chat("unknown command: " + message);
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
});
|
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { Bot } from "mineflayer";
|
|
2
2
|
import { UtilFunctions } from "./utilFunctions";
|
|
3
|
+
import md from "minecraft-data";
|
|
3
4
|
declare module "mineflayer" {
|
|
4
|
-
type PrioGroups = "inventory" | "movement";
|
|
5
5
|
interface Bot {
|
|
6
6
|
util: UtilFunctions;
|
|
7
|
+
registry: md.IndexedData;
|
|
7
8
|
}
|
|
8
9
|
}
|
|
9
10
|
export default function inject(bot: Bot): void;
|
package/lib/index.js
CHANGED
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MathUtils = exports.AABBUtils = exports.BlockFace = exports.RaycastIterator = exports.InterceptFunctions = exports.AABB = void 0;
|
|
4
4
|
const utilFunctions_1 = require("./utilFunctions");
|
|
5
|
-
const mineflayer_pathfinder_1 = require("mineflayer-pathfinder");
|
|
6
5
|
function inject(bot) {
|
|
7
|
-
if (!bot.hasPlugin(mineflayer_pathfinder_1.pathfinder))
|
|
8
|
-
bot.loadPlugin(mineflayer_pathfinder_1.pathfinder);
|
|
9
6
|
bot.util = new utilFunctions_1.UtilFunctions(bot);
|
|
10
7
|
}
|
|
11
8
|
exports.default = inject;
|
|
@@ -1,41 +1,8 @@
|
|
|
1
1
|
import type { Bot } from "mineflayer";
|
|
2
2
|
import type { Vec3 } from "vec3";
|
|
3
|
-
import { goals, Movements } from "mineflayer-pathfinder";
|
|
4
3
|
export declare class MovementFunctions {
|
|
5
4
|
private bot;
|
|
6
|
-
goalArray: goals.GoalCompositeAll;
|
|
7
5
|
constructor(bot: Bot);
|
|
8
|
-
set movements(movements: Movements);
|
|
9
|
-
get movements(): Movements;
|
|
10
|
-
/**
|
|
11
|
-
* Fuckin' mineflayer-pathfinder still doesn't have typings.
|
|
12
|
-
* Pain in my goddamn ass.
|
|
13
|
-
* @returns have the goal changed
|
|
14
|
-
*/
|
|
15
|
-
addGoal(goal: any): boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Sets current goal and clears all others.
|
|
18
|
-
* @param goal any type of mineflayer-pathfinder goal.
|
|
19
|
-
* @returns have the goal changed
|
|
20
|
-
*/
|
|
21
|
-
setOnlyGoal(goal: any, dynamic?: boolean): boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Reset all goals inside the goal array to none.
|
|
24
|
-
* @returns have the goals changed
|
|
25
|
-
*/
|
|
26
|
-
stop(): boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Retreat from current entity.
|
|
29
|
-
* @param entity Prismarine-Entity Entity
|
|
30
|
-
* @returns have the goals changed.
|
|
31
|
-
*/
|
|
32
|
-
retreatFromEntity(entity: any, distance: number, dynamic?: boolean): boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Follow entity with a specific range. Will not approach past a certain distance either.
|
|
35
|
-
* @param entity Prismarine-Entity Entity
|
|
36
|
-
* @returns have the goals changed
|
|
37
|
-
*/
|
|
38
|
-
followEntityWithRespectRange(entity: any, followDistance: number, invertDistance?: number): boolean;
|
|
39
6
|
forceLook(yaw: number, pitch: number, update?: boolean, onGround?: boolean): void;
|
|
40
7
|
forceLookAt(pos: Vec3, update?: boolean, onGround?: boolean): void;
|
|
41
8
|
lazyTeleport(endPos: Vec3): void;
|
package/lib/movementFunctions.js
CHANGED
|
@@ -1,96 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.MovementFunctions = void 0;
|
|
7
|
-
const mineflayer_pathfinder_1 = require("mineflayer-pathfinder");
|
|
8
|
-
const minecraft_data_1 = __importDefault(require("minecraft-data"));
|
|
9
|
-
const { GoalCompositeAll, GoalInvert, GoalFollow } = mineflayer_pathfinder_1.goals;
|
|
10
4
|
class MovementFunctions {
|
|
11
5
|
constructor(bot) {
|
|
12
6
|
this.bot = bot;
|
|
13
|
-
this.goalArray = new GoalCompositeAll();
|
|
14
|
-
this.movements = new mineflayer_pathfinder_1.Movements(bot, (0, minecraft_data_1.default)(bot.version));
|
|
15
|
-
}
|
|
16
|
-
set movements(movements) {
|
|
17
|
-
this.bot.pathfinder.setMovements(movements);
|
|
18
|
-
}
|
|
19
|
-
get movements() {
|
|
20
|
-
return this.movements;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Fuckin' mineflayer-pathfinder still doesn't have typings.
|
|
24
|
-
* Pain in my goddamn ass.
|
|
25
|
-
* @returns have the goal changed
|
|
26
|
-
*/
|
|
27
|
-
addGoal(goal) {
|
|
28
|
-
if (this.goalArray.goals.find((inGoal) => inGoal === goal))
|
|
29
|
-
return false;
|
|
30
|
-
this.goalArray.push(goal);
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Sets current goal and clears all others.
|
|
35
|
-
* @param goal any type of mineflayer-pathfinder goal.
|
|
36
|
-
* @returns have the goal changed
|
|
37
|
-
*/
|
|
38
|
-
setOnlyGoal(goal, dynamic = false) {
|
|
39
|
-
const goalArr = [goal];
|
|
40
|
-
if (this.goalArray.goals === goalArr)
|
|
41
|
-
return false;
|
|
42
|
-
this.goalArray.goals = goalArr;
|
|
43
|
-
this.bot.pathfinder.setGoal(this.goalArray, dynamic);
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Reset all goals inside the goal array to none.
|
|
48
|
-
* @returns have the goals changed
|
|
49
|
-
*/
|
|
50
|
-
stop() {
|
|
51
|
-
if (this.goalArray.goals.length === 0)
|
|
52
|
-
return false;
|
|
53
|
-
this.goalArray.goals = [];
|
|
54
|
-
this.bot.pathfinder.setGoal(null);
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Retreat from current entity.
|
|
59
|
-
* @param entity Prismarine-Entity Entity
|
|
60
|
-
* @returns have the goals changed.
|
|
61
|
-
*/
|
|
62
|
-
retreatFromEntity(entity, distance, dynamic = true) {
|
|
63
|
-
const oldGoals = this.goalArray.goals.length;
|
|
64
|
-
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; });
|
|
65
|
-
if (oldGoals !== this.goalArray.goals.length || this.goalArray.goals.length === 0) {
|
|
66
|
-
this.goalArray.push(new GoalFollow(entity, distance));
|
|
67
|
-
this.goalArray.push(new GoalInvert(new GoalFollow(entity, distance - 1)));
|
|
68
|
-
this.bot.pathfinder.setGoal(this.goalArray, dynamic);
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Follow entity with a specific range. Will not approach past a certain distance either.
|
|
75
|
-
* @param entity Prismarine-Entity Entity
|
|
76
|
-
* @returns have the goals changed
|
|
77
|
-
*/
|
|
78
|
-
followEntityWithRespectRange(entity, followDistance, invertDistance) {
|
|
79
|
-
const oldGoals = this.goalArray.goals.length;
|
|
80
|
-
this.goalArray.goals = this.goalArray.goals.filter((goal) => {
|
|
81
|
-
var _a;
|
|
82
|
-
return ((_a = goal.entity) === null || _a === void 0 ? void 0 : _a.id) === entity.id && goal.rangeSq === followDistance * followDistance;
|
|
83
|
-
});
|
|
84
|
-
if (oldGoals !== this.goalArray.goals.length || !this.bot.pathfinder.isMoving() || this.goalArray.goals.length === 0) {
|
|
85
|
-
if (this.goalArray.goals.length > 0) {
|
|
86
|
-
this.goalArray.goals = [];
|
|
87
|
-
}
|
|
88
|
-
this.goalArray.push(new GoalFollow(entity, followDistance));
|
|
89
|
-
this.goalArray.push(new GoalInvert(new GoalFollow(entity, invertDistance !== null && invertDistance !== void 0 ? invertDistance : followDistance - 0.5)));
|
|
90
|
-
this.bot.pathfinder.setGoal(this.goalArray, true);
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
return false;
|
|
94
7
|
}
|
|
95
8
|
forceLook(yaw, pitch, update = false, onGround) {
|
|
96
9
|
const notchianYawAndPitch = { yaw: this.bot.util.math.toNotchianYaw(yaw), pitch: this.bot.util.math.toNotchianPitch(pitch) };
|
package/lib/static/aabbUtil.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Block } from "prismarine-block";
|
|
2
|
-
import { AABB } from "../calcs/aabb";
|
|
3
2
|
import type { Vec3 } from "vec3";
|
|
3
|
+
import { AABB } from "../calcs/aabb";
|
|
4
4
|
export declare namespace AABBUtils {
|
|
5
5
|
function getBlockAABB(block: Block, height?: number): AABB;
|
|
6
6
|
function getBlockPosAABB(block: Vec3, height?: number): AABB;
|
package/lib/static/mathUtil.js
CHANGED
|
@@ -61,15 +61,7 @@ var MathUtils;
|
|
|
61
61
|
MathUtils.getYaw = getYaw;
|
|
62
62
|
//Scuffed.
|
|
63
63
|
function yawPitchAndSpeedToDir(yaw, pitch, speed) {
|
|
64
|
-
|
|
65
|
-
const thetaP = pitch;
|
|
66
|
-
const x = speed * Math.sin(thetaY);
|
|
67
|
-
const y = speed * Math.sin(thetaP);
|
|
68
|
-
const z = speed * Math.cos(thetaY);
|
|
69
|
-
const VxMag = Math.sqrt(x * x + z * z);
|
|
70
|
-
const VxRatio = Math.sqrt(VxMag * VxMag - y * y);
|
|
71
|
-
const allRatio = VxRatio / VxMag;
|
|
72
|
-
return new vec3_1.Vec3(x * allRatio, y, z * allRatio);
|
|
64
|
+
return new vec3_1.Vec3(-Math.sin(yaw) * Math.cos(pitch), Math.sin(pitch), -Math.cos(yaw) * Math.cos(pitch)).scale(speed);
|
|
73
65
|
}
|
|
74
66
|
MathUtils.yawPitchAndSpeedToDir = yawPitchAndSpeedToDir;
|
|
75
67
|
})(MathUtils = exports.MathUtils || (exports.MathUtils = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxg-org/mineflayer-util-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "mineflayer utils for NextGEN mineflayer plugins.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mineflayer",
|
|
@@ -17,15 +17,12 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "npx tsc",
|
|
19
19
|
"prepublish": "npm run build",
|
|
20
|
-
"test": "node
|
|
21
|
-
},
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"mineflayer-pathfinder": "^2.3.3",
|
|
24
|
-
"vec3": "^0.1.7"
|
|
20
|
+
"test": "ts-node examples/example.ts"
|
|
25
21
|
},
|
|
26
22
|
"devDependencies": {
|
|
27
23
|
"@types/node": "^17.0.4",
|
|
28
24
|
"mineflayer": "^4.4.0",
|
|
29
|
-
"typescript": "^4.5.2"
|
|
25
|
+
"typescript": "^4.5.2",
|
|
26
|
+
"vec3": "^0.1.7"
|
|
30
27
|
}
|
|
31
28
|
}
|
package/lib/example.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/example.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
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
|
-
const vec3_1 = require("vec3");
|
|
19
|
-
let target;
|
|
20
|
-
const bot = (0, mineflayer_1.createBot)({
|
|
21
|
-
username: "utilTesting",
|
|
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
|
-
const emptyVec = new vec3_1.Vec3(0, 0, 0);
|
|
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 "look":
|
|
32
|
-
target = bot.nearestEntity((e) => { var _a; return ((_a = e.username) !== null && _a !== void 0 ? _a : e.name) === split[1]; });
|
|
33
|
-
if (!target)
|
|
34
|
-
return console.log("no entity");
|
|
35
|
-
bot.util.move.forceLookAt(target.position, true);
|
|
36
|
-
break;
|
|
37
|
-
case "equip":
|
|
38
|
-
const item = bot.util.inv.getAllItems().find((i) => i.name.includes(split[1]));
|
|
39
|
-
if (!item)
|
|
40
|
-
return console.log("no item");
|
|
41
|
-
if (["hand", "off-hand"].includes(split[2])) {
|
|
42
|
-
bot.util.inv.customEquip(item, split[2]);
|
|
43
|
-
}
|
|
44
|
-
break;
|
|
45
|
-
case "health":
|
|
46
|
-
const health = bot.util.entity.getHealth();
|
|
47
|
-
bot.chat(`${health}`);
|
|
48
|
-
break;
|
|
49
|
-
case "whatAmILookingAt":
|
|
50
|
-
target = bot.nearestEntity((e) => { var _a; return ((_a = e.username) !== null && _a !== void 0 ? _a : e.name) === username; });
|
|
51
|
-
if (!target)
|
|
52
|
-
return console.log("no entity");
|
|
53
|
-
const player = bot.util.raytrace.entityAtEntityCursor(target, 256);
|
|
54
|
-
if (player) {
|
|
55
|
-
console.log(player);
|
|
56
|
-
bot.chat(`${(_c = player.username) !== null && _c !== void 0 ? _c : player.name} at ${player.position}`);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
const block = bot.util.raytrace.blockAtEntityCursor(target, 256); //includes face and intersect. That's very nice.
|
|
60
|
-
if (block) {
|
|
61
|
-
console.log(block);
|
|
62
|
-
bot.chat(`${block.name} at ${block.position}`);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
bot.chat("You're not looking at anything.");
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
break;
|
|
69
|
-
case "come":
|
|
70
|
-
target = bot.nearestEntity((e) => { var _a; return ((_a = e.username) !== null && _a !== void 0 ? _a : e.name) === username; });
|
|
71
|
-
if (!target)
|
|
72
|
-
return console.log("no entity");
|
|
73
|
-
if (!bot.pathfinder)
|
|
74
|
-
bot.chat("pathfinder is not loaded!");
|
|
75
|
-
bot.util.move.followEntityWithRespectRange(target, 1);
|
|
76
|
-
break;
|
|
77
|
-
case "follow":
|
|
78
|
-
target = bot.nearestEntity((e) => { var _a; return ((_a = e.username) !== null && _a !== void 0 ? _a : e.name) === split[1]; });
|
|
79
|
-
if (!target)
|
|
80
|
-
return console.log("no entity");
|
|
81
|
-
if (!bot.pathfinder)
|
|
82
|
-
bot.chat("pathfinder is not loaded!");
|
|
83
|
-
bot.util.move.followEntityWithRespectRange(target, 1);
|
|
84
|
-
break;
|
|
85
|
-
case "stop":
|
|
86
|
-
if (!bot.pathfinder)
|
|
87
|
-
bot.chat("pathfinder is not loaded!");
|
|
88
|
-
bot.util.move.stop();
|
|
89
|
-
break;
|
|
90
|
-
default:
|
|
91
|
-
console.log(username, bot.entity.username);
|
|
92
|
-
if (username !== bot.entity.username)
|
|
93
|
-
bot.chat("unknown command: " + message);
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
}));
|
package/lib/types/entities.d.ts
DELETED
|
File without changes
|
package/lib/types/entities.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|