Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sneaking option to controll states #609

Merged
merged 2 commits into from
Nov 5, 2017
Merged
Show file tree
Hide file tree
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
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint doesn't like the trailing commas, you will need to remove it to confirm to the code style rules

}
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 means no sneaking ?

jumpBoost: 0
})
}
}

Expand Down