@@ -54,6 +54,7 @@ function inject (bot) {
5454 z : Math . sign ( Math . abs ( dz ) > 0.5 ? dz : 0 )
5555 }
5656 const validFaces = [ ]
57+ const closerBlocks = [ ]
5758 for ( const i in visibleFaces ) {
5859 if ( ! visibleFaces [ i ] ) continue // skip as this face is not visible
5960 // target position on the target block face. -> 0.5 + (current face) * 0.5
@@ -65,13 +66,19 @@ function inject (bot) {
6566 const startPos = bot . entity . position . offset ( 0 , bot . entity . height , 0 )
6667 const rayBlock = bot . world . raycast ( startPos , targetPos . clone ( ) . subtract ( startPos ) . normalize ( ) , 5 )
6768 if ( rayBlock ) {
69+ if ( startPos . distanceTo ( rayBlock . intersect ) < startPos . distanceTo ( targetPos ) ) {
70+ // Block is closer then the raycasted block
71+ closerBlocks . push ( rayBlock )
72+ // continue since if distance is ever less, then we did not intersect the block we wanted,
73+ // meaning that the position of the intersected block is not what we want.
74+ continue
75+ }
6876 const rayPos = rayBlock . position
6977 if (
7078 rayPos . x === block . position . x &&
7179 rayPos . y === block . position . y &&
7280 rayPos . z === block . position . z
7381 ) {
74- // console.info(rayBlock)
7582 validFaces . push ( {
7683 face : rayBlock . face ,
7784 targetPos : rayBlock . intersect
@@ -95,6 +102,11 @@ function inject (bot) {
95102 }
96103 await bot . lookAt ( closest . targetPos , forceLook )
97104 diggingFace = closest . face
105+ } else if ( closerBlocks . length === 0 && block . shapes . length === 0 ) {
106+ // no other blocks were detected and the block has no shapes.
107+ // The block in question is replaceable (like tall grass) so we can just dig it
108+ // TODO: do AABB + ray intercept check to this position for diggingFace.
109+ await bot . lookAt ( block . position . offset ( 0.5 , 0.5 , 0.5 ) , forceLook )
98110 } else {
99111 // Block is obstructed return error?
100112 throw new Error ( 'Block not in view' )
0 commit comments