import { world } from '@minecraft/server';

const emit_particles = {
    onTick(event) {
        const block = event.block;
        const { x, y, z } = block.location;
        if (block.typeId === "furnideco:rustic.chandelier" || block.typeId === "furnideco:rustic.lamp") {
            block.dimension.spawnParticle("furnideco:sparkles", { x: x + 0.5, y: y + 0.0, z: z + 0.5 });
        } else if (block.typeId === "furnideco:rustic.television") {
            block.dimension.spawnParticle("furnideco:smooth_wave", { x: x + 0.5, y: y + 0.1, z: z + 0.5 });
        }
    }
};

world.beforeEvents.worldInitialize.subscribe(({ blockComponentRegistry }) => {
    blockComponentRegistry.registerCustomComponent(
        "furnideco:emit_particles",
        emit_particles
    );
});