Skip to content
Closed
Changes from all commits
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
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,15 @@ 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) } }
const world = {
getBlock: (pos) => {
if (typeof bot.blockAt === 'function') {
return bot.blockAt(pos, false)
}
// if blocks plugin is unloaded, return a minimal air block object
return { name: 'air', type: 0, boundingBox: 'empty', shapes: [], position: pos }
}
}
const physics = Physics(bot.registry, world)

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

function tickPhysics (now) {
if (bot.blockAt(bot.entity.position) == null) return // check if chunk is unloaded
if (typeof bot.blockAt === 'function' && 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