import { offsetPos } from "../util/dirUtils";
import { hasAnyBlockAround, spawnParticleOnBlockFace } from "../util/miscUtils";
import { McBlocks } from "../reg/mcBlocks";
import { suppEvents } from "../suppEventHandler";
suppEvents.subscribeOnPistonPushed((event) => {
    if (!event.isExpanding) {
        const pistonDir = event.pistonDir;
        for (const block of event.attachedBlocks) {
            let typeId = block.typeId;
            const isFlintBlock = typeId == "razz_sup:flint_block" /* SuppBlocks.FlintBlock */;
            const isIronBlock = typeId == McBlocks.Iron;
            if (isFlintBlock || isIronBlock) {
                const target = offsetPos(block, pistonDir, 1);
                //check all block around this
                const foundDir = hasAnyBlockAround(target, pistonDir, isFlintBlock ? McBlocks.Iron : "razz_sup:flint_block" /* SuppBlocks.FlintBlock */);
                if (foundDir) {
                    //place fire
                    if (target.isAir) {
                        target.dimension.setBlockType(target.location, McBlocks.Fire);
                    }
                    //TODO: add custom crit particle here
                    spawnParticleOnBlockFace(target, foundDir, "minecraft:critical_hit_emitter", 1);
                    target.dimension.playSound("fire.ignite", target.center());
                }
            }
        }
    }
});
