@@ -43,8 +43,26 @@ function inject (bot, { hideErrors }) {
4343 bot . quickBarSlot = null
4444 bot . inventory = windows . createWindow ( 0 , 'minecraft:inventory' , 'Inventory' )
4545 bot . currentWindow = null
46- bot . heldItem = null
4746 bot . usingHeldItem = false
47+ Object . defineProperty ( bot , 'heldItem' , {
48+ get : function ( ) {
49+ return bot . inventory . slots [ bot . QUICK_BAR_START + bot . quickBarSlot ]
50+ }
51+ } )
52+
53+ bot . on ( 'spawn' , ( ) => {
54+ Object . defineProperty ( bot . entity , 'equipment' , {
55+ get : bot . supportFeature ( 'doesntHaveOffHandSlot' )
56+ ? function ( ) {
57+ return [ bot . heldItem , bot . inventory . slots [ 8 ] , bot . inventory . slots [ 7 ] ,
58+ bot . inventory . slots [ 6 ] , bot . inventory . slots [ 5 ] ]
59+ }
60+ : function ( ) {
61+ return [ bot . heldItem , bot . inventory . slots [ 45 ] , bot . inventory . slots [ 8 ] ,
62+ bot . inventory . slots [ 7 ] , bot . inventory . slots [ 6 ] , bot . inventory . slots [ 5 ] ]
63+ }
64+ } )
65+ } )
4866
4967 bot . _client . on ( 'entity_status' , ( packet ) => {
5068 if ( packet . entityId === bot . entity . id && packet . entityStatus === 9 && ! eatingTask . done ) {
@@ -364,9 +382,7 @@ function inject (bot, { hideErrors }) {
364382 }
365383
366384 function updateHeldItem ( ) {
367- bot . heldItem = bot . inventory . slots [ bot . QUICK_BAR_START + bot . quickBarSlot ]
368- bot . entity . heldItem = bot . heldItem
369- bot . emit ( 'heldItemChanged' , bot . entity . heldItem )
385+ bot . emit ( 'heldItemChanged' , bot . heldItem )
370386 }
371387
372388 function closeWindow ( window ) {
0 commit comments