Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions lib/plugins/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ const PLAYER_WIDTH = 0.6
const PLAYER_EYEHEIGHT = 1.62
const CROUCH_EYEHEIGHT = 1.27

// export constants for reuse
module.exports.PLAYER_HEIGHT = PLAYER_HEIGHT
module.exports.CROUCH_HEIGHT = CROUCH_HEIGHT
module.exports.PLAYER_WIDTH = PLAYER_WIDTH
module.exports.PLAYER_EYEHEIGHT = PLAYER_EYEHEIGHT
module.exports.CROUCH_EYEHEIGHT = CROUCH_EYEHEIGHT

module.exports = inject

const animationEvents = {
Expand Down
9 changes: 6 additions & 3 deletions lib/plugins/ray_trace.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { Vec3 } = require('vec3')
const { RaycastIterator } = require('prismarine-world').iterators
const { PLAYER_EYEHEIGHT, CROUCH_EYEHEIGHT } = require('./entities')

module.exports = (bot) => {
function getViewDirection (pitch, yaw) {
Expand Down Expand Up @@ -56,10 +57,12 @@ module.exports = (bot) => {
}

bot.blockAtEntityCursor = (entity = bot.entity, maxDistance = 256, matcher = null) => {
if (!entity.position || !entity.height || !entity.pitch || !entity.yaw) return null
const { position, height, pitch, yaw } = entity
if (!entity.position || !entity.height || entity.pitch === undefined || entity.yaw === undefined) return null
const { position, pitch, yaw } = entity

const eyePosition = position.offset(0, height, 0)
const eyeHeight = bot.controlState.sneak ? CROUCH_EYEHEIGHT : PLAYER_EYEHEIGHT

const eyePosition = position.offset(0, eyeHeight, 0)
const viewDirection = getViewDirection(pitch, yaw)

return bot.world.raycast(eyePosition, viewDirection, maxDistance, matcher)
Expand Down
Loading