@nxg-org/mineflayer-physics-util 1.8.5 → 1.8.6
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.
|
@@ -311,9 +311,11 @@ class BotcraftPhysics {
|
|
|
311
311
|
for (blockPos.y = Math.floor(minAABB.y); blockPos.y <= Math.floor(maxAABB.y); ++blockPos.y) {
|
|
312
312
|
for (blockPos.z = Math.floor(minAABB.z); blockPos.z <= Math.floor(maxAABB.z); ++blockPos.z) {
|
|
313
313
|
const block = world.getBlock(blockPos);
|
|
314
|
+
if (block == null)
|
|
315
|
+
continue;
|
|
314
316
|
const waterRes = waterCond(block);
|
|
315
317
|
const lavaRes = lavaCond(block);
|
|
316
|
-
if (
|
|
318
|
+
if ((waterRes && !water) || (lavaRes && water) || (!waterRes && !lavaRes)) {
|
|
317
319
|
continue;
|
|
318
320
|
}
|
|
319
321
|
let fluidHeight = 0.0;
|
|
@@ -587,14 +589,17 @@ class BotcraftPhysics {
|
|
|
587
589
|
}
|
|
588
590
|
inputsToSprint(ctx, heading, world) {
|
|
589
591
|
const player = ctx.state;
|
|
590
|
-
//
|
|
592
|
+
// console.log('is sprinting', player.sprinting, 'can sprint', this.canStartSprinting(ctx, heading), player.sprinting)
|
|
591
593
|
if (this.canStartSprinting(ctx, heading) &&
|
|
592
|
-
(player.control.sprint ||
|
|
593
|
-
(player.sprintTriggerTime > 0 && heading.forward >= (player.isInWater ? 1e-5 : 0.8)))) {
|
|
594
|
+
(player.control.sprint || (player.sprintTriggerTime > 0 && heading.forward >= (player.isInWater ? 1e-5 : 0.8)))) {
|
|
594
595
|
this.setSprinting(ctx, true);
|
|
595
596
|
}
|
|
597
|
+
// console.log('should stop', this.shouldStopRunSprinting(ctx, heading), 'minor collision', player.isCollidedHorizontallyMinor)
|
|
596
598
|
// Stop sprinting if necessary
|
|
597
599
|
if (player.sprinting) {
|
|
600
|
+
if (!player.control.sprint) {
|
|
601
|
+
this.setSprinting(ctx, false);
|
|
602
|
+
}
|
|
598
603
|
if (this.isSwimming(ctx)) {
|
|
599
604
|
if (this.shouldStopSwimSprinting(ctx, heading)) {
|
|
600
605
|
this.setSprinting(ctx, false);
|
|
@@ -659,8 +664,7 @@ class BotcraftPhysics {
|
|
|
659
664
|
let attr = player.attributes[this.movementSpeedAttribute];
|
|
660
665
|
if (attr != null)
|
|
661
666
|
attributes.deleteAttributeModifier(attr, ctx.worldSettings.sprintingUUID);
|
|
662
|
-
|
|
663
|
-
attr = attributes.createAttributeValue(ctx.worldSettings.playerSpeed);
|
|
667
|
+
attr = attributes.createAttributeValue(ctx.worldSettings.playerSpeed);
|
|
664
668
|
if (value) {
|
|
665
669
|
attributes.addAttributeModifier(attr, {
|
|
666
670
|
uuid: ctx.worldSettings.sprintingUUID,
|
|
@@ -668,6 +672,10 @@ class BotcraftPhysics {
|
|
|
668
672
|
operation: 2,
|
|
669
673
|
});
|
|
670
674
|
}
|
|
675
|
+
// potential deviation from vanilla.
|
|
676
|
+
// if (value != player.sprinting) {
|
|
677
|
+
// player.sprintTriggerTime = ctx.worldSettings.sprintTimeTriggerCooldown;
|
|
678
|
+
// }
|
|
671
679
|
player.attributes[this.movementSpeedAttribute] = attr;
|
|
672
680
|
player.sprinting = value;
|
|
673
681
|
}
|
|
@@ -685,7 +693,7 @@ class BotcraftPhysics {
|
|
|
685
693
|
// If double jump in creative, swap flying mode
|
|
686
694
|
if (player.prevControl.jump && player.control.jump) {
|
|
687
695
|
if (player.flyJumpTriggerTime === 0) {
|
|
688
|
-
player.flyJumpTriggerTime =
|
|
696
|
+
player.flyJumpTriggerTime = ctx.worldSettings.flyJumpTriggerCooldown;
|
|
689
697
|
}
|
|
690
698
|
else if (this.isSwimmingAndNotFlying(ctx, world)) {
|
|
691
699
|
player.flying = !player.flying;
|
|
@@ -738,6 +746,7 @@ class BotcraftPhysics {
|
|
|
738
746
|
blockJumpFactor = 0.4;
|
|
739
747
|
}
|
|
740
748
|
if (this.verLessThan("1.20.5")) {
|
|
749
|
+
console.log(blockJumpFactor);
|
|
741
750
|
player.vel.y = Math.fround(0.42) * blockJumpFactor + jumpBoost;
|
|
742
751
|
if (player.sprinting) {
|
|
743
752
|
const yawRad = Math.PI - player.yaw; // should already be in yaw. MINEFLAYER SPECIFC CHANGE, MATH.PI -
|
|
@@ -750,7 +759,7 @@ class BotcraftPhysics {
|
|
|
750
759
|
}
|
|
751
760
|
else {
|
|
752
761
|
// something about getting an attribute for jump strength?
|
|
753
|
-
const value = (_b = (_a = entity.attributes[this.jumpStrengthAttribute]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b :
|
|
762
|
+
const value = (_b = (_a = entity.attributes[this.jumpStrengthAttribute]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : Math.fround(0.42); // default value from previous versions
|
|
754
763
|
const jumpPower = value * blockJumpFactor + jumpBoost;
|
|
755
764
|
if (jumpPower > 1e-5) {
|
|
756
765
|
player.vel.y = jumpPower;
|
|
@@ -1161,7 +1170,7 @@ class BotcraftPhysics {
|
|
|
1161
1170
|
// return false;
|
|
1162
1171
|
// }
|
|
1163
1172
|
// }
|
|
1164
|
-
const yawRad = player.yaw
|
|
1173
|
+
const yawRad = Math.PI - player.yaw; //* (Math.PI / 180);
|
|
1165
1174
|
const sinYaw = Math.sin(yawRad);
|
|
1166
1175
|
const cosYaw = Math.cos(yawRad);
|
|
1167
1176
|
const xxa = player.prevHeading.forward;
|
|
@@ -1172,7 +1181,9 @@ class BotcraftPhysics {
|
|
|
1172
1181
|
const horizMovement = Math.pow(var1.x, 2) + Math.pow(var1.z, 2);
|
|
1173
1182
|
if (horizSpeed >= 1e-5 && horizMovement >= 1e-5) {
|
|
1174
1183
|
const dot = xxaRot * var1.x + zzaRot * var1.z;
|
|
1175
|
-
|
|
1184
|
+
let angle = Math.acos(dot / Math.sqrt(horizSpeed * horizMovement));
|
|
1185
|
+
// unsure why this is needed, but this ends up matching.
|
|
1186
|
+
angle = Math.abs(angle - Math.PI / 2);
|
|
1176
1187
|
return angle < 0.13962634; // magic number
|
|
1177
1188
|
}
|
|
1178
1189
|
else
|
|
@@ -18,6 +18,8 @@ export declare class PhysicsWorldSettings {
|
|
|
18
18
|
ladderClimbSpeed: number;
|
|
19
19
|
defaultSlipperiness: number;
|
|
20
20
|
outOfLiquidImpulse: number;
|
|
21
|
+
sprintTimeTriggerCooldown: number;
|
|
22
|
+
flyJumpTriggerCooldown: number;
|
|
21
23
|
autojumpCooldown: number;
|
|
22
24
|
bubbleColumnSurfaceDrag: BubbleColumnInfo;
|
|
23
25
|
bubbleColumnDrag: BubbleColumnInfo;
|
|
@@ -18,6 +18,8 @@ class PhysicsWorldSettings {
|
|
|
18
18
|
// public liquidAcceleration: number = 0.02;
|
|
19
19
|
this.defaultSlipperiness = 0.6;
|
|
20
20
|
this.outOfLiquidImpulse = Math.fround(0.3);
|
|
21
|
+
this.sprintTimeTriggerCooldown = 2;
|
|
22
|
+
this.flyJumpTriggerCooldown = 7;
|
|
21
23
|
this.autojumpCooldown = 10; // ticks (0.5s)
|
|
22
24
|
this.bubbleColumnSurfaceDrag = {
|
|
23
25
|
down: 0.03,
|
|
@@ -110,6 +110,8 @@ class PlayerState {
|
|
|
110
110
|
return 1.62;
|
|
111
111
|
case poses_1.PlayerPoses.SNEAKING:
|
|
112
112
|
return 1.27;
|
|
113
|
+
case poses_1.PlayerPoses.DYING:
|
|
114
|
+
case poses_1.PlayerPoses.SLEEPING:
|
|
113
115
|
case poses_1.PlayerPoses.SWIMMING:
|
|
114
116
|
case poses_1.PlayerPoses.FALL_FLYING:
|
|
115
117
|
case poses_1.PlayerPoses.SPIN_ATTACK:
|
package/package.json
CHANGED
package/tests/actualBot.ts
CHANGED
|
@@ -16,12 +16,16 @@ function buildBot() {
|
|
|
16
16
|
console.log("hey!");
|
|
17
17
|
|
|
18
18
|
const bot = createBot({
|
|
19
|
-
host: process.argv[2],
|
|
19
|
+
host: process.argv[2] || 'localhost',
|
|
20
20
|
port: Number(process.argv[3]),
|
|
21
21
|
username: "testingbot",
|
|
22
22
|
version: process.argv[4],
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
+
bot.on('login', () => {
|
|
26
|
+
bot.chat("Hello! I am a testing bot!");
|
|
27
|
+
})
|
|
28
|
+
|
|
25
29
|
bot.once("spawn", async () => {
|
|
26
30
|
bot.loadPlugin(loader);
|
|
27
31
|
bot.loadPlugin(pathfinder);
|