import { Block, Dimension } from "@minecraft/server";

/**
 * Evento del componente buttonReloadComponent
 * @param {{block: Block, dimension: Dimension}} event 
 */
export const buttonReloadEvent = ({ block, dimension }) => {
    try {
        if(!block) return;
        let permutation = block.permutation;
    
        if(block.typeId == 'nps_ec:iron_button' && !permutation.getState('nps_ec:state')) return;
        if(block.typeId == 'nps_ec:iron_button' && permutation.getState('nps_ec:state')) dimension.runCommand(`playsound iron.button @a ${block.x} ${block.y} ${block.z} 0.4`);
        permutation = permutation.withState('nps_ec:state', false);
        
    
        block.setPermutation(permutation);
    } catch{}
}