@nxg-org/mineflayer-physics-util 1.7.4 → 1.7.5
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/physics/engines/botcraft.js +8 -7
- package/package.json +1 -1
- package/tests/actualBot.ts +35 -27
|
@@ -479,14 +479,15 @@ class BotcraftPhysics {
|
|
|
479
479
|
// Compensate water downward speed depending on looking direction (?)
|
|
480
480
|
if (this.isSwimmingAndNotFlying(ctx, world)) {
|
|
481
481
|
const mSinPitch = player.pitch;
|
|
482
|
-
|
|
482
|
+
let condition = mSinPitch < 0.0 || player.control.jump;
|
|
483
483
|
if (!condition) {
|
|
484
484
|
// check above block
|
|
485
485
|
const bl1 = world.getBlock(new vec3_1.Vec3(player.pos.x, player.pos.y + 1.0 - 0.1, player.pos.z));
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
486
|
+
condition = bl1 != null && (this.waterId === bl1.type || this.waterLike.has(bl1.type));
|
|
487
|
+
}
|
|
488
|
+
if (condition) {
|
|
489
|
+
// console.log('changing vel by', (mSinPitch - player.vel.y) * (mSinPitch < -0.2 ? 0.085 : 0.06));
|
|
490
|
+
player.vel.y += (mSinPitch - player.vel.y) * (mSinPitch < -0.2 ? 0.085 : 0.06);
|
|
490
491
|
}
|
|
491
492
|
}
|
|
492
493
|
const velY = player.vel.y;
|
|
@@ -892,7 +893,7 @@ class BotcraftPhysics {
|
|
|
892
893
|
const inertia = player.onGround ? friction * ctx.airborneInertia : ctx.airborneInertia;
|
|
893
894
|
// deviation, adding additional logic for changing attribute values.
|
|
894
895
|
const movementSpeedAttr = this.getMovementSpeedAttribute(ctx);
|
|
895
|
-
const inputStrength = player.onGround ? movementSpeedAttr * (0.21600002 / (friction * friction * friction)) : 0.
|
|
896
|
+
const inputStrength = player.onGround ? movementSpeedAttr * (0.21600002 / (friction * friction * friction)) : (movementSpeedAttr) * 0.2;
|
|
896
897
|
this.applyInputs(inputStrength, player);
|
|
897
898
|
if (player.onClimbable) {
|
|
898
899
|
// LivingEntity::handleOnClimbable
|
|
@@ -1201,7 +1202,7 @@ class BotcraftPhysics {
|
|
|
1201
1202
|
movedAABB.translate(thisAxis == 0 ? movementLst[0] : 0, thisAxis == 1 ? movementLst[1] : 0, thisAxis == 2 ? movementLst[2] : 0);
|
|
1202
1203
|
}
|
|
1203
1204
|
applyInputs(inputStrength, player) {
|
|
1204
|
-
|
|
1205
|
+
console.log("current input strength of normal movement", inputStrength, player.onGround, player.sprinting, player.control);
|
|
1205
1206
|
const inputVector = new vec3_1.Vec3(player.heading.strafe, 0, player.heading.forward);
|
|
1206
1207
|
const sqrNorm = Math.pow(inputVector.norm(), 2);
|
|
1207
1208
|
if (sqrNorm < 1e-7) {
|
package/package.json
CHANGED
package/tests/actualBot.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { pathfinder, goals } from "mineflayer-pathfinder";
|
|
2
2
|
import { Bot, createBot } from "mineflayer";
|
|
3
|
+
const physicsInject = require("mineflayer/lib/plugins/physics")
|
|
3
4
|
import loader, { BotcraftPhysics, EntityPhysics, EntityState, EPhysicsCtx } from "../src/index";
|
|
4
5
|
import { PlayerState } from "../src/physics/states";
|
|
5
6
|
|
|
@@ -16,7 +17,9 @@ bot.once("spawn", async () => {
|
|
|
16
17
|
bot.loadPlugin(loader);
|
|
17
18
|
bot.loadPlugin(pathfinder);
|
|
18
19
|
await bot.waitForTicks(20);
|
|
19
|
-
bot.
|
|
20
|
+
(bot as any).physics.yawSpeed = 50;
|
|
21
|
+
(bot as any).physics.pitchSpeed = 50;
|
|
22
|
+
// setupNewPhysics(bot);
|
|
20
23
|
});
|
|
21
24
|
|
|
22
25
|
const rl = require("readline").createInterface({
|
|
@@ -40,7 +43,6 @@ bot.on("move", (pos) => {
|
|
|
40
43
|
// print whenever another player hits the ground
|
|
41
44
|
let lastPositions: Record<string, boolean> = {};
|
|
42
45
|
bot.on("entityMoved", (entity) => {
|
|
43
|
-
console.log("entityMove", entity.username)
|
|
44
46
|
if (entity.username && entity.username !== bot.username) {
|
|
45
47
|
// check by seeing is y value is an integer
|
|
46
48
|
if (Math.floor(entity.position.y) === entity.position.y && !lastPositions[entity.username]) {
|
|
@@ -56,11 +58,40 @@ bot.on("entityMoved", (entity) => {
|
|
|
56
58
|
}}
|
|
57
59
|
});
|
|
58
60
|
|
|
61
|
+
function setupNewPhysics(bot: Bot) {
|
|
62
|
+
const val = new BotcraftPhysics(bot.registry);
|
|
63
|
+
|
|
64
|
+
(EntityState.prototype as any).apply = function (this: EntityState, bot: Bot) {
|
|
65
|
+
// console.log(this.control, this.isUsingItem);
|
|
66
|
+
this.applyToBot(bot);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const ctx = EPhysicsCtx.FROM_BOT(val, bot);
|
|
70
|
+
const state = ctx.state as PlayerState
|
|
71
|
+
|
|
72
|
+
// EntityPhysics.prototype.simulate = function (ctx, world) {
|
|
73
|
+
// bot.physics.simulatePlayer(ctx.state, world);
|
|
74
|
+
// }
|
|
75
|
+
|
|
76
|
+
(bot.physics as any).autojumpCooldown = 0;
|
|
77
|
+
// (bot.physics).jumpTicks = 0;
|
|
78
|
+
|
|
79
|
+
(bot.physics as any).simulatePlayer = (...args: any[]) => {
|
|
80
|
+
state.update(bot);
|
|
81
|
+
ctx.state.jumpTicks = 0; // allow immediate jumping
|
|
82
|
+
return val.simulate(ctx, bot.world);
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
59
86
|
bot.on("chat", (user, message) => {
|
|
60
87
|
const [cmd, ...args] = message.split(" ");
|
|
61
88
|
const author = bot.nearestEntity((e) => e.username === user);
|
|
62
89
|
|
|
63
90
|
switch (cmd) {
|
|
91
|
+
case "lookatme":
|
|
92
|
+
if (!author) return bot.chat("I can't see you!");
|
|
93
|
+
bot.lookAt(author.position.offset(0, author.height, 0));
|
|
94
|
+
break;
|
|
64
95
|
case "status":
|
|
65
96
|
const str = `onGround: ${bot.entity.onGround}, hCol:${(bot.entity as any).isCollidedHorizontally}, vCol:${(bot.entity as any).isCollidedVertically}, inWater:${(bot.entity as any).isInWater}, inLava:${(bot.entity as any).isInLava}`;
|
|
66
97
|
bot.chat(str);
|
|
@@ -80,34 +111,11 @@ bot.on("chat", (user, message) => {
|
|
|
80
111
|
bot.setControlState(args[0] as any, args[1] === "true");
|
|
81
112
|
break;
|
|
82
113
|
case "original":
|
|
83
|
-
bot.
|
|
114
|
+
bot.loadPlugin(physicsInject);
|
|
84
115
|
bot.chat("Switched to original physics!");
|
|
85
116
|
break;
|
|
86
117
|
case "new":
|
|
87
|
-
|
|
88
|
-
const oldSim = (bot.physics as any).simulatePlayer;
|
|
89
|
-
|
|
90
|
-
(EntityState.prototype as any).apply = function (this: EntityState, bot: Bot) {
|
|
91
|
-
// console.log(this.control, this.isUsingItem);
|
|
92
|
-
this.applyToBot(bot);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const ctx = EPhysicsCtx.FROM_BOT(val, bot);
|
|
96
|
-
const state = ctx.state as PlayerState
|
|
97
|
-
|
|
98
|
-
// EntityPhysics.prototype.simulate = function (ctx, world) {
|
|
99
|
-
// bot.physics.simulatePlayer(ctx.state, world);
|
|
100
|
-
// }
|
|
101
|
-
|
|
102
|
-
(bot.physics as any).autojumpCooldown = 0;
|
|
103
|
-
// (bot.physics).jumpTicks = 0;
|
|
104
|
-
|
|
105
|
-
(bot.physics as any).simulatePlayer = (...args: any[]) => {
|
|
106
|
-
state.update(bot);
|
|
107
|
-
ctx.state.jumpTicks = 0; // allow immediate jumping
|
|
108
|
-
return val.simulate(ctx, bot.world);
|
|
109
|
-
return oldSim(...args);
|
|
110
|
-
};
|
|
118
|
+
setupNewPhysics(bot);
|
|
111
119
|
bot.chat("Switched to new physics!");
|
|
112
120
|
break;
|
|
113
121
|
case "jump":
|