Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
make physics plugin robust when blocks plugin disabled
  • Loading branch information
Callanplays committed Sep 22, 2025
commit 8a6954e4562d13edc28ad50b844d68c9cd98502c
12 changes: 10 additions & 2 deletions lib/plugins/physics.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ const PHYSICS_TIMESTEP = PHYSICS_INTERVAL_MS / 1000 // 0.05

function inject (bot, { physicsEnabled, maxCatchupTicks }) {
const PHYSICS_CATCHUP_TICKS = maxCatchupTicks ?? 4
const world = { getBlock: (pos) => { return bot.blockAt(pos, false) } }
// In setups where the 'blocks' plugin is intentionally disabled to reduce CPU,
// bot.blockAt may be undefined. Guard it so the physics plugin can still operate in
// packet-scheduling mode (with physicsEnabled=false) without crashing.
const world = { getBlock: (pos) => { return (typeof bot.blockAt === 'function') ? bot.blockAt(pos, false) : null } }
const physics = Physics(bot.registry, world)

const positionUpdateSentEveryTick = bot.supportFeature('positionUpdateSentEveryTick')
Expand Down Expand Up @@ -76,7 +79,12 @@ function inject (bot, { physicsEnabled, maxCatchupTicks }) {
}

function tickPhysics (now) {
if (bot.blockAt(bot.entity.position) == null) return // check if chunk is unloaded
// If the world plugin is disabled, bot.blockAt may not exist. Only perform the
// chunk-loaded check when available. Otherwise, proceed so the plugin can continue
// to send movement/keepalive packets without full world state.
if (typeof bot.blockAt === 'function') {
if (bot.blockAt(bot.entity.position) == null) return // check if chunk is unloaded
}
if (bot.physicsEnabled && shouldUsePhysics) {
physics.simulatePlayer(new PlayerState(bot, controlState), world).apply(bot)
bot.emit('physicsTick')
Expand Down
Loading