Skip to content

Commit

Permalink
Fix wait for ticks && Expose bot.physicEnabled (#1687)
Browse files Browse the repository at this point in the history
* Fix wait for ticks

* Expose bot.physicEnabled

* lib/plugins/block_actions.js

* Update api
  • Loading branch information
Karang authored Feb 20, 2021
1 parent 79a7533 commit 0c1511f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,10 @@ The item in the bot's hand, represented as a [prismarine-item](https://github.co

#### bot.game.serverBrand

### bot.physicEnabled

Enable physics, default true.

### bot.player

Bot's player object
Expand Down
2 changes: 2 additions & 0 deletions lib/plugins/block_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ function inject (bot, { version }) {
if (bot.supportFeature('doesntHaveChestType')) {
const facing = parseChestMetadata(chestBlock).facing

if (!facing) return 'single'

// We have to check if the adjacent blocks in the perpendicular cardinals are the same type
const perpendicularCardinals = Object.keys(FACING_MAP[facing])
for (const cardinal of perpendicularCardinals) {
Expand Down
12 changes: 6 additions & 6 deletions lib/plugins/physics.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function inject (bot) {
let lastSentYaw = null
let doPhysicsTimer = null
let lastPhysicsFrameTime = null
let physicEnabled = false
bot.physicEnabled = false

const lastSent = {
x: 0,
Expand All @@ -58,7 +58,7 @@ function inject (bot) {
timeAccumulator += deltaSeconds

while (timeAccumulator >= PHYSICS_TIMESTEP) {
if (physicEnabled) {
if (bot.physicEnabled) {
physics.simulatePlayer(new PlayerState(bot, controlState), world).apply(bot)
bot.emit('physicTick')
}
Expand Down Expand Up @@ -253,7 +253,7 @@ function inject (bot) {
}
sendPacketPositionAndLook(pos, newYaw, newPitch, bot.entity.onGround)

physicEnabled = true
bot.physicEnabled = true
bot.entity.timeSinceOnGround = 0
lastSentYaw = bot.entity.yaw

Expand All @@ -275,11 +275,11 @@ function inject (bot) {
}
}

this.bot.on('physicTick', tickListener)
bot.on('physicTick', tickListener)
})
}

bot.on('mount', () => { physicEnabled = false })
bot.on('respawn', () => { physicEnabled = false })
bot.on('mount', () => { bot.physicEnabled = false })
bot.on('respawn', () => { bot.physicEnabled = false })
bot.on('end', cleanup)
}

0 comments on commit 0c1511f

Please sign in to comment.