import * as mc from "@minecraft/server";
import * as utils from "../utils/index";
import { HeartAbilityManager } from "../systems/index";
const tntCount = 5;
export async function tnt_blockAbility(player) {
    utils.mclog(`tnt_block`);
    HeartAbilityManager.addInvulnerability(player, 'noExplosionDamage');
    HeartAbilityManager.addInvulnerabilityToFriends('noExplosionDamage');
    mc.world.playSound('ability.tnt.fall', player.location);
    let tntRemaining = tntCount;
    await utils.waitForLoopEvent(5, () => {
        const location = { x: player.location.x + utils.getRandomInteger(-5, 5), y: player.location.y + 10, z: player.location.z + utils.getRandomInteger(-5, 5) };
        const tnt = player.dimension.spawnEntity('ldz:tnt_ability_fake_tnt', location);
        if (player.hasTag('InSpawnHouse')) {
            tnt.triggerEvent('InSpawnHouse');
        }
        else {
            tnt.triggerEvent('default');
        }
        mc.world.playSound('custom.pop', location);
        tntRemaining--;
        return tntRemaining < 0;
    });
    utils.waitForEvent(120, () => {
        utils.mclog('Finished');
        HeartAbilityManager.removeInvulnerability(player, 'noExplosionDamage');
        HeartAbilityManager.removeInvulnerabilityFromFriends('noExplosionDamage');
    });
}
