#Does Anyone Know How to Check what item is in the players mainhand?
1 messages · Page 1 of 1 (latest)
mainhand -> Mainhand
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})
}
})```
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})
}
})```
Debug result for [code](#1341467831857840249 message)
Compiler Result
Compiler found 1 errors:
[36m<REPL0>.js[0m:[33m2[0m:[33m24[0m - [31merror[0m[30m TS2339: [0mProperty 'damagingEntity' does not exist on type 'EntityHurtAfterEvent'.
[7m2[0m let player = event.damagingEntity
[7m [0m [31m ~~~~~~~~~~~~~~[0m
Lint Result
There are no errors from ESLint.
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})
}
})
Debug result for [code](#1341467831857840249 message)
Compiler Result
Compiler found 1 errors:
[36m<REPL0>.js[0m:[33m4[0m:[33m73[0m - [31merror[0m[30m TS2345: [0mArgument of type '"Mainhand"' is not assignable to parameter of type 'EquipmentSlot'.
[7m4[0m let item = player.getComponent(`minecraft:equippable`).getEquipment(`Mainhand`)
[7m [0m [31m ~~~~~~~~~~[0m
Lint Result
There are no errors from ESLint.
@desert yew try this
Yea I solved that
And then this seems like a problem with typescript so it doesn't matter
This might work
use Enums if you can 😭
then it will not throw error
EquipmentSlot.Mainhand
thx