#how2fix error in entityDeath event when the entity is an item entity?
1 messages · Page 1 of 1 (latest)
send code
world.afterEvents.entityDie.subscribe(ev => {
switch (ev.deadEntity.typeId) {
case "minecraft:sheep": {
ev.deadEntity.runCommandAsync("say hi");
break;
}
}
});
also this error is given for projectile entity
bro wdym the code legit works?
use 2nd parameter
?
world.afterEvents.entityDie.subscribe(e => {
const d = e.deadEntity
//code
}, { entityTypes:['minecraft:sheep','minecraft:player'] })
@harsh turret the code works perfectly
I will try later
just add ? (optional chaining operator) to safely access deadEntity.typeId without an error.
ev.deadEntity?.typeId
That wasn't the case before
And doesn't make sense
/kill some random animals and it won't complain but if there are some item or projectile it will give error for those specific entities
cus animals triggers when they die
and they have "dying animation"
thats enoug time for 'deadEntity' to be defined in afterEvent
Nah that shouldn't matter
as well as call their properties
this is no good
i need to run specific code for each animal i want
i dont really want to refactor my code