11import { useEffect , useRef , useState } from 'react'
2+ import type { Entity } from 'prismarine-entity'
23import { useSnapshot } from 'valtio'
34import type { Block } from 'prismarine-block'
45import { getThreeJsRendererMethods } from 'renderer/viewer/three/threeJsMethods'
@@ -39,6 +40,7 @@ export default () => {
3940 const [ timeOfDay , setTimeOfDay ] = useState ( 0 )
4041 const [ dimension , setDimension ] = useState ( '' )
4142 const [ cursorBlock , setCursorBlock ] = useState < Block | null > ( null )
43+ const [ cursorEntity , setCursorEntity ] = useState < Entity | null > ( null )
4244 const [ blockInfo , setBlockInfo ] = useState < { customBlockName ?: string , modelInfo ?: BlockStateModelInfo } | null > ( null )
4345 const [ clientTps , setClientTps ] = useState ( 0 )
4446 const [ serverTps , setServerTps ] = useState ( null as null | { value : number , frozen : boolean } )
@@ -55,6 +57,14 @@ export default () => {
5557
5658 const viewDegToMinecraft = ( yaw ) => yaw % 360 - 180 * ( yaw < 0 ? - 1 : 1 )
5759
60+ const shortenUuid = ( uuid : string | undefined ) : string | undefined => {
61+ if ( ! uuid ) return undefined
62+ // Format: 2383-*-3243 (first 4 chars, *, last 4 chars)
63+ const cleaned = uuid . replaceAll ( '-' , '' )
64+ if ( cleaned . length < 8 ) return uuid
65+ return `${ cleaned . slice ( 0 , 4 ) } -*-${ cleaned . slice ( - 4 ) } `
66+ }
67+
5868 const readPacket = ( data , { name } , _buf , fullBuffer ) => {
5969 if ( fullBuffer ) {
6070 const size = fullBuffer . byteLength
@@ -129,7 +139,9 @@ export default () => {
129139 setDimension ( bot . game . dimension )
130140 setDay ( bot . time . day )
131141 setTimeOfDay ( bot . time . timeOfDay )
132- setCursorBlock ( bot . mouse . getCursorState ( ) . cursorBlock )
142+ const cursorState = bot . mouse . getCursorState ( )
143+ setCursorBlock ( cursorState . cursorBlock )
144+ setCursorEntity ( cursorState . entity )
133145 } , 100 )
134146
135147 const notFrequentUpdateInterval = setInterval ( async ( ) => {
@@ -212,6 +224,22 @@ export default () => {
212224 { cursorBlock ? (
213225 < p > Looking at: { cursorBlock . position . x } { cursorBlock . position . y } { cursorBlock . position . z } </ p >
214226 ) : '' }
227+ { cursorEntity ? ( < >
228+ < div className = { styles . empty } />
229+ < p > E: { cursorEntity . name } </ p >
230+ { cursorEntity . displayName && < p > { cursorEntity . displayName } </ p > }
231+ { cursorEntity . id !== undefined && < p > ID: { cursorEntity . id } </ p > }
232+ { shortenUuid ( cursorEntity . uuid ) && < p > UUID: { shortenUuid ( cursorEntity . uuid ) } </ p > }
233+ { cursorEntity . username && < p > Username: { cursorEntity . username } </ p > }
234+ { cursorEntity . position && (
235+ < p > { cursorEntity . position . x . toFixed ( 2 ) } { cursorEntity . position . y . toFixed ( 2 ) } { cursorEntity . position . z . toFixed ( 2 ) } </ p >
236+ ) }
237+ { cursorEntity . yaw !== undefined && < p > Yaw: { cursorEntity . yaw . toFixed ( 1 ) } </ p > }
238+ { cursorEntity . pitch !== undefined && < p > Pitch: { cursorEntity . pitch . toFixed ( 1 ) } </ p > }
239+ { cursorEntity . type && < p > Type: { cursorEntity . type } </ p > }
240+ { cursorEntity . health !== undefined && < p > Health: { cursorEntity . health . toFixed ( 1 ) } </ p > }
241+ </ > )
242+ : '' }
215243 < div className = { styles . empty } />
216244 { blockInfo && ( ( ) => {
217245 const { customBlockName, modelInfo } = blockInfo
0 commit comments