import { Entity } from "@minecraft/server";

/**
 * 
 * @param {Entity} damaged 
 */
export function onDamage(damaged) {
    damaged?.applyKnockback(0, 0, 0, 1);
    //One shot creepers
    if (damaged?.typeId === `minecraft:creeper`) {
        damaged?.kill()
    }
};
/**
 * 
 * @param {Entity} damaged 
 * @param {Number} damage 
 */
export function onHurt(damaged, damage) {
    const maxBattery = 100;
    const battery = damaged?.getProperty(`cy_cr:battery`) ?? 0;
    const leftBattery = maxBattery - battery;

    damaged?.setProperty(`cy_cr:battery`, Math.max(battery - (Math.floor(damage / 2)), leftBattery))
}