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 FillerNumberCodeBlockUpdateTickProcedure {
	public static void execute(LevelAccessor world, double x, double y, double z) {
		double sx = 0;
		double sy = 0;
		double sz = 0;
		boolean isBiggerFirstX = false;
		boolean isBiggerFirstY = false;
		boolean isBiggerFirstZ = false;
		isBiggerFirstX = GetNBTNumberSystemProcedure.execute(world, x, y, z, "x1Pos") > GetNBTNumberSystemProcedure.execute(world, x, y, z, "x2Pos");
		isBiggerFirstY = GetNBTNumberSystemProcedure.execute(world, x, y, z, "y1Pos") > GetNBTNumberSystemProcedure.execute(world, x, y, z, "y2Pos");
		isBiggerFirstZ = GetNBTNumberSystemProcedure.execute(world, x, y, z, "z1Pos") > GetNBTNumberSystemProcedure.execute(world, x, y, z, "z2Pos");
		sx = GetNBTNumberSystemProcedure.execute(world, x, y, z, "x1Pos");
		sy = GetNBTNumberSystemProcedure.execute(world, x, y, z, "y1Pos");
		sz = GetNBTNumberSystemProcedure.execute(world, x, y, z, "z1Pos");
		while (!(sx == GetNBTNumberSystemProcedure.execute(world, x, y, z, "x2Pos") + (isBiggerFirstX ? -1 : 1))) {
			while (!(sy == GetNBTNumberSystemProcedure.execute(world, x, y, z, "y2Pos") + (isBiggerFirstY ? -1 : 1))) {
				while (!(sz == GetNBTNumberSystemProcedure.execute(world, x, y, z, "z2Pos") + (isBiggerFirstZ ? -1 : 1))) {
					SetNBTNumberSystemProcedure.execute(world, sx, sy, sz, GetNBTNumberSystemProcedure.execute(world, GetXOffsetSystemProcedure.execute(x, 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)), "Back"), GetYOffsetSystemProcedure.execute(y, 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)), "Back"), GetZOffsetSystemProcedure.execute(z, 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)), "Back"), GetNBTTextSystemProcedure.execute(world, x, y, z, "getNBT")), GetNBTTextSystemProcedure.execute(world, x, y, z, "setNBT"));
					sz = isBiggerFirstZ ? sz - 1 : sz + 1;
				}
				sy = isBiggerFirstY ? sy - 1 : sy + 1;
				sz = GetNBTNumberSystemProcedure.execute(world, x, y, z, "z1Pos");
			}
			sx = isBiggerFirstX ? sx - 1 : sx + 1;
			sy = GetNBTNumberSystemProcedure.execute(world, x, y, z, "y1Pos");
			sz = GetNBTNumberSystemProcedure.execute(world, x, y, z, "z1Pos");
		}
	}
}
