import { system, world } from "@minecraft/server";

system.beforeEvents.startup.subscribe((initEvent) => {
    initEvent.blockComponentRegistry.registerCustomComponent("rustic:custom_trapdoor", {
        onPlayerInteract: e => {
            const { player, block, dimension, face, faceLocation } = e;
            const isOpen = block.permutation.getState("r:open");
            const sound = isOpen ? "close.wooden_trapdoor" : "open.wooden_trapdoor";
    
            block.setPermutation(block.permutation.withState("r:open", !isOpen));
    
            dimension.playSound(sound, block.center(), {
                pitch: 0.9,
                volume: 0.9,
            });
        },
    });
});