@nxg-org/mineflayer-physics-util 1.7.10 → 1.7.12
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 +21 -12
- package/package.json +1 -1
- package/tests/fakeWorld.test.ts +53 -3
|
@@ -673,6 +673,7 @@ class BotcraftPhysics {
|
|
|
673
673
|
}
|
|
674
674
|
inputsToJump(entity, world, worldSettings) {
|
|
675
675
|
// TODO: implement non-player entity jumping.
|
|
676
|
+
var _a, _b;
|
|
676
677
|
if (entity instanceof states_1.PlayerState) {
|
|
677
678
|
const player = entity;
|
|
678
679
|
if (player.control.jump && !player.flying) {
|
|
@@ -706,7 +707,8 @@ class BotcraftPhysics {
|
|
|
706
707
|
}
|
|
707
708
|
else {
|
|
708
709
|
// something about getting an attribute for jump strength?
|
|
709
|
-
const
|
|
710
|
+
const value = (_b = (_a = entity.attributes[this.jumpStrengthAttribute]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 1; // random value as default
|
|
711
|
+
const jumpPower = value * blockJumpFactor + jumpBoost;
|
|
710
712
|
if (jumpPower > 1e-5) {
|
|
711
713
|
player.vel.y = jumpPower;
|
|
712
714
|
if (player.sprinting) {
|
|
@@ -771,7 +773,7 @@ class BotcraftPhysics {
|
|
|
771
773
|
* @param world
|
|
772
774
|
*/
|
|
773
775
|
movePlayer(ctx, world) {
|
|
774
|
-
var _a;
|
|
776
|
+
var _a, _b, _c;
|
|
775
777
|
const player = ctx.state;
|
|
776
778
|
{
|
|
777
779
|
// LivingEntity::travel
|
|
@@ -795,11 +797,11 @@ class BotcraftPhysics {
|
|
|
795
797
|
depthStriderMult = Math.min(depthStrider, 3) / 3;
|
|
796
798
|
}
|
|
797
799
|
else {
|
|
798
|
-
depthStriderMult = player.attributes[this.waterMovementEfficiencyAttribute].value;
|
|
800
|
+
depthStriderMult = (_b = (_a = player.attributes[this.waterMovementEfficiencyAttribute]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0; // random value as default
|
|
799
801
|
}
|
|
800
802
|
if (!player.onGround) {
|
|
801
803
|
waterSlowDown += (0.54600006 - waterSlowDown) * depthStriderMult; // magic number
|
|
802
|
-
const movementSpeed =
|
|
804
|
+
const movementSpeed = this.getMovementSpeedAttribute(ctx); // slight deviation, using utility method
|
|
803
805
|
inputStrength += Math.fround(movementSpeed - inputStrength) * depthStriderMult;
|
|
804
806
|
}
|
|
805
807
|
if (this.verGreaterThan("1.12.2")) {
|
|
@@ -887,7 +889,7 @@ class BotcraftPhysics {
|
|
|
887
889
|
const blockBelow = world.getBlock(this.getBlockBelowAffectingMovement(player, world));
|
|
888
890
|
// deviation. using our stores slipperiness values.
|
|
889
891
|
const friction = blockBelow
|
|
890
|
-
? (
|
|
892
|
+
? (_c = this.blockSlipperiness[blockBelow.type]) !== null && _c !== void 0 ? _c : ctx.worldSettings.defaultSlipperiness
|
|
891
893
|
: ctx.worldSettings.defaultSlipperiness;
|
|
892
894
|
const inertia = player.onGround ? friction * ctx.airborneInertia : ctx.airborneInertia;
|
|
893
895
|
// deviation, adding additional logic for changing attribute values.
|
|
@@ -936,11 +938,13 @@ class BotcraftPhysics {
|
|
|
936
938
|
}
|
|
937
939
|
}
|
|
938
940
|
applyMovement(ctx, world) {
|
|
941
|
+
var _a, _b, _c, _d;
|
|
939
942
|
const player = ctx.state;
|
|
940
943
|
if (player.gameMode === "spectator") {
|
|
941
944
|
player.pos.translate(player.vel.x, player.vel.y, player.vel.z);
|
|
942
945
|
return;
|
|
943
946
|
}
|
|
947
|
+
// console.log('wtf vel?', player.vel)
|
|
944
948
|
// this might be a clone.
|
|
945
949
|
let movement = player.vel.clone();
|
|
946
950
|
// if a player is stuck, reset stuck multiplier and set velocity to 0.
|
|
@@ -953,7 +957,7 @@ class BotcraftPhysics {
|
|
|
953
957
|
}
|
|
954
958
|
let maxUpStep = ctx.stepHeight;
|
|
955
959
|
if (!this.verLessThan("1.20.5")) {
|
|
956
|
-
maxUpStep = player.attributes[this.stepHeightAttribute].value;
|
|
960
|
+
maxUpStep = (_b = (_a = player.attributes[this.stepHeightAttribute]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : ctx.stepHeight;
|
|
957
961
|
}
|
|
958
962
|
// const playerAABB = player.getBB();
|
|
959
963
|
if (!player.flying && movement.y <= 0.0 && player.control.sneak && player.onGround) {
|
|
@@ -977,8 +981,10 @@ class BotcraftPhysics {
|
|
|
977
981
|
}
|
|
978
982
|
}
|
|
979
983
|
const movementBeforeCollisions = movement.clone();
|
|
984
|
+
// console.log('movement', movement.x, movement.y, movement.z)
|
|
980
985
|
{ // Entity::collide
|
|
981
986
|
const playerAABB = player.getBB();
|
|
987
|
+
const fuck = playerAABB.clone();
|
|
982
988
|
const hDist = (vec) => Math.sqrt(vec.x * vec.x + vec.z * vec.z);
|
|
983
989
|
// const entityCollisions = world.getEntityCollisions(player, playerAABB.expand(movement));
|
|
984
990
|
let newMovement = Math.pow(movement.norm(), 2) === 0 ? movement : this.collideBoundingBox(world, playerAABB, movement);
|
|
@@ -988,7 +994,8 @@ class BotcraftPhysics {
|
|
|
988
994
|
const onGround = player.onGround || (collisionY && movement.y < 0);
|
|
989
995
|
if (maxUpStep > 0 && onGround && (collisionX || collisionZ)) {
|
|
990
996
|
let stepUpMovement = this.collideBoundingBox(world, playerAABB, new vec3_1.Vec3(movement.x, maxUpStep, movement.z));
|
|
991
|
-
const
|
|
997
|
+
const expand = playerAABB.expandTowardsCoords(movement.x, 0, movement.z);
|
|
998
|
+
const stepOnlyMovement = this.collideBoundingBox(world, expand, new vec3_1.Vec3(0, maxUpStep, 0));
|
|
992
999
|
if (stepOnlyMovement.y < maxUpStep) {
|
|
993
1000
|
const adjustedStepUp = this.collideBoundingBox(world, playerAABB.translateVec(stepOnlyMovement), new vec3_1.Vec3(movement.x, 0, movement.z)).add(stepOnlyMovement);
|
|
994
1001
|
if (hDist(adjustedStepUp) > hDist(stepUpMovement)) {
|
|
@@ -1001,6 +1008,7 @@ class BotcraftPhysics {
|
|
|
1001
1008
|
}
|
|
1002
1009
|
movement = newMovement;
|
|
1003
1010
|
}
|
|
1011
|
+
// console.log('after all collision', movement)
|
|
1004
1012
|
if (Math.pow(movement.norm(), 2) > 1e-7) {
|
|
1005
1013
|
player.pos.add(movement);
|
|
1006
1014
|
}
|
|
@@ -1073,7 +1081,8 @@ class BotcraftPhysics {
|
|
|
1073
1081
|
}
|
|
1074
1082
|
}
|
|
1075
1083
|
if (this.verGreaterThan("1.20.6")) {
|
|
1076
|
-
|
|
1084
|
+
const factor = (_d = (_c = player.attributes[this.movementEfficiencyAttribute]) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 1;
|
|
1085
|
+
blockSpeedFactor = blockSpeedFactor + factor * (1 - blockSpeedFactor);
|
|
1077
1086
|
}
|
|
1078
1087
|
player.vel.x *= blockSpeedFactor;
|
|
1079
1088
|
player.vel.z *= blockSpeedFactor;
|
|
@@ -1136,7 +1145,7 @@ class BotcraftPhysics {
|
|
|
1136
1145
|
}
|
|
1137
1146
|
}
|
|
1138
1147
|
collideBoundingBox(world, bb, movement, colliders = []) {
|
|
1139
|
-
|
|
1148
|
+
let queryBB = bb.expandTowards(movement);
|
|
1140
1149
|
const combinedColliders = [...colliders];
|
|
1141
1150
|
const blockCollisions = this.getSurroundingBBs(queryBB, world);
|
|
1142
1151
|
for (const block of blockCollisions) {
|
|
@@ -1154,20 +1163,20 @@ class BotcraftPhysics {
|
|
|
1154
1163
|
if (dy !== 0.0) {
|
|
1155
1164
|
dy = this.shapeCollide(1, bb, colliders, dy);
|
|
1156
1165
|
if (dy !== 0.0) {
|
|
1157
|
-
bb = bb.
|
|
1166
|
+
bb = bb.moveCoords(0, dy, 0);
|
|
1158
1167
|
}
|
|
1159
1168
|
}
|
|
1160
1169
|
const prioritizeZ = Math.abs(dx) < Math.abs(dz);
|
|
1161
1170
|
if (prioritizeZ && dz !== 0.0) {
|
|
1162
1171
|
dz = this.shapeCollide(2, bb, colliders, dz);
|
|
1163
1172
|
if (dz !== 0.0) {
|
|
1164
|
-
bb = bb.
|
|
1173
|
+
bb = bb.moveCoords(0, 0, dz);
|
|
1165
1174
|
}
|
|
1166
1175
|
}
|
|
1167
1176
|
if (dx !== 0.0) {
|
|
1168
1177
|
dx = this.shapeCollide(0, bb, colliders, dx);
|
|
1169
1178
|
if (!prioritizeZ && dx !== 0.0) {
|
|
1170
|
-
bb = bb.
|
|
1179
|
+
bb = bb.moveCoords(dx, 0, 0);
|
|
1171
1180
|
}
|
|
1172
1181
|
}
|
|
1173
1182
|
if (!prioritizeZ && dz !== 0.0) {
|
package/package.json
CHANGED
package/tests/fakeWorld.test.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { BotcraftPhysics, EntityPhysics, IPhysics } from "../src/physics/engines
|
|
|
10
10
|
import { initSetup } from "../src/index";
|
|
11
11
|
import { PlayerState } from "../src/physics/states";
|
|
12
12
|
import { Bot, ControlState } from "mineflayer";
|
|
13
|
+
import { AABB } from "@nxg-org/mineflayer-util-plugin";
|
|
13
14
|
|
|
14
15
|
const version = "1.12.2";
|
|
15
16
|
const mcData = md(version);
|
|
@@ -189,7 +190,7 @@ describe("Physics Simulation Tests", () => {
|
|
|
189
190
|
|
|
190
191
|
// console.log(fakePlayer.entity.position, landingPos, playerState.pos, playerState.control)
|
|
191
192
|
|
|
192
|
-
expect(fakePlayer.entity.position.z).toEqual(-
|
|
193
|
+
expect(fakePlayer.entity.position.z).toEqual(-6.607484778042766);
|
|
193
194
|
expect(fakePlayer.entity.position.y).toEqual(groundLevel);
|
|
194
195
|
})
|
|
195
196
|
|
|
@@ -234,7 +235,7 @@ describe("Physics Simulation Tests", () => {
|
|
|
234
235
|
expect(fakePlayer.entity.position.y).toEqual(groundLevel);
|
|
235
236
|
});
|
|
236
237
|
|
|
237
|
-
it("hCol
|
|
238
|
+
it("hCol--z", () => {
|
|
238
239
|
setupEntity(0);
|
|
239
240
|
const blockPos = new Vec3(0, groundLevel + 1, -2);
|
|
240
241
|
fakeWorld.setOverrideBlock(blockPos, mcData.blocksByName.dirt.id);
|
|
@@ -251,7 +252,7 @@ describe("Physics Simulation Tests", () => {
|
|
|
251
252
|
expect(playerState.isCollidedHorizontally).toEqual(true);
|
|
252
253
|
});
|
|
253
254
|
|
|
254
|
-
it("hCol
|
|
255
|
+
it("hCol-z", () => {
|
|
255
256
|
setupEntity(0);
|
|
256
257
|
const blockPos = new Vec3(0, groundLevel + 1, 1);
|
|
257
258
|
fakeWorld.setOverrideBlock(blockPos, mcData.blocksByName.dirt.id);
|
|
@@ -301,4 +302,53 @@ describe("Physics Simulation Tests", () => {
|
|
|
301
302
|
expect(playerState.pos.x).toEqual(0.7);
|
|
302
303
|
expect(playerState.isCollidedHorizontally).toEqual(true);
|
|
303
304
|
});
|
|
305
|
+
|
|
306
|
+
it("jumpIntoBlock", () => {
|
|
307
|
+
setupEntity(0);
|
|
308
|
+
|
|
309
|
+
const bl1 = new Vec3(0, groundLevel + 1, 1);
|
|
310
|
+
fakeWorld.setOverrideBlock(bl1, mcData.blocksByName.dirt.id);
|
|
311
|
+
|
|
312
|
+
fakePlayer.entity.position = new Vec3(0.5, groundLevel, 0.7); // right up against a block
|
|
313
|
+
playerState.pos = fakePlayer.entity.position.clone();
|
|
314
|
+
playerState.look(-359.9999 * (Math.PI / 360), 0);
|
|
315
|
+
|
|
316
|
+
playerState.control.jump = true;
|
|
317
|
+
playerState.control.forward = true;
|
|
318
|
+
playerState.control.sprint = true;
|
|
319
|
+
|
|
320
|
+
for (let i = 0; i < 12; i++) {
|
|
321
|
+
physics.simulate(playerCtx, fakeWorld);
|
|
322
|
+
playerState.apply(fakePlayer);
|
|
323
|
+
// console.log(fakePlayer.entity.position, playerState.isCollidedHorizontally);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
expect(playerState.pos.z).toEqual(0.7);
|
|
327
|
+
expect(playerState.isCollidedHorizontally).toEqual(true);
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it("walkUpStairs", () => {
|
|
331
|
+
setupEntity(0);
|
|
332
|
+
|
|
333
|
+
const bl1 = new Vec3(0, groundLevel, -1);
|
|
334
|
+
fakeWorld.setOverrideBlock(bl1, mcData.blocksByName.stone_stairs.id);
|
|
335
|
+
|
|
336
|
+
const shapes = fakeWorld.getBlock(bl1).shapes;
|
|
337
|
+
const bbs = shapes.map((shape) => AABB.fromShape(shape, bl1));
|
|
338
|
+
|
|
339
|
+
fakePlayer.entity.position = new Vec3(-0.3, groundLevel, -0.5); // right up against a block
|
|
340
|
+
playerState.pos = fakePlayer.entity.position.clone();
|
|
341
|
+
playerState.look(-180 * (Math.PI / 360), 0);
|
|
342
|
+
|
|
343
|
+
playerState.control.forward = true;
|
|
344
|
+
playerState.control.sprint = true;
|
|
345
|
+
|
|
346
|
+
for (let i = 0; i < 4; i++) {
|
|
347
|
+
// console.log(fakePlayer.entity.position, playerState.pos, playerState.isCollidedHorizontally);
|
|
348
|
+
physics.simulate(playerCtx, fakeWorld);
|
|
349
|
+
playerState.apply(fakePlayer);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
expect(playerState.pos.y).toEqual(groundLevel + 1);
|
|
353
|
+
});
|
|
304
354
|
});
|