@@ -2,6 +2,7 @@ import { useRef, useEffect } from 'react'
2
2
import { subscribe , useSnapshot } from 'valtio'
3
3
import { useUtilsEffect } from '@zardoy/react-util'
4
4
import { getThreeJsRendererMethods } from 'renderer/viewer/three/threeJsMethods'
5
+ import { isItemActivatableMobile } from 'mineflayer-mouse/dist/activatableItemsMobile'
5
6
import { options } from '../optionsStorage'
6
7
import { activeModalStack , isGameActive , miscUiState } from '../globalState'
7
8
import { onCameraMove , CameraMoveEvent } from '../cameraRotationControls'
@@ -77,7 +78,10 @@ function GameInteractionOverlayInner ({
77
78
if ( options . touchInteractionType === 'classic' ) {
78
79
virtualClickTimeout ??= setTimeout ( ( ) => {
79
80
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 } ) )
81
85
} , touchStartBreakingBlockMs )
82
86
}
83
87
}
@@ -150,16 +154,23 @@ function GameInteractionOverlayInner ({
150
154
151
155
if ( virtualClickActive ) {
152
156
// 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 } ) )
154
161
virtualClickActive = false
155
162
} else if ( ! capturedPointer . active . activateCameraMove && ( Date . now ( ) - capturedPointer . active . time < touchStartBreakingBlockMs ) ) {
156
163
// single click action
157
164
const MOUSE_BUTTON_RIGHT = 2
158
165
const MOUSE_BUTTON_LEFT = 0
166
+ const heldItemName = bot ?. heldItem ?. name
167
+ const isOnlyActivatable = heldItemName && isItemActivatableMobile ( heldItemName , loadedData )
159
168
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 } ) )
161
172
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 } ) )
163
174
}
164
175
165
176
if ( screenTouches > 0 ) {
0 commit comments