@@ -724,8 +724,9 @@ export class Entities {
724724
725725 // check if entity has armor
726726 if ( entity . equipment ) {
727- this . addItemModel ( e , 'left' , entity . equipment [ 0 ] )
728- this . addItemModel ( e , 'right' , entity . equipment [ 1 ] )
727+ const isPlayer = entity . type === 'player'
728+ this . addItemModel ( e , isPlayer ? 'right' : 'left' , entity . equipment [ 0 ] , isPlayer )
729+ this . addItemModel ( e , isPlayer ? 'left' : 'right' , entity . equipment [ 1 ] , isPlayer )
729730 addArmorModel ( this . worldRenderer , e , 'feet' , entity . equipment [ 2 ] )
730731 addArmorModel ( this . worldRenderer , e , 'legs' , entity . equipment [ 3 ] , 2 )
731732 addArmorModel ( this . worldRenderer , e , 'chest' , entity . equipment [ 4 ] )
@@ -1019,11 +1020,13 @@ export class Entities {
10191020 return texture
10201021 }
10211022
1022- addItemModel ( entityMesh : SceneEntity , hand : 'left' | 'right' , item : Item ) {
1023- const parentName = `bone_${ hand } item`
1023+ addItemModel ( entityMesh : SceneEntity , hand : 'left' | 'right' , item : Item , isPlayer = false ) {
1024+ const bedrockParentName = `bone_${ hand } item`
1025+ const itemName = `custom_item_${ hand } `
1026+
10241027 // remove existing item
10251028 entityMesh . traverse ( c => {
1026- if ( c . parent ?. name . toLowerCase ( ) === parentName ) {
1029+ if ( c . name === itemName ) {
10271030 c . removeFromParent ( )
10281031 if ( c [ 'additionalCleanup' ] ) c [ 'additionalCleanup' ] ( )
10291032 }
@@ -1035,7 +1038,7 @@ export class Entities {
10351038 } )
10361039 if ( itemObject ?. mesh ) {
10371040 entityMesh . traverse ( c => {
1038- if ( c . name . toLowerCase ( ) === parentName ) {
1041+ if ( c . name . toLowerCase ( ) === bedrockParentName || c . name === ` ${ hand } Arm` ) {
10391042 const group = new THREE . Object3D ( )
10401043 group [ 'additionalCleanup' ] = ( ) => {
10411044 // important: avoid texture memory leak and gpu slowdown
@@ -1051,7 +1054,18 @@ export class Entities {
10511054 group . rotation . y = Math . PI / 2
10521055 group . scale . multiplyScalar ( 2 )
10531056 }
1057+
1058+ // if player, move item below and forward a bit
1059+ if ( isPlayer ) {
1060+ group . position . y = - 8
1061+ group . position . z = 5
1062+ group . position . x = hand === 'left' ? 1 : - 1
1063+ group . rotation . x = Math . PI
1064+ }
1065+
10541066 group . add ( itemMesh )
1067+
1068+ group . name = itemName
10551069 c . add ( group )
10561070 }
10571071 } )
0 commit comments