
triggerAnimation causes the game to crash
Hanwei233 opened this issue ยท 4 comments
Here are the crash logs:
https://pastebin.com/YjVstFPq
I want to play an animation when an entity is hurt, so I used triggerAnimation. However, the game crashes when the entity is hurt.
It may be that my code is wrong because I just used kubejs not long ago
My code:
event.addTriggerableAnimation("animation.mimic.die","death","DEFAULT")
if(!event.isMoving()){
event.thenPlay("animation.mimic.move")
}
return true;
})
.onHurt(entity => {
entity.triggerAnimation("MimicAnimation","death")
})
I used the latest 0.0.6, but the problem was not solved, I tried shooting the mimic to play the animation and the game crashed
New crash log:
https://pastebin.com/K6E3KEiM
The complete entity registration code:
StartupEvents.registry('entity_type', event => {
event.create("mimic","entityjs:mob")
.mobCategory("monster")
.sized(0.9,0.9)
.canBreatheUnderwater(true)
.mobType("undefined")
.addAnimationController("MimicAnimation", 1, event => {
event.addTriggerableAnimation("animation.mimic.hurt","hurt","DEFAULT")
if(!event.isMoving()){
event.thenPlay("animation.mimic.move")
}
return true;
})
.onHurt(entity => {
entity.triggerAnimation("MimicAnimation","hurt")
})
})
onHurt goes off of context so you'll have to do something like this
.onHurt(context => {
const { entity, damageAmount } = context
entity.triggerAnimation("MimicAnimation","hurt")
// Log the amount of damage received by the entity
console.log(damageAmount)
})
@hanweiyyds
theres actually full example scripts like this on the wiki page here -> https://github.com/liopyu/EntityJS/wiki/Entity-Registry#:~:text=Full%20Animal%20Entity%20Example%20Usage%201.20.1
another useful addon mod for this is probejs where it will show you typings as you hover over them, i explain how to install probejs in my kubejs tutorial video here -> https://youtu.be/xhJJbNJjics?t=87