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

/**
 * Evento onRandomTick del componente weatherControlComponent.
 * Addon: Electrical Creativity BP
 * @param {{block: Block, dimension: Dimension}} event
 */
export const weatherControlOnRandomTickEvent = ({ block, dimension }) => {
    try {
        let permutation = block.permutation;
        const chargeState = permutation.getState('nps_ec:charge');

        if (permutation.getState('nps_ec:power') && chargeState !== 4) {
            if (Math.random() < 0.4) {
                permutation = permutation.withState('nps_ec:charge', chargeState + 1);
                block.setPermutation(permutation);
            }
        }
    } catch { }
}