package net.mcreator.cawezsmantletostratus.procedures;

import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.util.RandomSource;
import net.minecraft.util.Mth;
import net.minecraft.core.BlockPos;

import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.util.RandomSource;
import net.minecraft.util.Mth;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.state.BlockState;

public class CeilingCrystalProcedure {
	public static boolean execute(LevelAccessor world, double x, double y, double z) {
		int flavour = Mth.nextInt(RandomSource.create(), 0, 12);
		for (int i = 1 ; i < 100; i++) {
			if (world.getBlockState(BlockPos.containing(x, y+i, z)).canOcclude()) {
				int height = i * 1 / 3;
				for (int j = 0; j < height ; j++) {

					if (world.getBlockState(BlockPos.containing(x, y+i-j-1, z)).canOcclude()) { return true;}

					world.setBlock(BlockPos.containing(x, y + i-j, z), getBlock(flavour), 3);

					if (Mth.nextInt(RandomSource.create(), 1, 8)==2){
						world.setBlock(BlockPos.containing(x+1, y + i-j, z), Blocks.LIGHT.defaultBlockState(), 3);
						world.setBlock(BlockPos.containing(x-1, y + i-j, z), Blocks.LIGHT.defaultBlockState(), 3);
						world.setBlock(BlockPos.containing(x, y + i-j, z+1), Blocks.LIGHT.defaultBlockState(), 3);
						world.setBlock(BlockPos.containing(x, y + i-j, z-1), Blocks.LIGHT.defaultBlockState(), 3);
					}
				}

				return true;
			}
			
		}
		return true;
	}

	

	private static BlockState getBlock(int flavour){
		switch(flavour) {
			case 0:
				return Blocks.WHITE_STAINED_GLASS.defaultBlockState();
			case 1:
				return Blocks.BLACK_STAINED_GLASS.defaultBlockState();

			case 2:
				return Blocks.RED_STAINED_GLASS.defaultBlockState();

			case 3:
				return Blocks.ORANGE_STAINED_GLASS.defaultBlockState();

			case 4:
				return Blocks.YELLOW_STAINED_GLASS.defaultBlockState();

			case 5:
				return Blocks.LIME_STAINED_GLASS.defaultBlockState();

			case 6:
				return Blocks.GREEN_STAINED_GLASS.defaultBlockState();

			case 7:
				return Blocks.CYAN_STAINED_GLASS.defaultBlockState();
				
			case 8:
				return Blocks.LIGHT_BLUE_STAINED_GLASS.defaultBlockState();
							case 9:
				return Blocks.PURPLE_STAINED_GLASS.defaultBlockState();
							case 10:
				return Blocks.MAGENTA_STAINED_GLASS.defaultBlockState();
							case 11:
				return Blocks.PINK_STAINED_GLASS.defaultBlockState();
			}
				return Blocks.RED_STAINED_GLASS.defaultBlockState();

	}
}
