@nxg-org/mineflayer-physics-util 1.6.0 → 1.7.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/dist/index.d.ts +1 -1
- package/dist/physics/info/entity_physics.json +2 -1
- package/package.json +3 -2
- package/tests/actualBot.ts +33 -0
- package/tests/fakeWorld.ts +12 -9
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ declare module "mineflayer" {
|
|
|
8
8
|
}
|
|
9
9
|
export default function loader(bot: Bot): void;
|
|
10
10
|
export declare function initSetup(data: IndexedData): void;
|
|
11
|
-
export { EPhysicsCtx, PhysicsSettings } from "./physics/settings";
|
|
11
|
+
export { EPhysicsCtx, PhysicsSettings as PhysicsSettings } from "./physics/settings";
|
|
12
12
|
export { BaseSimulator } from "./simulators";
|
|
13
13
|
export { EntityPhysics } from "./physics/engines";
|
|
14
14
|
export { EntityState } from "./physics/states";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxg-org/mineflayer-physics-util",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Provides functionality for more accurate entity and projectile tracking.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mineflayer",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"expect": "^29.5.0",
|
|
28
|
-
"
|
|
28
|
+
"minecraft-data": "^3.83.1",
|
|
29
|
+
"mineflayer": "^4.22.0",
|
|
29
30
|
"mineflayer-pathfinder": "^2.4.4",
|
|
30
31
|
"prismarine-entity": "^2.4.0",
|
|
31
32
|
"typescript": "^4.5.5"
|
package/tests/actualBot.ts
CHANGED
|
@@ -8,6 +8,7 @@ const bot: Bot = createBot({
|
|
|
8
8
|
host: process.argv[2],
|
|
9
9
|
port: Number(process.argv[3]),
|
|
10
10
|
username: "testingbot",
|
|
11
|
+
version: process.argv[4],
|
|
11
12
|
});
|
|
12
13
|
|
|
13
14
|
bot.once("spawn", async () => {
|
|
@@ -24,13 +25,44 @@ const rl = require("readline").createInterface({
|
|
|
24
25
|
|
|
25
26
|
rl.on("line", (line: any) => bot.chat(line));
|
|
26
27
|
|
|
28
|
+
// print whenever bot hits the ground
|
|
29
|
+
|
|
30
|
+
let wasOnGround = false;
|
|
31
|
+
let printNextPos = false;
|
|
32
|
+
bot.on("move", (pos) => {
|
|
33
|
+
if (bot.entity.onGround && !wasOnGround) {
|
|
34
|
+
bot.chat("Hit the ground! " + bot.entity.position.toString());
|
|
35
|
+
}
|
|
36
|
+
wasOnGround = bot.entity.onGround;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// print whenever another player hits the ground
|
|
40
|
+
let lastPositions: Record<string, boolean> = {};
|
|
41
|
+
bot.on("entityMoved", (entity) => {
|
|
42
|
+
console.log(entity.username)
|
|
43
|
+
if (entity.username && entity.username !== bot.username) {
|
|
44
|
+
// check by seeing is y value is an integer
|
|
45
|
+
if (Math.floor(entity.position.y) === entity.position.y && !lastPositions[entity.username]) {
|
|
46
|
+
bot.chat(`${entity.username} hit the ground! ${entity.position.toString()}`);
|
|
47
|
+
lastPositions[entity.username] = true;
|
|
48
|
+
} else if (Math.floor(entity.position.y) !== entity.position.y) {
|
|
49
|
+
lastPositions[entity.username] = false;
|
|
50
|
+
}}
|
|
51
|
+
});
|
|
52
|
+
|
|
27
53
|
bot.on("chat", (user, message) => {
|
|
28
54
|
const [cmd, ...args] = message.split(" ");
|
|
29
55
|
const author = bot.nearestEntity((e) => e.username === user);
|
|
30
56
|
|
|
31
57
|
switch (cmd) {
|
|
58
|
+
case "control":
|
|
59
|
+
if (args.length !== 2) return bot.chat("Invalid control command!");
|
|
60
|
+
if (args[0] === "clear") return bot.clearControlStates();
|
|
61
|
+
bot.setControlState(args[0] as any, args[1] === "true");
|
|
62
|
+
break;
|
|
32
63
|
case "original":
|
|
33
64
|
bot.physics = new Physics(bot.registry, bot.world);
|
|
65
|
+
bot.chat("Switched to original physics!");
|
|
34
66
|
break;
|
|
35
67
|
case "new":
|
|
36
68
|
const val = new EntityPhysics(bot.registry);
|
|
@@ -54,6 +86,7 @@ bot.on("chat", (user, message) => {
|
|
|
54
86
|
return val.simulate(ctx, bot.world);
|
|
55
87
|
return oldSim(...args);
|
|
56
88
|
};
|
|
89
|
+
bot.chat("Switched to new physics!");
|
|
57
90
|
break;
|
|
58
91
|
case "jump":
|
|
59
92
|
bot.setControlState("jump", true);
|
package/tests/fakeWorld.ts
CHANGED
|
@@ -12,12 +12,14 @@ import expect from "expect";
|
|
|
12
12
|
|
|
13
13
|
import { initSetup } from "../src/index";
|
|
14
14
|
|
|
15
|
-
const mcData = md("1.
|
|
16
|
-
const Block = (block as any)("1.
|
|
15
|
+
const mcData = md("1.12.2");
|
|
16
|
+
const Block = (block as any)("1.12.2");
|
|
17
|
+
|
|
18
|
+
const groundLevel = 4;
|
|
17
19
|
|
|
18
20
|
const fakeWorld = {
|
|
19
21
|
getBlock: (pos: { x: number; y: number; z: number }) => {
|
|
20
|
-
const type = pos.y <
|
|
22
|
+
const type = pos.y < groundLevel ? mcData.blocksByName.stone.id : mcData.blocksByName.air.id;
|
|
21
23
|
const b = new Block(type, 0, 0);
|
|
22
24
|
b.position = pos;
|
|
23
25
|
return b;
|
|
@@ -45,7 +47,7 @@ function createFakePlayer(pos: Vec3) {
|
|
|
45
47
|
slots: [],
|
|
46
48
|
},
|
|
47
49
|
|
|
48
|
-
setControlState: (...args) => {}
|
|
50
|
+
setControlState: (...args: any) => {}
|
|
49
51
|
};
|
|
50
52
|
}
|
|
51
53
|
|
|
@@ -55,7 +57,7 @@ initSetup(mcData);
|
|
|
55
57
|
|
|
56
58
|
//create fake bot
|
|
57
59
|
const playerType = mcData.entitiesByName["player"]; // specify type we will be simulating.
|
|
58
|
-
const fakePlayer = createFakePlayer(new Vec3(0,
|
|
60
|
+
const fakePlayer = createFakePlayer(new Vec3(0, groundLevel + 20, 0)); // call function supplied by prismarine-physics
|
|
59
61
|
fakePlayer.entity = applyMdToNewEntity(EPhysicsCtx, playerType, fakePlayer.entity); // ensure compatibility.
|
|
60
62
|
|
|
61
63
|
// create physics context.
|
|
@@ -69,6 +71,7 @@ const playerCtx = EPhysicsCtx.FROM_ENTITY_STATE(physics, playerState, playerType
|
|
|
69
71
|
playerState.control = ControlStateHandler.DEFAULT(); // specific to players and mobs, specify control scheme to apply.
|
|
70
72
|
playerState.control.forward = true;
|
|
71
73
|
|
|
74
|
+
|
|
72
75
|
// simulate until on ground.
|
|
73
76
|
while (!playerCtx.state.onGround) {
|
|
74
77
|
physics.simulate(playerCtx, fakeWorld).applyToBot(fakePlayer as any); // (applyToBot since fakePlayer is supposed to be a bot)
|
|
@@ -76,9 +79,9 @@ while (!playerCtx.state.onGround) {
|
|
|
76
79
|
}
|
|
77
80
|
|
|
78
81
|
if (playerState.control.forward) {
|
|
79
|
-
expect(fakePlayer.entity.position).toEqual(new Vec3(0,
|
|
82
|
+
expect(fakePlayer.entity.position).toEqual(new Vec3(0, groundLevel, -3.4508449226731694)); // it works.
|
|
80
83
|
} else {
|
|
81
|
-
expect(fakePlayer.entity.position).toEqual(new Vec3(0,
|
|
84
|
+
expect(fakePlayer.entity.position).toEqual(new Vec3(0, groundLevel, 0)); // it works.
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
playerCtx.state.control.set("jump", true);
|
|
@@ -88,9 +91,9 @@ for (let i = 0; i < 12; i++) {
|
|
|
88
91
|
}
|
|
89
92
|
|
|
90
93
|
if (playerState.control.forward) {
|
|
91
|
-
expect(fakePlayer.entity.position).toEqual(new Vec3(0,
|
|
94
|
+
expect(fakePlayer.entity.position).toEqual(new Vec3(0, groundLevel, -5.788782872583908)); // it works.
|
|
92
95
|
} else {
|
|
93
|
-
expect(fakePlayer.entity.position).toEqual(new Vec3(0,
|
|
96
|
+
expect(fakePlayer.entity.position).toEqual(new Vec3(0, groundLevel, 0)); // it works.
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
|