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.state.BlockState;

public class CrystalgrowthAdditionalGenerationConditionProcedure {
	public static boolean execute(LevelAccessor world, double x, double y, double z) {

		if (Mth.nextInt(RandomSource.create(), 0, 4) != 1){
			int flavour = Mth.nextInt(RandomSource.create(), 0, 12);
	        for (int j = 0 ; j <  50 ; j++){
				double dx = Mth.nextDouble(RandomSource.create(), -1.0, 1.0);
				double dz = Mth.nextDouble(RandomSource.create(), -1.0, 1.0);
				int length= Mth.nextInt(RandomSource.create(), 0, 10);
		
				for (int i = 0 ; i<length ; i ++ ) {
					world.setBlock(BlockPos.containing(x + i * dx, y + i , z+ i * dz), getBlock(flavour), 3);
		        }
		        if (Mth.nextInt(RandomSource.create(), 0, 5) ==1) {y++;}
	        }
	    } else {
			for (int t = 1 ; t < 100 ; t++) {
				if (world.getBlockState(BlockPos.containing(x, y + t, z)).canOcclude()) {
		
			    	int flavour = Mth.nextInt(RandomSource.create(), 0, 12);
			        for (int j = 0 ; j <  50 ; j++){
						double dx = Mth.nextDouble(RandomSource.create(), -1.0, 1.0);
						double dz = Mth.nextDouble(RandomSource.create(), -1.0, 1.0);
						int length= Mth.nextInt(RandomSource.create(), 0, 10);
				
						for (int i = 0 ; i<length ; i ++ ) {
							world.setBlock(BlockPos.containing(x + i * dx, y - i + t , z+ i * dz), getBlock(flavour), 3);
				        }
				        if (Mth.nextInt(RandomSource.create(), 0, 5) ==1) {y--;}
			        }
			        return true;
				} 
	    }
	    }
		return true;
	}

	private static BlockState getBlock(int flavour){

		if ( Mth.nextInt(RandomSource.create(), 0, 50) == 1) { return Blocks.GLOWSTONE.defaultBlockState();}
		if ( Mth.nextInt(RandomSource.create(), 0, 3) != 1) { return Blocks.AMETHYST_BLOCK.defaultBlockState();}

		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();

	}
	
}
