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

/**
 * Evento del componente batteryPlaceComponent
 * @param {{previousBlock: BlockPermutation, dimension: Dimension, block: Block}} event 
 */
export const batteryPlaceEvent = ({previousBlock, dimension, block}) => {
    try {
        if(!block) return;

        if(block.typeId === 'minecraft:air') return
        const charge = parseInt(block.typeId.split('_')[3]);

        if (block.typeId.includes("nps_ec:battery")) {
            const permutation = BlockPermutation.resolve('nps_ec:battery', {'nps_ec:charge': charge})
            if(block.typeId === 'minecraft:air') return
            block.setPermutation(permutation);
        }
    } catch{}
}