@@ -2,6 +2,7 @@ import { useRef, useEffect } from 'react'
22import { subscribe , useSnapshot } from 'valtio'
33import { useUtilsEffect } from '@zardoy/react-util'
44import { getThreeJsRendererMethods } from 'renderer/viewer/three/threeJsMethods'
5+ import { isItemActivatableMobile } from 'mineflayer-mouse/dist/activatableItemsMobile'
56import { options } from '../optionsStorage'
67import { activeModalStack , isGameActive , miscUiState } from '../globalState'
78import { onCameraMove , CameraMoveEvent } from '../cameraRotationControls'
@@ -77,7 +78,10 @@ function GameInteractionOverlayInner ({
7778 if ( options . touchInteractionType === 'classic' ) {
7879 virtualClickTimeout ??= setTimeout ( ( ) => {
7980 virtualClickActive = true
80- document . dispatchEvent ( new MouseEvent ( 'mousedown' , { button : 0 } ) )
81+ // If held item is activatable, use right click instead of left
82+ const heldItemName = bot ?. heldItem ?. name
83+ const isOnlyActivatable = heldItemName && isItemActivatableMobile ( heldItemName , loadedData )
84+ document . dispatchEvent ( new MouseEvent ( 'mousedown' , { button : isOnlyActivatable ? 2 : 0 } ) )
8185 } , touchStartBreakingBlockMs )
8286 }
8387 }
@@ -150,16 +154,23 @@ function GameInteractionOverlayInner ({
150154
151155 if ( virtualClickActive ) {
152156 // button 0 is left click
153- document . dispatchEvent ( new MouseEvent ( 'mouseup' , { button : 0 } ) )
157+ // If held item is activatable, use right click instead of left
158+ const heldItemName = bot ?. heldItem ?. name
159+ const isOnlyActivatable = heldItemName && isItemActivatableMobile ( heldItemName , loadedData )
160+ document . dispatchEvent ( new MouseEvent ( 'mouseup' , { button : isOnlyActivatable ? 2 : 0 } ) )
154161 virtualClickActive = false
155162 } else if ( ! capturedPointer . active . activateCameraMove && ( Date . now ( ) - capturedPointer . active . time < touchStartBreakingBlockMs ) ) {
156163 // single click action
157164 const MOUSE_BUTTON_RIGHT = 2
158165 const MOUSE_BUTTON_LEFT = 0
166+ const heldItemName = bot ?. heldItem ?. name
167+ const isOnlyActivatable = heldItemName && isItemActivatableMobile ( heldItemName , loadedData )
159168 const gonnaAttack = ! ! bot . mouse . getCursorState ( ) . entity || ! ! videoCursorInteraction ( )
160- document . dispatchEvent ( new MouseEvent ( 'mousedown' , { button : gonnaAttack ? MOUSE_BUTTON_LEFT : MOUSE_BUTTON_RIGHT } ) )
169+ // If not attacking entity and item is activatable, use right click for breaking
170+ const useButton = ! gonnaAttack && isOnlyActivatable ? MOUSE_BUTTON_RIGHT : ( gonnaAttack ? MOUSE_BUTTON_LEFT : MOUSE_BUTTON_RIGHT )
171+ document . dispatchEvent ( new MouseEvent ( 'mousedown' , { button : useButton } ) )
161172 bot . mouse . update ( )
162- document . dispatchEvent ( new MouseEvent ( 'mouseup' , { button : gonnaAttack ? MOUSE_BUTTON_LEFT : MOUSE_BUTTON_RIGHT } ) )
173+ document . dispatchEvent ( new MouseEvent ( 'mouseup' , { button : useButton } ) )
163174 }
164175
165176 if ( screenTouches > 0 ) {
0 commit comments