import { system } from "@minecraft/server";
import { digitalBlockOnEntityFallOnEvent } from "../../events/blocks/digitalBlock/onEntityFallOnEvent";
import { digitalBlockOnPlayerInteractEvent } from "../../events/blocks/digitalBlock/onPlayerInteractEvent";
import { digitalBlockOnStepOnEvent } from "../../events/blocks/digitalBlock/onStepOnEvent";

/**
 * Componente: nps_ec:digital_block
 * Descripción: description
 * Addon: Electrical Creativity BP
 */

export const digitalBlockComponent = {
    onEntityFallOn: digitalBlockOnEntityFallOnEvent,
	onPlayerInteract: digitalBlockOnPlayerInteractEvent,
	onStepOn: digitalBlockOnStepOnEvent,
	onTick: ({block}) => {
		try {
			if (block.permutation.getState("nps_ec:active") == 1 && block.permutation.getState("nps_ec:power") == 0) {
				const job = system.runInterval(() => {
					try {
						block.setPermutation(block.permutation.withState("nps_ec:active", 0));
						system.clearRun(job);
					} catch {
						system.clearRun(job)
					}
				}, 109)

				if (!block.permutation.getState("nps_ec:active")) {
					system.clearRun(job);
				}
			}
		} catch { }
	}
}