import { BlockPermutation, system, world } from "@minecraft/server";
import { SettingsHandler } from "./settings";
export function fireSpongePlace(block) {
    // Check if fire sponge is enabled
    if (!SettingsHandler.isSpongeEnabled("fireSponge")) {
        const dimension = world.getDimension(block.dimension.id);
        dimension.runCommand(`setblock ${block.location.x} ${block.location.y} ${block.location.z} air destroy`);
        // Notify nearby players
        const nearbyPlayers = dimension.getPlayers({ location: block.location, maxDistance: 10 });
        for (const player of nearbyPlayers) {
            player.sendMessage("§cFire Sponge is disabled in settings!");
        }
        return;
    }
    const position = block.location;
    const players = world.getDimension(block.dimension.id).getEntities({ type: "minecraft:player", location: position, maxDistance: 15 });
    if (players.length > 0) {
        for (const player of players) {
            player.extinguishFire(true);
        }
    }
    for (let x = -15; x <= 15; x++) {
        for (let y = -15; y <= 15; y++) {
            for (let z = -15; z <= 15; z++) {
                const targetY = position.y + y;
                // Skip positions below y -63 (world boundary)
                if (targetY < -63) {
                    continue;
                }
                const targetBlock = block.dimension.getBlock({ x: position.x + x, y: targetY, z: position.z + z });
                if (targetBlock && targetBlock.typeId === "minecraft:fire") {
                    targetBlock.setPermutation(BlockPermutation.resolve("minecraft:air"));
                }
            }
        }
    }
    world.getDimension(block.dimension.id).playSound("extinguish.candle", position);
    world.getDimension(block.dimension.id).spawnParticle("wildphire_spg:fire_sponge_particle", { x: position.x + 0.5, y: position.y, z: position.z + 0.5 });
    system.runTimeout(() => {
        world.getDimension(block.dimension.id).runCommand(`setblock ${position.x} ${position.y} ${position.z} air destroy`);
    }, 40);
}
