package hmggirlfront.world;

import java.util.Random;

import hmggirlfront.mod_GirlFront;
import hmggirlfront.event.level.WorldDifficultyLevel_new;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLeaves;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;

public class WorldBlockBase extends WorldGenerator {

	public boolean flag = false;
	public Block block;
	public int id;

	public WorldBlockBase(int bl) {
		//this.flag = flag;
		this.id = bl;
	}

	@Override
	public boolean generate(World par1World, Random p_180709_2_, BlockPos pos) {

		int par1 = pos.getX();
		int par2 = pos.getY();
		int par3 = pos.getZ();

		if (id == 100) {
			par1World.setBlockState(new BlockPos(par1 + 0, par2 + 1, par3 + 0),
					mod_GirlFront.bdoll_supplies.getDefaultState(), 2);
		}
		
    	if(par1World.getBlockState(new BlockPos(par1, par2-1, par3)).getBlock() instanceof BlockLeaves
    			|| par1World.getBlockState(new BlockPos(par1, par2-1, par3)).getBlock() == Blocks.AIR)
		{
    		for(int q = 0; q < 10; ++q) {
    			if(!(par1World.getBlockState(new BlockPos(par1, par2 - 1 - q, par3)).getBlock() instanceof BlockLeaves)
    					&& par1World.getBlockState(new BlockPos(par1, par2 - 1 - q, par3)).getBlock() != Blocks.AIR) {
    				par2 = par2 - 1 - q;
    				break;
    			}
    		}
		}
		
		/*if (par1World.getBlockState(new BlockPos(par1, par2 - 1, par3)).getBlock() == Blocks.GRASS
				|| par1World.getBlockState(new BlockPos(par1, par2 - 1, par3)).getBlock() == Blocks.SAND
				|| par1World.getBlockState(new BlockPos(par1, par2 - 1, par3)).getBlock() == Blocks.WATER
				|| par1World.getBlockState(new BlockPos(par1, par2 - 1, par3)).getBlock() == Blocks.NETHERRACK
				|| par1World.getBlockState(new BlockPos(par1, par2 - 1, par3)).getBlock() == Blocks.END_STONE
				|| par1World.getBlockState(new BlockPos(par1, par2 - 1, par3)).getBlock() == Blocks.TALLGRASS) */
		{
			
			if (id == 200) {
				int dd = p_180709_2_.nextInt(4);
				if (dd == 1) {
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.b_goods_tank_break.getDefaultState(), 2);
				} else {
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.b_goods_ibc01_break.getDefaultState(), 2);
				}
			}
			
			if (id == 0) {
				int dd = p_180709_2_.nextInt(8);
				if (dd == 1) {
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_munitionsdepot.getDefaultState(), 2);
				} else if (dd == 2) {
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_fieldhospital.getDefaultState(), 2);
				}
				else if (dd == 3) {
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_helipad.getDefaultState(), 2);
				}
				else if (dd == 4) {
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_substation.getDefaultState(), 2);
				}
				else if (dd == 5) {
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_wastecollection.getDefaultState(), 2);
				}
				else if (dd == 6) {
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_materials.getDefaultState(), 2);
				}
				else{
					if(WorldDifficultyLevel_new.getLevel() >= 10) {
						par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
								mod_GirlFront.base_antennabase.getDefaultState(), 2);
					}else {
						par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
								mod_GirlFront.base_materials.getDefaultState(), 2);
					}
				}
			}
			if (id == 21) {
				int dd = p_180709_2_.nextInt(7);
				if (dd == 1) {
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_bunker.getDefaultState(), 2);
				} else if (dd == 2) {
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_helipad_de.getDefaultState(), 2);
				} else if (dd == 3) {
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_oilwell.getDefaultState(), 2);
				}
				else if (dd == 4) {
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_desert_camp.getDefaultState(), 2);
				}
				else{
					if(WorldDifficultyLevel_new.getLevel() >= 10) {
						par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
								mod_GirlFront.base_antennabase_de.getDefaultState(), 2);
					}else {
						par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
								mod_GirlFront.base_desert_camp.getDefaultState(), 2);
					}
				}
			}
			if (id == 22) {
				int dd = p_180709_2_.nextInt(4);
				if (dd == 1) {
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_snowforest_camp.getDefaultState(), 2);
				} else if (dd == 2) {
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_snow_camp2.getDefaultState(), 2);
				}
				else{
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_snow_camp.getDefaultState(), 2);
				}
			}
			if (id == 23) {
				int dd = p_180709_2_.nextInt(4);
				if (dd == 1) {
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_helipad_mt.getDefaultState(), 2);
				} else if (dd == 2) {
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_coalmine.getDefaultState(), 2);
				}
				else{
					if(WorldDifficultyLevel_new.getLevel() >= 10) {
						par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
								mod_GirlFront.base_antennabase_mt.getDefaultState(), 2);
					}else {
						par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
								mod_GirlFront.base_coalmine.getDefaultState(), 2);
					}
				}
			}
			if (id == 24) {
				int dd = p_180709_2_.nextInt(4);
				if (dd == 1) {
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_helipad_se.getDefaultState(), 2);
				} else if (dd == 2) {
					if(WorldDifficultyLevel_new.getLevel() >= 10) {
						par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
								mod_GirlFront.base_containership.getDefaultState(), 2);
					}else {
						par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
								mod_GirlFront.base_helipad_se.getDefaultState(), 2);
					}
				} else if (dd == 2) {
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_wastecarrier.getDefaultState(), 2);
				}
				else{
					if(WorldDifficultyLevel_new.getLevel() >= 10) {
						par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
								mod_GirlFront.base_offshorecrane.getDefaultState(), 2);
					}else {
						par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
								mod_GirlFront.base_wastecarrier.getDefaultState(), 2);
					}
				}
			}
			
			
			if (id == 1) {
				{
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_headquarters.getDefaultState(), 2);
				}
			}
			if (id == 2) {
				{
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_forest_base.getDefaultState(), 2);
				}
			}
			if (id == 3) {
				int dd = p_180709_2_.nextInt(2);
				if (dd == 1) {
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_oil_complex.getDefaultState(), 2);
				}
				else{
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_desert_base.getDefaultState(), 2);
				}
			}
			if (id == 4) {
				{
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_amusement.getDefaultState(), 2);
				}
			}
			if (id == 8) {
				{
					par1World.setBlockState(new BlockPos(par1 + 0, 70, par3 + 0),
							mod_GirlFront.base_observation_base.getDefaultState(), 2);
				}
			}
			
			
			
			if (id == 7) {
				{
					par1World.setBlockState(new BlockPos(par1 + 0, par2 + 0, par3 + 0),
							mod_GirlFront.base_sea_launch.getDefaultState(), 2);
				}
			}
			if (id == 9) {
				{
					par1World.setBlockState(new BlockPos(par1 + 0, 80, par3 + 0),
							mod_GirlFront.base_missile_silo.getDefaultState(), 2);
				}
			}

		}
		return true;

	}
}
