@@ -341,6 +341,16 @@ function inject (bot) {
341341 bot . emit ( 'entityMoved' , entity )
342342 } )
343343
344+ // 1.21.3 - merges the packets above
345+ bot . _client . on ( 'sync_entity_position' , ( packet ) => {
346+ const entity = fetchEntity ( packet . entityId )
347+ entity . position . set ( packet . x , packet . y , packet . z )
348+ entity . velocity . update ( packet . dx , packet . dy , packet . dz )
349+ entity . yaw = packet . yaw
350+ entity . pitch = packet . pitch
351+ bot . emit ( 'entityMoved' , entity )
352+ } )
353+
344354 bot . _client . on ( 'entity_head_rotation' , ( packet ) => {
345355 // entity head look
346356 const entity = fetchEntity ( packet . entityId )
@@ -361,6 +371,11 @@ function inject (bot) {
361371 if ( eventName ) bot . emit ( eventName , entity )
362372 } )
363373
374+ bot . _client . on ( 'damage_event' , ( packet ) => { // 1.20+
375+ const entity = bot . entities [ packet . entityId ]
376+ bot . emit ( 'entityHurt' , entity )
377+ } )
378+
364379 bot . _client . on ( 'attach_entity' , ( packet ) => {
365380 // attach entity
366381 const entity = fetchEntity ( packet . entityId )
@@ -585,6 +600,62 @@ function inject (bot) {
585600 bot . _client . on ( 'player_info' , ( packet ) => {
586601 // player list item(s)
587602
603+ if ( typeof packet . action !== 'number' ) {
604+ // the features checks below this will be un-needed with https://github.com/PrismarineJS/minecraft-data/pull/948
605+ for ( const update of packet . data ) {
606+ let player = bot . uuidToUsername [ update . uuid ] ? bot . players [ bot . uuidToUsername [ update . uuid ] ] : null
607+ let newPlayer = false
608+
609+ const obj = {
610+ uuid : update . uuid
611+ }
612+
613+ if ( ! player ) newPlayer = true
614+
615+ player ||= obj
616+
617+ if ( packet . action . add_player ) {
618+ obj . username = update . player . name
619+ obj . displayName = player . displayName || new ChatMessage ( { text : '' , extra : [ { text : update . player . name } ] } )
620+ obj . skinData = extractSkinInformation ( update . player . properties )
621+ }
622+
623+ if ( packet . action . update_game_mode ) {
624+ obj . gamemode = update . gamemode
625+ }
626+
627+ if ( packet . action . update_latency ) {
628+ obj . ping = update . latency
629+ }
630+
631+ if ( update . displayName ) {
632+ obj . displayName = ChatMessage . fromNotch ( update . displayName )
633+ }
634+
635+ if ( newPlayer ) {
636+ if ( ! obj . username ) continue // Should be unreachable
637+ player = bot . players [ obj . username ] = obj
638+ bot . uuidToUsername [ obj . uuid ] = obj . username
639+ } else {
640+ Object . assign ( player , obj )
641+ }
642+
643+ const playerEntity = Object . values ( bot . entities ) . find ( e => e . type === 'player' && e . username === player . username )
644+ player . entity = playerEntity
645+
646+ if ( playerEntity === bot . entity ) {
647+ bot . player = player
648+ }
649+
650+ if ( newPlayer ) {
651+ bot . emit ( 'playerJoined' , player )
652+ } else {
653+ bot . emit ( 'playerUpdated' , player )
654+ }
655+ }
656+ return
657+ }
658+
588659 if ( bot . supportFeature ( 'playerInfoActionIsBitfield' ) ) {
589660 for ( const item of packet . data ) {
590661 let player = bot . uuidToUsername [ item . uuid ] ? bot . players [ bot . uuidToUsername [ item . uuid ] ] : null
@@ -795,20 +866,42 @@ function inject (bot) {
795866 }
796867
797868 function moveVehicle ( left , forward ) {
798- bot . _client . write ( 'steer_vehicle' , {
799- sideways : left ,
800- forward,
801- jump : 0x01
802- } )
869+ if ( bot . supportFeature ( 'newPlayerInputPacket' ) ) {
870+ // docs:
871+ // * left can take -1 or 1 : -1 means right, 1 means left
872+ // * forward can take -1 or 1 : -1 means backward, 1 means forward
873+ bot . _client . write ( 'player_input' , {
874+ inputs : {
875+ forward : forward > 0 ,
876+ backward : forward < 0 ,
877+ left : left > 0 ,
878+ right : left < 0
879+ }
880+ } )
881+ } else {
882+ bot . _client . write ( 'steer_vehicle' , {
883+ sideways : left ,
884+ forward,
885+ jump : 0x01
886+ } )
887+ }
803888 }
804889
805890 function dismount ( ) {
806891 if ( bot . vehicle ) {
807- bot . _client . write ( 'steer_vehicle' , {
808- sideways : 0.0 ,
809- forward : 0.0 ,
810- jump : 0x02
811- } )
892+ if ( bot . supportFeature ( 'newPlayerInputPacket' ) ) {
893+ bot . _client . write ( 'player_input' , {
894+ inputs : {
895+ jump : true
896+ }
897+ } )
898+ } else {
899+ bot . _client . write ( 'steer_vehicle' , {
900+ sideways : 0.0 ,
901+ forward : 0.0 ,
902+ jump : 0x02
903+ } )
904+ }
812905 } else {
813906 bot . emit ( 'error' , new Error ( 'dismount: not mounted' ) )
814907 }
0 commit comments