package net.mcreator.puzzle_code.procedures;

import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.core.Direction;
import net.minecraft.core.BlockPos;

public class TransferNumberCodeBlockUpdateTickProcedure {
	public static void execute(LevelAccessor world, double x, double y, double z) {
		Direction blockDirection = Direction.NORTH;
		if (!GetNBTLogicSystemProcedure.execute(world, x, y, z, "isDisabled")) {
			blockDirection = new Object() {
				public Direction getDirection(BlockPos pos) {
					BlockState _bs = world.getBlockState(pos);
					Property<?> property = _bs.getBlock().getStateDefinition().getProperty("facing");
					if (property != null && _bs.getValue(property) instanceof Direction _dir)
						return _dir;
					else if (_bs.hasProperty(BlockStateProperties.AXIS))
						return Direction.fromAxisAndDirection(_bs.getValue(BlockStateProperties.AXIS), Direction.AxisDirection.POSITIVE);
					else if (_bs.hasProperty(BlockStateProperties.HORIZONTAL_AXIS))
						return Direction.fromAxisAndDirection(_bs.getValue(BlockStateProperties.HORIZONTAL_AXIS), Direction.AxisDirection.POSITIVE);
					return Direction.NORTH;
				}
			}.getDirection(BlockPos.containing(x, y, z));
			SetNBTNumberSystemProcedure.execute(world, GetXOffsetSystemProcedure.execute(x, blockDirection, "Front"), GetYOffsetSystemProcedure.execute(y, blockDirection, "Front"), GetZOffsetSystemProcedure.execute(z, blockDirection, "Front"),
					GetNBTNumberSystemProcedure.execute(world, GetXOffsetSystemProcedure.execute(x, blockDirection, "Back"), GetYOffsetSystemProcedure.execute(y, blockDirection, "Back"), GetZOffsetSystemProcedure.execute(z, blockDirection, "Back"),
							GetNBTTextSystemProcedure.execute(world, x, y, z, "getNBT")),
					GetNBTTextSystemProcedure.execute(world, x, y, z, "setNBT"));
		}
	}
}
