@nxg-org/mineflayer-physics-util 1.8.14 → 1.8.15
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/.vscode/settings.json +4 -4
- package/README.md +1 -1
- package/dist/physics/engines/botcraft.js +21 -7
- package/dist/physics/states/playerState.js +1 -1
- package/eslint.config.mjs +17 -17
- package/package.json +46 -46
- package/tests/actualBot.ts +198 -198
- package/tests/fakeWorld.test.ts +354 -354
- package/tests/predictBot.ts +73 -73
- package/tests/util/testUtils.ts +67 -67
package/tests/predictBot.ts
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import { createBot } from "mineflayer";
|
|
2
|
-
import { Vec3 } from "vec3";
|
|
3
|
-
import loader, { EntityPhysics, EPhysicsCtx } from "../src/index";
|
|
4
|
-
import { SimulationTypes } from "../src/wrapper";
|
|
5
|
-
import { Entity } from "prismarine-entity";
|
|
6
|
-
|
|
7
|
-
const bot = createBot({
|
|
8
|
-
username: "shot-testing",
|
|
9
|
-
host: process.argv[2] ?? "localhost",
|
|
10
|
-
port: Number(process.argv[3]) ?? 25565,
|
|
11
|
-
version: process.argv[4],
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
bot.loadPlugin(loader);
|
|
15
|
-
|
|
16
|
-
const checkedEntities: Record<number, Vec3[]> = {};
|
|
17
|
-
const emptyVec = new Vec3(0, 0, 0);
|
|
18
|
-
|
|
19
|
-
// this code shows the trajectory of a projectile and whether it may hit people.
|
|
20
|
-
|
|
21
|
-
const lastPrintedEntities: Record<number, number> = {};
|
|
22
|
-
async function showSim(entity: Entity) {
|
|
23
|
-
if (lastPrintedEntities[entity.id] - performance.now() < 3000) return;
|
|
24
|
-
lastPrintedEntities[entity.id] = performance.now();
|
|
25
|
-
checkedEntities[entity.id] = [];
|
|
26
|
-
|
|
27
|
-
const physics = new EntityPhysics(bot.registry);
|
|
28
|
-
const ectx = EPhysicsCtx.FROM_ENTITY(physics, entity);
|
|
29
|
-
|
|
30
|
-
for (let i = 0; i < 300; i++) {
|
|
31
|
-
let state = ectx.state;
|
|
32
|
-
state = physics.simulate(ectx, bot.world);
|
|
33
|
-
|
|
34
|
-
if (state.onGround) {
|
|
35
|
-
console.log("Hit ground at", state.pos);
|
|
36
|
-
checkedEntities[entity.id].push(state.pos.clone());
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// bot.chat(`/particle flame ${x} ${y} ${z} 0 0 0 0 1 force`);
|
|
41
|
-
checkedEntities[entity.id].push(state.pos.clone());
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
for (let i = 0; i < 5; i++) {
|
|
45
|
-
let j = 0;
|
|
46
|
-
for (const pos of checkedEntities[entity.id]) {
|
|
47
|
-
j++;
|
|
48
|
-
if (j === checkedEntities[entity.id].length) bot.chat(`/particle heart ${pos.x} ${pos.y} ${pos.z} 0 0 0 0 1 force`);
|
|
49
|
-
bot.chat(`/particle flame ${pos.x} ${pos.y} ${pos.z} 0 0 0 0 1 force`);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
await bot.waitForTicks(20);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
delete checkedEntities[entity.id];
|
|
56
|
-
delete lastPrintedEntities[entity.id];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
bot.on("entityMoved", async (ent) => {
|
|
60
|
-
const physics = new EntityPhysics(bot.registry);
|
|
61
|
-
|
|
62
|
-
if (ent.velocity.equals(emptyVec)) return;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (ent.type === "projectile") {
|
|
67
|
-
console.log(ent.velocity, ent.name);
|
|
68
|
-
showSim(ent as Entity);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// console.log(ent)
|
|
73
|
-
});
|
|
1
|
+
import { createBot } from "mineflayer";
|
|
2
|
+
import { Vec3 } from "vec3";
|
|
3
|
+
import loader, { EntityPhysics, EPhysicsCtx } from "../src/index";
|
|
4
|
+
import { SimulationTypes } from "../src/wrapper";
|
|
5
|
+
import { Entity } from "prismarine-entity";
|
|
6
|
+
|
|
7
|
+
const bot = createBot({
|
|
8
|
+
username: "shot-testing",
|
|
9
|
+
host: process.argv[2] ?? "localhost",
|
|
10
|
+
port: Number(process.argv[3]) ?? 25565,
|
|
11
|
+
version: process.argv[4],
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
bot.loadPlugin(loader);
|
|
15
|
+
|
|
16
|
+
const checkedEntities: Record<number, Vec3[]> = {};
|
|
17
|
+
const emptyVec = new Vec3(0, 0, 0);
|
|
18
|
+
|
|
19
|
+
// this code shows the trajectory of a projectile and whether it may hit people.
|
|
20
|
+
|
|
21
|
+
const lastPrintedEntities: Record<number, number> = {};
|
|
22
|
+
async function showSim(entity: Entity) {
|
|
23
|
+
if (lastPrintedEntities[entity.id] - performance.now() < 3000) return;
|
|
24
|
+
lastPrintedEntities[entity.id] = performance.now();
|
|
25
|
+
checkedEntities[entity.id] = [];
|
|
26
|
+
|
|
27
|
+
const physics = new EntityPhysics(bot.registry);
|
|
28
|
+
const ectx = EPhysicsCtx.FROM_ENTITY(physics, entity);
|
|
29
|
+
|
|
30
|
+
for (let i = 0; i < 300; i++) {
|
|
31
|
+
let state = ectx.state;
|
|
32
|
+
state = physics.simulate(ectx, bot.world);
|
|
33
|
+
|
|
34
|
+
if (state.onGround) {
|
|
35
|
+
console.log("Hit ground at", state.pos);
|
|
36
|
+
checkedEntities[entity.id].push(state.pos.clone());
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// bot.chat(`/particle flame ${x} ${y} ${z} 0 0 0 0 1 force`);
|
|
41
|
+
checkedEntities[entity.id].push(state.pos.clone());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
for (let i = 0; i < 5; i++) {
|
|
45
|
+
let j = 0;
|
|
46
|
+
for (const pos of checkedEntities[entity.id]) {
|
|
47
|
+
j++;
|
|
48
|
+
if (j === checkedEntities[entity.id].length) bot.chat(`/particle heart ${pos.x} ${pos.y} ${pos.z} 0 0 0 0 1 force`);
|
|
49
|
+
bot.chat(`/particle flame ${pos.x} ${pos.y} ${pos.z} 0 0 0 0 1 force`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
await bot.waitForTicks(20);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
delete checkedEntities[entity.id];
|
|
56
|
+
delete lastPrintedEntities[entity.id];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
bot.on("entityMoved", async (ent) => {
|
|
60
|
+
const physics = new EntityPhysics(bot.registry);
|
|
61
|
+
|
|
62
|
+
if (ent.velocity.equals(emptyVec)) return;
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
if (ent.type === "projectile") {
|
|
67
|
+
console.log(ent.velocity, ent.name);
|
|
68
|
+
showSim(ent as Entity);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
// console.log(ent)
|
|
73
|
+
});
|
package/tests/util/testUtils.ts
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
import { Effect } from "mineflayer";
|
|
2
|
-
import { Entity } from "prismarine-entity";
|
|
3
|
-
import { Vec3 } from "vec3";
|
|
4
|
-
import md from "minecraft-data";
|
|
5
|
-
import block from "prismarine-block";
|
|
6
|
-
import entity from "prismarine-entity"
|
|
7
|
-
|
|
8
|
-
export default function load(version: string) {
|
|
9
|
-
|
|
10
|
-
const mcData = md(version);
|
|
11
|
-
const Block = (block as any)(version);
|
|
12
|
-
const Entity = (entity as any)(version)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const fakeWorld = {
|
|
16
|
-
getBlock: (pos: { x: number; y: number; z: number }) => {
|
|
17
|
-
const type = pos.y < 60 ? mcData.blocksByName.stone.id : mcData.blocksByName.air.id;
|
|
18
|
-
const b = new Block(type, 0, 0);
|
|
19
|
-
b.position = pos;
|
|
20
|
-
return b;
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const createFakeEntity = (name: string, pos: Vec3) => {
|
|
25
|
-
if (!mcData.entitiesByName[name!]) throw "invalid name"
|
|
26
|
-
const tmp = mcData.entitiesByName[name!]
|
|
27
|
-
return {
|
|
28
|
-
name: name,
|
|
29
|
-
type: tmp.type,
|
|
30
|
-
height: tmp.height,
|
|
31
|
-
width: tmp.width,
|
|
32
|
-
position: pos,
|
|
33
|
-
velocity: new Vec3(0, 0, 0),
|
|
34
|
-
onGround: false,
|
|
35
|
-
isInWater: false,
|
|
36
|
-
isInLava: false,
|
|
37
|
-
isInWeb: false,
|
|
38
|
-
isCollidedHorizontally: false,
|
|
39
|
-
isCollidedVertically: false,
|
|
40
|
-
yaw: 0,
|
|
41
|
-
effects: {} as Effect[],
|
|
42
|
-
metadata: [],
|
|
43
|
-
equipment: new Array(6)
|
|
44
|
-
} as unknown as Entity
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const modifyEntity = (name: string, entity: Entity) => {
|
|
48
|
-
if (!mcData.entitiesByName[name!]) throw "invalid name"
|
|
49
|
-
const tmp = mcData.entitiesByName[name!]
|
|
50
|
-
entity.height = tmp.height ?? 0
|
|
51
|
-
entity.width = tmp.width ?? 0
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const createFakePlayer = (pos: Vec3) => {
|
|
55
|
-
return {
|
|
56
|
-
entity: createFakeEntity("player", pos),
|
|
57
|
-
jumpTicks: 0,
|
|
58
|
-
jumpQueued: false,
|
|
59
|
-
version: "1.17.1",
|
|
60
|
-
inventory: {
|
|
61
|
-
slots: [],
|
|
62
|
-
},
|
|
63
|
-
world: fakeWorld
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return { mcData, Block, Entity, fakeWorld, createFakePlayer, createFakeEntity, modifyEntity };
|
|
1
|
+
import { Effect } from "mineflayer";
|
|
2
|
+
import { Entity } from "prismarine-entity";
|
|
3
|
+
import { Vec3 } from "vec3";
|
|
4
|
+
import md from "minecraft-data";
|
|
5
|
+
import block from "prismarine-block";
|
|
6
|
+
import entity from "prismarine-entity"
|
|
7
|
+
|
|
8
|
+
export default function load(version: string) {
|
|
9
|
+
|
|
10
|
+
const mcData = md(version);
|
|
11
|
+
const Block = (block as any)(version);
|
|
12
|
+
const Entity = (entity as any)(version)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const fakeWorld = {
|
|
16
|
+
getBlock: (pos: { x: number; y: number; z: number }) => {
|
|
17
|
+
const type = pos.y < 60 ? mcData.blocksByName.stone.id : mcData.blocksByName.air.id;
|
|
18
|
+
const b = new Block(type, 0, 0);
|
|
19
|
+
b.position = pos;
|
|
20
|
+
return b;
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const createFakeEntity = (name: string, pos: Vec3) => {
|
|
25
|
+
if (!mcData.entitiesByName[name!]) throw "invalid name"
|
|
26
|
+
const tmp = mcData.entitiesByName[name!]
|
|
27
|
+
return {
|
|
28
|
+
name: name,
|
|
29
|
+
type: tmp.type,
|
|
30
|
+
height: tmp.height,
|
|
31
|
+
width: tmp.width,
|
|
32
|
+
position: pos,
|
|
33
|
+
velocity: new Vec3(0, 0, 0),
|
|
34
|
+
onGround: false,
|
|
35
|
+
isInWater: false,
|
|
36
|
+
isInLava: false,
|
|
37
|
+
isInWeb: false,
|
|
38
|
+
isCollidedHorizontally: false,
|
|
39
|
+
isCollidedVertically: false,
|
|
40
|
+
yaw: 0,
|
|
41
|
+
effects: {} as Effect[],
|
|
42
|
+
metadata: [],
|
|
43
|
+
equipment: new Array(6)
|
|
44
|
+
} as unknown as Entity
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const modifyEntity = (name: string, entity: Entity) => {
|
|
48
|
+
if (!mcData.entitiesByName[name!]) throw "invalid name"
|
|
49
|
+
const tmp = mcData.entitiesByName[name!]
|
|
50
|
+
entity.height = tmp.height ?? 0
|
|
51
|
+
entity.width = tmp.width ?? 0
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const createFakePlayer = (pos: Vec3) => {
|
|
55
|
+
return {
|
|
56
|
+
entity: createFakeEntity("player", pos),
|
|
57
|
+
jumpTicks: 0,
|
|
58
|
+
jumpQueued: false,
|
|
59
|
+
version: "1.17.1",
|
|
60
|
+
inventory: {
|
|
61
|
+
slots: [],
|
|
62
|
+
},
|
|
63
|
+
world: fakeWorld
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return { mcData, Block, Entity, fakeWorld, createFakePlayer, createFakeEntity, modifyEntity };
|
|
68
68
|
}
|