Skip to content

Commit

Permalink
Merge pull request #609 from Meldiron/master
Browse files Browse the repository at this point in the history
Added sneaking option to controll states
  • Loading branch information
rom1504 authored Nov 5, 2017
2 parents 2d44812 + de9eee5 commit 0d0f491
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ All scoreboards known to the bot in an object scoreboard name -> scoreboard.

#### bot.controlState

An object whose keys are the main control states: ['forward', 'back', 'left', 'right', 'jump', 'sprint'].
An object whose keys are the main control states: ['forward', 'back', 'left', 'right', 'jump', 'sprint', 'sneak'].

Setting values for this object internally calls [bot.setControlState](#botsetcontrolstatecontrol-state).

Expand Down Expand Up @@ -1144,7 +1144,7 @@ Get out of bed. `cb` can have an err parameter if the bot cannot wake up.

#### bot.setControlState(control, state)

* `control` - one of ['forward', 'back', 'left', 'right', 'jump', 'sprint']
* `control` - one of ['forward', 'back', 'left', 'right', 'jump', 'sprint', 'sneak']
* `state` - `true` or `false`

#### bot.clearControlStates()
Expand Down
9 changes: 8 additions & 1 deletion lib/plugins/physics.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ function inject (bot) {
left: false,
right: false,
jump: false,
sprint: false
sprint: false,
sneak: false
}
let jumpQueued = false
let lastSentYaw = null
Expand Down Expand Up @@ -302,6 +303,12 @@ function inject (bot) {
actionId: state ? 3 : 4,
jumpBoost: 0
})
} else if (control === 'sneak') {
bot._client.write('entity_action', {
entityId: bot.entity.id,
actionId: state ? 0 : 1,
jumpBoost: 0
})
}
}

Expand Down

0 comments on commit 0d0f491

Please sign in to comment.