package hmggirlfront.biome;

import java.util.Iterator;
import java.util.Random;

import hmggirlfront.mod_GirlFront;
import net.minecraft.entity.passive.EntityRabbit;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.feature.WorldGenDeadBush;
import net.minecraft.world.gen.feature.WorldGenSand;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class CollapseBiome extends Biome {
	
	private final CollapseBiome.Type type;
	
    public CollapseBiome(CollapseBiome.Type typeIn, Biome.BiomeProperties properties) {
        /*super(new Biome.Builder()
                .surfaceBuilder(SurfaceBuilder.DEFAULT, new SurfaceBuilderConfig(Blocks.END_STONE.getDefaultState(), Blocks.NETHERRACK.getDefaultState(), Blocks.LAVA.getDefaultState()))
                .precipitation(RainType.SNOW)
                .depth(0.0f)
                .scale(0.0f)
                .category(Category.DESERT)
                .downfall(1.0f)
                .temperature(1.2f))
                .waterColor(0xffffff)
                .waterFogColor(0x000000);
        DefaultBiomeFeatures.addLakes(this);
        this.addSpawn(EntityClassification.MONSTER, new SpawnListEntry(EntityType.field_226289_e_, 5, 1, 2));
        setRegistryName(Location.create("test_biome"));*/
    	//super(new Biome.BiomeProperties("Collapse").setBaseHeight(0.45F).setHeightVariation(0.3F).setTemperature(2.0F).setRainfall(0.0F).setRainDisabled());
    	super(properties);
    	
    	type = typeIn;
    	if (this.type == CollapseBiome.Type.DEEP)
        {
    		//this.setRegistryName(mod_GirlFront.MOD_ID, "Collapse");
    	       // this.spawnableCreatureList.add(new Biome.SpawnListEntry(EntityHorse.class, 5, 2, 6));
    	        //this.spawnableCreatureList.add(new Biome.SpawnListEntry(EntityDonkey.class, 1, 1, 3));
    	    	this.spawnableCreatureList.clear();
    	        this.topBlock = mod_GirlFront.b_block_collapse_grass.getDefaultState();
    	        this.fillerBlock = mod_GirlFront.b_block_collapse.getDefaultState();
    	        this.decorator.treesPerChunk = -999;
    	        this.decorator.deadBushPerChunk = 2;
    	        this.decorator.reedsPerChunk = 50;
    	        this.decorator.cactiPerChunk = 10;
    	        this.spawnableCreatureList.clear();
    	        this.spawnableMonsterList.clear();
    	        //this.spawnableCreatureList.add(new Biome.SpawnListEntry(EntityRabbit.class, 4, 2, 3));
    	        Iterator<Biome.SpawnListEntry> iterator = this.spawnableMonsterList.iterator();
        }else {
         	this.spawnableCreatureList.clear();
             this.topBlock = Blocks.GRASS.getDefaultState();
             this.fillerBlock = Blocks.DIRT.getDefaultState();
             this.decorator.treesPerChunk = 2;
             this.decorator.deadBushPerChunk = 2;
             this.decorator.reedsPerChunk = 50;
             this.decorator.cactiPerChunk = 10;
             this.spawnableCreatureList.clear();
             this.spawnableMonsterList.clear();
             Iterator<Biome.SpawnListEntry> iterator = this.spawnableMonsterList.iterator();
        }
    	
    	
    }
    
    
    @SideOnly(Side.CLIENT)
    public int getGrassColorAtPos(BlockPos pos)
    {
        /*double d0 = (double)MathHelper.clamp(this.getTemperature(pos), 0.0F, 1.0F);
        double d1 = (double)MathHelper.clamp(this.getRainfall(), 0.0F, 1.0F);
        return getModdedBiomeGrassColor(ColorizerGrass.getGrassColor(d0, d1));*/
    	 return getModdedBiomeGrassColor(0XEEEEAF);
    }
    
    public WorldGenerator sandGen = new WorldGenCollapse(mod_GirlFront.b_block_collapse_hv, 6);//mod_GirlFront.b_block_collapse_hv
    public boolean create = true;
    public void decorate(World worldIn, Random rand, BlockPos pos)
    {
    	create = true;
        if (this.type == CollapseBiome.Type.DEEP)
        {
        	{
            	int genX = pos.getX();
        		int genZ = pos.getZ();
        		int ran1 = 16;//896
            	
            	for (int i = 0; i < 2; ++i)
                {
                    int j = rand.nextInt(16) + 8;
                    int k = rand.nextInt(16) + 8;
                   // BlockPos bp = worldIn.getHeight(new BlockPos(j, 60 + rand.nextInt(100), k));
                   this.sandGen.generate(worldIn, rand, worldIn.getTopSolidOrLiquidBlock(pos.add(j, 0, k)));
                    //this.sandGen.generate(worldIn, rand, worldIn.getHeight(pos.add(j, 0, k)));
                }
            }
           /* for (int j3 = 0; j3 < 5; ++j3)
            {
                int k7 = rand.nextInt(16) + 8;
                int j11 = rand.nextInt(16) + 8;
                int l14 = worldIn.getHeight(new BlockPos(k7, 0, j11)).getY() * 2;

                if (l14 > 0)
                {
                    int i18 = rand.nextInt(l14);
                    (new WorldGenDeadBush()).generate(worldIn, rand, new BlockPos(k7, i18, j11));
                }
            }*/
            
            
            {
        		BlockPos bp = worldIn.getHeight(new BlockPos(pos.getX(), 0, pos.getZ()));
        		if(Math.abs(pos.getZ()) %32 == 0)
        		{
            		WorldGenRoad road = new WorldGenRoad(true);
            		road.generate(worldIn, rand, bp);
                }
        		if(Math.abs(pos.getX()) %48 == 0)
        		{
    				WorldGenRoad road = new WorldGenRoad(false);
        			road.generate(worldIn, rand, bp);
        		}
            }
            
            //for (int j3 = 0; j3 < 2; ++j3)
            if(rand.nextInt(2) == 0){
            	int j = rand.nextInt(16) + 8;
                int k = rand.nextInt(16) + 8;
        		BlockPos bp = worldIn.getHeight(pos.add(j, 0, k));
        		{
                    (new WorldGenDeadTree()).generate(worldIn, rand, bp);
                }
            }
           
            Building(worldIn, rand, pos, "ruin_building.txt", 10, 8, 8, 0, false);
            Building(worldIn, rand, pos, "ruin_bunker.txt", 20, 8, 8, 0, false);
           
            
            
            Building(worldIn, rand, pos, "co_bunker.txt", 20, 8, 8, -2, true);
            Building(worldIn, rand, pos, "co_bullet.txt", 25, 8, 8, -1, true);
            Building(worldIn, rand, pos, "co_ammochamber.txt", 40, 8, 8, -1, true);
            Building(worldIn, rand, pos, "co_camp.txt", 30, 8, 8, -1, true);
            
            
            Building(worldIn, rand, pos, "co_comb.txt", 100, 16, 16, -1, true);
            Building(worldIn, rand, pos, "co_base.txt", 150, 16, 16, -1, true);
            
            Building(worldIn, rand, pos, "ruin_house.txt", 99, 8, 8, 0, true);
            
        }
        else {
        	
        	{
            	int genX = pos.getX();
        		int genZ = pos.getZ();
        		int ran1 = 16;//896
            	
            	//for (int i = 0; i < 2; ++i)
        		if(rand.nextInt(3) == 0){
                    int j = rand.nextInt(16) + 8;
                    int k = rand.nextInt(16) + 8;
                   // BlockPos bp = worldIn.getHeight(new BlockPos(j, 60 + rand.nextInt(100), k));
                   this.sandGen.generate(worldIn, rand, worldIn.getTopSolidOrLiquidBlock(pos.add(j, 0, k)));
                    //this.sandGen.generate(worldIn, rand, worldIn.getHeight(pos.add(j, 0, k)));
                }
            }
        	
        	if(rand.nextInt(2) == 0){
            	int j = rand.nextInt(16) + 8;
                int k = rand.nextInt(16) + 8;
        		BlockPos bp = worldIn.getHeight(pos.add(j, 0, k));
        		{
                    (new WorldGenDeadTree()).generate(worldIn, rand, bp);
                }
            }
           
        	Building(worldIn, rand, pos, "ruin_building.txt", 10, 8, 8, 0, false);
            
            Building(worldIn, rand, pos, "ruin_bunker.txt", 20, 8, 8, 0, false);
            
            Building(worldIn, rand, pos, "co_bunker.txt", 20, 8, 8, -2, true);
            Building(worldIn, rand, pos, "co_ammochamber.txt", 40, 8, 8, -1, true);
           // Building(worldIn, rand, pos, "co_camp.txt", 30, 8, 8, -1, false);
        }
        
        super.decorate(worldIn, rand, pos);
    }
    
    public void Building(World worldIn, Random rand, BlockPos pos, String name, int ran, int xsize, int zsize, int offset, boolean air) {
    	if(create) {
    		WorldGen_Ruin ruin = new WorldGen_Ruin(name, xsize, zsize, offset, air);
        	int genX = pos.getX();
    		int genZ = pos.getZ();
    		int ran1 = 16;//896
    		BlockPos bp = worldIn.getHeight(new BlockPos(genX, 60 + rand.nextInt(100), genZ));
    		int genY = bp.getY(); //world.getChunksLowestHorizon(genX, genZ);
    		if(Math.abs(genX) %ran1 == 0 && Math.abs(genZ) %ran1 == 0  && genY > 60)
    		if(rand.nextInt(ran) == 0)
    		{
    			ruin.generate(worldIn, rand, pos);
    			create = false;
    		}
    	}
    }
    
    
    public static enum Type
    {
        NORMAL,
        DEEP;
    }
    
}