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;

public class FrozenTreeAdditionalGenerationConditionProcedure {
	public static boolean execute(LevelAccessor world, double x, double y, double z) {
		int height = Mth.nextInt(RandomSource.create(), 25, 100); 
		for (int i = 0 ; i < height ; i ++ ) {
			if (!world.getBlockState(BlockPos.containing(x, y + i , z)).canOcclude()) {
				world.setBlock(BlockPos.containing(x, y + i , z), Blocks.DARK_OAK_WOOD.defaultBlockState(), 3);
			}
			float dx = Mth.nextFloat(RandomSource.create(), -0.3f, 0.3f); 
			float dz = Mth.nextFloat(RandomSource.create(), -0.3f, 0.3f); 
			for (int j = 0 ; j < (height - i)/2 ; j++){
				if (!world.getBlockState(BlockPos.containing(x+dx*j, y + i , z+dz*j)).canOcclude()) {
					world.setBlock(BlockPos.containing(x+dx*j, y + i , z+dz*j), Blocks.DARK_OAK_WOOD.defaultBlockState(), 3);
				}
				for (int xx = -1 ; xx < 2 ; xx ++) {
					for (int yy = -1 ; yy < 2 ; yy ++){
						for (int zz = -1 ; zz < 2 ; zz ++){
							if (!world.getBlockState(BlockPos.containing(x+xx+dx*j, y + i+yy, z+zz+dz*j)).canOcclude()) {
								if (Mth.nextInt(RandomSource.create(), 1, 4) == 2) {
									world.setBlock(BlockPos.containing(x+xx+dx*j, y + i +yy , z+zz+dz*j), Blocks.ICE.defaultBlockState(), 3);
								}
							}
						}
					}
				}
			}

			for (int xx = -1 ; xx < 2 ; xx ++) {
				for (int yy = -1 ; yy < 2 ; yy ++){
					for (int zz = -1 ; zz < 2 ; zz ++){
						if (!world.getBlockState(BlockPos.containing(x+xx, y + i+yy, z+zz)).canOcclude()) {
							if (Mth.nextInt(RandomSource.create(), 1, 4) == 2) {
								world.setBlock(BlockPos.containing(x+xx, y + i +yy , z+zz), Blocks.ICE.defaultBlockState(), 3);
							}
						}
					}
				}
			}


		}
		return true;
	}

}
