Skip to content

Commit 16bd129

Browse files
committed
reset lastsent and controls on server change
1 parent 5ab6fa9 commit 16bd129

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

lib/plugins/physics.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ const sensitivityConstant = 0.15 * calculatedSensitivity
2222

2323
module.exports = inject
2424

25-
const PI = Math.PI
26-
const PI_2 = Math.PI * 2
2725
const PHYSICS_INTERVAL_MS = 50
2826
const PHYSICS_TIMESTEP = PHYSICS_INTERVAL_MS / 1000 // 0.05
2927

@@ -81,14 +79,13 @@ function inject(bot, {physicsEnabled, maxCatchupTicks}) {
8179
bot.physicsEnabled = physicsEnabled ?? true
8280
let deadTicks = 21
8381

84-
const lastSent = {
82+
let lastSent = {
8583
x: 0,
8684
y: 0,
8785
z: 0,
8886
// notchian
8987
yaw: 0,
9088
pitch: 0,
91-
// non-notchian
9289
onGround: false,
9390
ticker: 20,
9491
flags: {onGround: false, hasHorizontalCollision: false},
@@ -513,12 +510,37 @@ function inject(bot, {physicsEnabled, maxCatchupTicks}) {
513510
bot.on('mount', () => {
514511
shouldUsePhysics = false
515512
})
513+
514+
function forceResetControls() {
515+
for (const control in controlState) {
516+
controlState[control] = false
517+
}
518+
}
519+
516520
bot.on('respawn', () => {
517521
shouldUsePhysics = false
518-
bot.clearControlStates()
522+
forceResetControls()
519523
})
524+
520525
bot.on('login', () => {
521526
shouldUsePhysics = false
527+
forceResetControls()
528+
lastSent = {
529+
x: 0,
530+
y: 0,
531+
z: 0,
532+
// notchian
533+
yaw: 0,
534+
pitch: 0,
535+
onGround: false,
536+
ticker: 20,
537+
flags: {onGround: false, hasHorizontalCollision: false},
538+
// keep track of serverside sneak and sprint
539+
sprintState: false,
540+
sneakState: false,
541+
previousInputState: cloneInput(controlState)
542+
}
543+
522544
if (doPhysicsTimer === null) {
523545
lastPhysicsFrameTime = performance.now()
524546
doPhysicsTimer = setInterval(doPhysics, PHYSICS_INTERVAL_MS)

0 commit comments

Comments
 (0)