onEvent("entity.hurt", event => {
let hurtEntity = event.entity
let entityType = hurtEntity.getType()
console.log(`entityType: ${entityType}`);
if (entityType == "minecraft:ender_dragon") {
let player = event.source.getActual()
console.log(`player: ${player}`);
if (player) {
if (player.isPlayer()) {
let lastgate = hurtEntity.persistentData.lastretaliationgate
player.tell(`lastgate : ${lastgate}`)
let hpPercent = (hurtEntity.getHealth() / hurtEntity.getMaxHealth()) * 100
player.tell(`hpPercent: ${hpPercent}`)
if (lastgate > 1 && hpPercent <= lastgate) {
//dragon summons a reinforcement gate at 100%, 75%, 50% and 25% health
let x = Math.floor(player.x)
let y = Math.floor(player.y)
let z = Math.floor(player.z)
player.tell(`coord: ${x}, ${y}, ${z}`)
let command = `execute in minecraft:the_end run open_gateway ${x} ${y} ${z} gateways:dragon_retaliation`
player.tell("The Dragon roars in anger in response to your attack, and summons reinforcements")
hurtEntity.persistentData.lastretaliationgate -= 25
player.getServer().runCommandSilent(command)
}
}
}
}
})
The code's intention is that it would spawn a gateway (from gateways to eternity) on specific hp intervals during the ender dragon bossfight, specifically 25%, 50%, and 75%. No errors are thrown back at me but at the same time it isn't working. Anything wrong with the code that could be causing it?