PlayerEvents.loggedIn(event => {
    if (!event.player.persistentData.healthFix_v2) {
        event.player.maxHealth = 20
        event.player.health = 20
        event.player.persistentData.healthFix_v2 = true
    }
})

PlayerEvents.tick(event => {
    const { player, level } = event
    if (player.age % 20 !== 0 || !player.isAlive()) return

    // CLEANSE A5R1 (Unbreakable Curse)
    if (player.potionEffects.isActive("libraryferret:unbreakable_curse")) {
        player.potionEffects.remove("libraryferret:unbreakable_curse")
    }

    if (player.exhaustion > 0) player.exhaustion *= 0.5

    if (player.health < player.maxHealth) {
        if (player.persistentData.allowHealAt && level.time < player.persistentData.allowHealAt) return
        let food = player.foodLevel
        if (food >= 11) {
            player.heal(1.0)
        } else if (food >= 1 && player.age % 60 === 0) {
            player.heal(1.0)
        }
    }
})

EntityEvents.hurt(event => {
    if (event.entity.isPlayer()) {
        event.entity.persistentData.allowHealAt = event.level.time + 200
    }
})