package net.mcreator.puzzle_code.procedures;

import net.neoforged.neoforge.event.tick.LevelTickEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.bus.api.Event;

import net.minecraft.world.level.LevelAccessor;

import net.mcreator.puzzle_code.network.PuzzleCodeModVariables;
import net.mcreator.puzzle_code.PuzzleCodeMod;

import javax.annotation.Nullable;

@EventBusSubscriber
public class TimedSwichingBlockWorldUpdateProcedure {
	@SubscribeEvent
	public static void onWorldTick(LevelTickEvent.Post event) {
		execute(event, event.getLevel());
	}

	public static void execute(LevelAccessor world) {
		execute(null, world);
	}

	private static void execute(@Nullable Event event, LevelAccessor world) {
		double number1 = 0;
		double number2 = 0;
		if (PuzzleCodeModVariables.MapVariables.get(world).IsTimedSwitched) {
			PuzzleCodeMod.queueServerWork(80, () -> {
				PuzzleCodeModVariables.MapVariables.get(world).IsTimedSwitched = false;
				PuzzleCodeModVariables.MapVariables.get(world).syncData(world);
			});
		} else {
			PuzzleCodeMod.queueServerWork(80, () -> {
				PuzzleCodeModVariables.MapVariables.get(world).IsTimedSwitched = true;
				PuzzleCodeModVariables.MapVariables.get(world).syncData(world);
			});
		}
	}
}
