11const { Vec3} = require ( 'vec3' )
22const assert = require ( 'assert' )
33const conv = require ( '../conversions' )
4+ const math = require ( '../math' )
45const { performance} = require ( 'perf_hooks' )
56const { createDoneTask, createTask} = require ( '../promise_utils' )
67
@@ -380,18 +381,19 @@ function inject(bot, {physicsEnabled, maxCatchupTicks}) {
380381 bot . entity . pitch = conv . fromNotchianPitch ( bot . entity . pitchDegrees )
381382 }
382383
383- // bot.on('physicsTick', () => {
384- // if (!lookingTask.done) {
385- // if (Math.abs(deltaYawDegrees(bot.entity.yawDegrees, targetYaw)) < 0.1 && Math.abs(bot.entity.pitchDegrees.subtract(targetPitch)) < 0.1) {
386- // lookingTask.finish()
387- // } else {
388- // // look toward it
389- // const yawChange = math.clamp(-physics.yawSpeed, deltaYawDegrees(targetYaw, bot.entity.yawDegrees.valueOf()), physics.yawSpeed)
390- // const pitchChange = math.clamp(-physics.pitchSpeed, targetPitch - bot.entity.pitchDegrees.valueOf(), physics.pitchSpeed)
391- // setAngleDegrees(bot.entity.yawDegrees.valueOf() + yawChange, bot.entity.pitchDegrees.valueOf() + pitchChange)
392- // }
393- // }
394- // })
384+ bot . on ( 'physicsTick' , ( ) => {
385+ if ( lookingTask . done ) return
386+ const deltaYaw = deltaYawDegrees ( targetYaw , bot . entity . yawDegrees ) . valueOf ( )
387+ const deltaPitch = targetPitch . subtract ( bot . entity . pitchDegrees ) . valueOf ( )
388+ if ( Math . abs ( deltaYaw ) < 0.1 && Math . abs ( deltaPitch ) < 0.1 ) {
389+ lookingTask . finish ( )
390+ return
391+ }
392+ // look toward it
393+ const yawChange = math . clamp ( - physics . yawSpeed , deltaYaw , physics . yawSpeed )
394+ const pitchChange = math . clamp ( - physics . pitchSpeed , deltaPitch , physics . pitchSpeed )
395+ setAngleDegrees ( bot . entity . yawDegrees . valueOf ( ) + yawChange , bot . entity . pitchDegrees . valueOf ( ) + pitchChange )
396+ } )
395397
396398 bot . _client . on ( 'explosion' , explosion => {
397399 // TODO: emit an explosion event with more info
@@ -426,8 +428,8 @@ function inject(bot, {physicsEnabled, maxCatchupTicks}) {
426428 }
427429
428430 lookingTask = createTask ( )
429- targetYaw = yawNotchian
430- targetPitch = pitchNotchian
431+ targetYaw = new JavaFloat ( yawNotchian )
432+ targetPitch = new JavaFloat ( pitchNotchian )
431433 return await lookingTask . promise
432434 }
433435
@@ -559,4 +561,4 @@ function inject(bot, {physicsEnabled, maxCatchupTicks}) {
559561 bot . on ( 'end' , cleanup )
560562}
561563
562- module . exports = inject
564+ module . exports = inject
0 commit comments