Skip to content

Commit 151c247

Browse files
committed
update server side sprinting
1 parent 422c247 commit 151c247

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/plugins/physics.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ function inject(bot, {physicsEnabled, maxCatchupTicks}) {
124124

125125
function tickPhysics(now) {
126126
if (bot.blockAt(bot.entity.position) == null) return // check if chunk is unloaded
127+
bot.emit('physicsTickBegin')
127128
if (bot.physicsEnabled && shouldUsePhysics) {
128129
if (typeof bot.entity.yawDegrees !== 'number') {
129130
bot.entity.yawDegrees = 0
@@ -132,12 +133,10 @@ function inject(bot, {physicsEnabled, maxCatchupTicks}) {
132133
physics.simulatePlayer(new PlayerState(bot, controlState, lastSent), world).apply(bot)
133134
updatePosition(now)
134135
bot.emit('physicsTick')
135-
bot.emit('physicTick') // Deprecated, only exists to support old plugins. May be removed in the future
136136
}
137137
if (bot.version === "1.21.5") {
138138
bot._client.write("tick_end")
139139
}
140-
bot.emit('physicsTickEnd')
141140
}
142141

143142
function cleanup() {
@@ -202,13 +201,18 @@ function inject(bot, {physicsEnabled, maxCatchupTicks}) {
202201
// Only send updates for 20 ticks after death
203202
if (isEntityRemoved()) return
204203

205-
if (lastSent.sprintState !== controlState.sprint) {
204+
const forward = (controlState.forward ? 1 : 0) - (controlState.back ? 1 : 0)
205+
const isSprintingApplicable = forward > 0 && !bot.entity.isCollidedHorizontally && !controlState.sneak
206+
// treat controlState.sprint as a request (sprint held), not necessary to fulfill it
207+
const actualSprint = isSprintingApplicable && controlState.sprint
208+
209+
if (lastSent.sprintState !== actualSprint) {
206210
bot._client.write('entity_action', {
207211
entityId: bot.entity.id,
208-
actionId: controlState.sprint ? 3 : 4,
212+
actionId: actualSprint ? 3 : 4,
209213
jumpBoost: 0,
210214
});
211-
lastSent.sprintState = controlState.sprint;
215+
lastSent.sprintState = actualSprint;
212216
}
213217

214218
if (lastSent.sneakState !== controlState.sneak) {

0 commit comments

Comments
 (0)