Skip to content

Commit

Permalink
forcelook
Browse files Browse the repository at this point in the history
  • Loading branch information
aesthetic0001 committed Mar 13, 2024
1 parent 1538d35 commit 7cc0607
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/blockInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bot.once('spawn', () => {
range: 4
}))
await bot.equip(itemsInInventory[0], 'hand')
await bot.lookAt(rayBlock.position.offset(face.x * 0.5 + 0.5, face.y * 0.5 + 0.5, face.z * 0.5 + 0.5))
await bot.lookAt(rayBlock.position.offset(face.x * 0.5 + 0.5, face.y * 0.5 + 0.5, face.z * 0.5 + 0.5), true)
await bot.placeBlock(rayBlock, face)
} catch (e) {
console.error(e)
Expand Down
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ function inject (bot) {
const viewVector = getViewVector(targetPitch, targetYaw)
// While the bot is not in the right position rotate the view and press back while crouching
if (bot.entity.position.distanceTo(refBlock.clone().offset(edge.x + 0.5, 1, edge.z + 0.5)) > 0.4) {
bot.lookAt(bot.entity.position.offset(viewVector.x, viewVector.y, viewVector.z), allowInstantTurn)
bot.lookAt(bot.entity.position.offset(viewVector.x, viewVector.y, viewVector.z), true)
bot.setControlState('sneak', true)
bot.setControlState('back', true)
return false
Expand All @@ -382,7 +382,7 @@ function inject (bot) {
const minDistanceSq = 0.2 * 0.2
const targetPos = pos.clone().offset(0.5, 0, 0.5)
if (bot.entity.position.distanceSquared(targetPos) > minDistanceSq) {
bot.lookAt(targetPos)
bot.lookAt(targetPos, true)
bot.setControlState('forward', true)
return false
}
Expand Down Expand Up @@ -427,7 +427,7 @@ function inject (bot) {
if (stateMovements && stateMovements.allowFreeMotion && stateGoal && stateGoal.entity) {
const target = stateGoal.entity
if (physics.canStraightLine([target.position])) {
bot.lookAt(target.position.offset(0, 1.6, 0))
bot.lookAt(target.position.offset(0, 1.6, 0), true)

if (target.position.distanceSquared(bot.entity.position) > stateGoal.rangeSq) {
bot.setControlState('forward', true)
Expand Down Expand Up @@ -624,7 +624,7 @@ function inject (bot) {

// console.log(`Treating as regular goal node: ${nextPoint.x}, ${nextPoint.y}, ${nextPoint.z}`)

bot.look(Math.atan2(-dx, -dz), Math.random() > 0.5 ? -Math.random() * (Math.PI / 24) : Math.random() * (Math.PI / 24), false)
bot.look(Math.atan2(-dx, -dz), Math.random() > 0.5 ? -Math.random() * (Math.PI / 24) : Math.random() * (Math.PI / 24), true)

bot.setControlState('forward', true)
bot.setControlState('jump', false)
Expand Down

0 comments on commit 7cc0607

Please sign in to comment.