package net.mcreator.puzzle_code.procedures;

import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.Entity;
import net.minecraft.network.chat.Component;

import net.mcreator.puzzle_code.network.PuzzleCodeModVariables;

public class NBTVerifierItemInHandTickProcedure {
	public static void execute(LevelAccessor world, Entity entity) {
		if (entity == null)
			return;
		{
			PuzzleCodeModVariables.PlayerVariables _vars = entity.getData(PuzzleCodeModVariables.PLAYER_VARIABLES);
			_vars.NBTVerifierXPosBlock = entity.level().clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos()
					.getX();
			_vars.syncPlayerVariables(entity);
		}
		{
			PuzzleCodeModVariables.PlayerVariables _vars = entity.getData(PuzzleCodeModVariables.PLAYER_VARIABLES);
			_vars.NBTVerifierYPosBlock = entity.level().clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos()
					.getY();
			_vars.syncPlayerVariables(entity);
		}
		{
			PuzzleCodeModVariables.PlayerVariables _vars = entity.getData(PuzzleCodeModVariables.PLAYER_VARIABLES);
			_vars.NBTVerifierZPosBlock = entity.level().clip(new ClipContext(entity.getEyePosition(1f), entity.getEyePosition(1f).add(entity.getViewVector(1f).scale(5)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, entity)).getBlockPos()
					.getZ();
			_vars.syncPlayerVariables(entity);
		}
		if ((entity.getData(PuzzleCodeModVariables.PLAYER_VARIABLES).NBTVerifierVariableType).equals("Text")) {
			{
				PuzzleCodeModVariables.PlayerVariables _vars = entity.getData(PuzzleCodeModVariables.PLAYER_VARIABLES);
				_vars.NBTVerifierCurrentValue = GetNBTTextSystemProcedure.execute(world, entity.getData(PuzzleCodeModVariables.PLAYER_VARIABLES).NBTVerifierXPosBlock, entity.getData(PuzzleCodeModVariables.PLAYER_VARIABLES).NBTVerifierYPosBlock,
						entity.getData(PuzzleCodeModVariables.PLAYER_VARIABLES).NBTVerifierZPosBlock, entity.getData(PuzzleCodeModVariables.PLAYER_VARIABLES).NBTVerifierNBT);
				_vars.syncPlayerVariables(entity);
			}
		} else if ((entity.getData(PuzzleCodeModVariables.PLAYER_VARIABLES).NBTVerifierVariableType).equals("Number")) {
			{
				PuzzleCodeModVariables.PlayerVariables _vars = entity.getData(PuzzleCodeModVariables.PLAYER_VARIABLES);
				_vars.NBTVerifierCurrentValue = ""
						+ GetNBTNumberSystemProcedure.execute(world, entity.getData(PuzzleCodeModVariables.PLAYER_VARIABLES).NBTVerifierXPosBlock, entity.getData(PuzzleCodeModVariables.PLAYER_VARIABLES).NBTVerifierYPosBlock,
								entity.getData(PuzzleCodeModVariables.PLAYER_VARIABLES).NBTVerifierZPosBlock, entity.getData(PuzzleCodeModVariables.PLAYER_VARIABLES).NBTVerifierNBT);
				_vars.syncPlayerVariables(entity);
			}
		} else if ((entity.getData(PuzzleCodeModVariables.PLAYER_VARIABLES).NBTVerifierVariableType).equals("Logic")) {
			{
				PuzzleCodeModVariables.PlayerVariables _vars = entity.getData(PuzzleCodeModVariables.PLAYER_VARIABLES);
				_vars.NBTVerifierCurrentValue = "" + GetNBTLogicSystemProcedure.execute(world, entity.getData(PuzzleCodeModVariables.PLAYER_VARIABLES).NBTVerifierXPosBlock, entity.getData(PuzzleCodeModVariables.PLAYER_VARIABLES).NBTVerifierYPosBlock,
						entity.getData(PuzzleCodeModVariables.PLAYER_VARIABLES).NBTVerifierZPosBlock, entity.getData(PuzzleCodeModVariables.PLAYER_VARIABLES).NBTVerifierNBT);
				_vars.syncPlayerVariables(entity);
			}
		}
		if (entity instanceof Player _player && !_player.level().isClientSide())
			_player.displayClientMessage(Component.literal(("Current Value: " + entity.getData(PuzzleCodeModVariables.PLAYER_VARIABLES).NBTVerifierCurrentValue)), true);
	}
}
