import { BlockPermutation, world } from "@minecraft/server";
import { SettingsHandler } from "./settings";
let feedingSpongeMap = new Map();
export function feedingSpongePulse(block) {
    // Check if feeding sponge is enabled
    if (!SettingsHandler.isSpongeEnabled("feedingSponge")) {
        block.setPermutation(BlockPermutation.resolve("minecraft:air"));
        // Notify nearby players
        const nearbyPlayers = world.getDimension(block.dimension.id).getPlayers({ location: block.location, maxDistance: 10 });
        for (const player of nearbyPlayers) {
            player.sendMessage("§cFeeding Sponge is disabled in settings!");
        }
        return;
    }
    const blockId = `${block.location.x}_${block.location.y}_${block.location.z}`;
    if (!feedingSpongeMap.has(blockId)) {
        feedingSpongeMap.set(blockId, Date.now() + (15 * 1000));
    }
    else {
        const time = feedingSpongeMap.get(blockId);
        if (time != undefined && time < Date.now()) {
            feedingSpongeMap.delete(blockId);
            block.setPermutation(BlockPermutation.resolve("minecraft:air"));
        }
    }
    const players = world.getDimension(block.dimension.id).getEntities({ maxDistance: 15, type: "minecraft:player", location: block.location });
    if (players.length == 0)
        return;
    for (const player of players) {
        player.addEffect("minecraft:saturation", 2, { amplifier: 1 });
        // Spawn feeding particle on block every time saturation is triggered
        world.getDimension(block.dimension.id).spawnParticle("wildphire_spg:feeding_sponge_particle", { x: block.location.x + 0.5, y: block.location.y, z: block.location.z + 0.5 });
    }
    world.getDimension(block.dimension.id).playSound("random.eat", block.location);
    world.getDimension(block.dimension.id).spawnParticle("wildphire_spg:feeding_ring_sponge_particle", { x: block.location.x + 0.5, y: block.location.y, z: block.location.z + 0.5 });
}
