#Does Anyone Know How to Check what item is in the players mainhand?

1 messages · Page 1 of 1 (latest)

desert yew
#

i was thinking something like this player.getComponent(`minecraft:equippable`).getEquipment(`mainhand`)

uncut maple
#

mainhand -> Mainhand

desert yew
#

doesnt work

#
    let player = event.damagingEntity
    let mob = event.hurtEntity
    let item = player.getComponent(`minecraft:equippable`).getEquipment(`Mainhand`)
    if (item.typeId == `sb:skeleton_sword`) {
        mob.addEffect(`poison`,5,{amplifier: 1, showParticles: true})
    }
})```
torn matrix
#
world.afterEvents.entityHurt.subscribe(event => {
    let player = event.damagingEntity
    let mob = event.hurtEntity
    let item = player.getComponent(`minecraft:equippable`).getEquipment(`Mainhand`)
    if (item.typeId == `sb:skeleton_sword`) {
        mob.addEffect(`poison`,5,{amplifier: 1, showParticles: true})
    }
})```
steel wolfBOT
torn matrix
#
world.afterEvents.entityHurt.subscribe(event => {
    let player = event.damageSource.damagingEntity
    let mob = event.hurtEntity
    let item = player.getComponent(`minecraft:equippable`).getEquipment(`Mainhand`)
    if (item.typeId == `sb:skeleton_sword`) {
        mob.addEffect(`poison`,5,{amplifier: 1, showParticles: true})
    }
})
steel wolfBOT
# torn matrix ```js world.afterEvents.entityHurt.subscribe(event => { let player = event.d...

Debug result for [code](#1341467831857840249 message)

Compiler Result

Compiler found 1 errors:

<REPL0>.js:4:73 - error TS2345: Argument of type '"Mainhand"' is not assignable to parameter of type 'EquipmentSlot'.

4     let item = player.getComponent(`minecraft:equippable`).getEquipment(`Mainhand`)
                                                                          ~~~~~~~~~~

Lint Result

There are no errors from ESLint.

weak jay
#

event.damageSource

#

.damagingEntity

torn matrix
torn matrix
weak jay
#

then it will not throw error

#

EquipmentSlot.Mainhand

desert yew
#

thx