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

const emit_sound = {
    onTick(event) {
        const block = event.block;
        const { x, y, z } = block.location;
        if (block.typeId === "furnideco:rustic.ceiling_fan") {
            block.dimension.playSound("furnideco.fan", { x: x, y: y, z: z });
        } else if (block.typeId === "furnideco:rustic.clock") {
            block.dimension.playSound("furnideco.tick", { x: x, y: y, z: z });
        } else if (block.typeId === "furnideco:rustic.fire_pit") {
            block.dimension.playSound("fire.fire", { x: x, y: y, z: z });
        }
    }
};

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