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

world.beforeEvents.worldInitialize.subscribe(initEvent => {
  initEvent.blockComponentRegistry.registerCustomComponent('pa:escotilla', {
    onPlayerInteract: e => {
      const isOpen = e.block.permutation.getState("pa:open");
      const sound = "ancient_debris";
      e.block.setPermutation(e.block.permutation.withState("pa:open", !isOpen));
      e.dimension.playSound(sound, e.block.center(), { pitch: 0.9, volume: 0.9 });
    },
  });
});
