import { system, world } from '@minecraft/server';
import { decrementStack, getOppositeDirection, DirectionType, cardinalSides } from './utils/helper';
import { directionToVector3 } from './utils/math';

world.beforeEvents.worldInitialize.subscribe(initEvent => {
  initEvent.blockComponentRegistry.registerCustomComponent('pa:puerta_de_valla', {
  onPlayerInteract: e => { let face = getOppositeDirection(e.face);

const isOpen = e.block.permutation.getState("pa:open");
const sound = isOpen ? "close.fence_gate" : "open.fence_gate";

e.block.setPermutation(e.block.permutation.withState("minecraft:cardinal_direction", face.toLowerCase()));
e.block.setPermutation(e.block.permutation.withState("pa:open", !isOpen));

e.dimension.playSound(sound, e.block.center(), {
    pitch: 0.9,
    volume: 0.9,
});
 },
});

});