package net.mcreator.puzzle_code.procedures;

import net.neoforged.neoforge.event.level.BlockEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.bus.api.Event;

import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.LevelAccessor;

import net.mcreator.puzzle_code.network.PuzzleCodeModVariables;

import javax.annotation.Nullable;

@EventBusSubscriber
public class ABlockIsBrokenGlobalTriggerProcedure {
	@SubscribeEvent
	public static void onBlockBreak(BlockEvent.BreakEvent event) {
		execute(event, event.getLevel(), event.getPos().getX(), event.getPos().getY(), event.getPos().getZ(), event.getState());
	}

	public static void execute(LevelAccessor world, double x, double y, double z, BlockState blockstate) {
		execute(null, world, x, y, z, blockstate);
	}

	private static void execute(@Nullable Event event, LevelAccessor world, double x, double y, double z, BlockState blockstate) {
		PuzzleCodeModVariables.MapVariables.get(world).ABlockIsBrokenBlockstate = blockstate;
		PuzzleCodeModVariables.MapVariables.get(world).syncData(world);
		PuzzleCodeModVariables.MapVariables.get(world).ABlockIsBrokenX_Pos = x;
		PuzzleCodeModVariables.MapVariables.get(world).syncData(world);
		PuzzleCodeModVariables.MapVariables.get(world).ABlockIsBrokenY_Pos = y;
		PuzzleCodeModVariables.MapVariables.get(world).syncData(world);
		PuzzleCodeModVariables.MapVariables.get(world).ABlockIsBrokenZ_Pos = z;
		PuzzleCodeModVariables.MapVariables.get(world).syncData(world);
	}
}
