package hmggirlfront.biome;

import java.util.Random;

import hmggirlfront.mod_GirlFront;
import net.minecraft.block.Block;
import net.minecraft.block.BlockStaticLiquid;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
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 WorldGenRoad extends WorldGenerator
{
	
	public boolean houx = true;
	
	public WorldGenRoad(boolean hou)
    {
		houx = hou;
    }
	
    public boolean generate(World worldIn, Random rand, BlockPos position)
    {
    	int par1 = position.getX();
    	int par2 = position.getY();
    	int par3 = position.getZ();
    	/*if(worldIn.getBlockState(new BlockPos(par1, par2-1, par3)).getBlock() instanceof BlockStaticLiquid) {
    		return false;
    	}else */
    	{
    		if(houx) {
    			for(int x = 0; x < 16; ++x) {
        			for(int z = 0; z < 4; ++z) {
        				BlockPos bp = worldIn.getHeight(new BlockPos(par1 + x, 60 + rand.nextInt(100), par3 + z + 12));
        				if(!(worldIn.getBlockState(new BlockPos(par1 + x, bp.getY() - 1, par3 + z + 12)).getBlock() instanceof BlockStaticLiquid)) {
        					if(rand.nextInt(5) == 1) {
        						worldIn.setBlockState(new BlockPos(par1 + x, bp.getY() - 1, par3 + z + 12), mod_GirlFront.b_block_collapse.getDefaultState(), 2);
        					}else if(rand.nextInt(5) == 2 || rand.nextInt(5) == 3) {
        						worldIn.setBlockState(new BlockPos(par1 + x, bp.getY() - 1, par3 + z + 12), mod_GirlFront.b_block_collapse_grass.getDefaultState(), 2);
        					}
        					else {
        						worldIn.setBlockState(new BlockPos(par1 + x, bp.getY() - 1, par3 + z + 12), Blocks.STONEBRICK.getDefaultState(), 2);
        					}
        					
        				}
        			}
        		}
    		}else {
    			for(int x = 0; x < 4; ++x) {
        			for(int z = 0; z < 16; ++z) {
        				BlockPos bp = worldIn.getHeight(new BlockPos(par1 + x + 12, 60 + rand.nextInt(100), par3 + z));
        				if(!(worldIn.getBlockState(new BlockPos(par1 + x + 12, bp.getY() - 1, par3 + z)).getBlock() instanceof BlockStaticLiquid)) {
        					if(rand.nextInt(5) == 1) {
        						worldIn.setBlockState(new BlockPos(par1 + x + 12, bp.getY() - 1, par3 + z), mod_GirlFront.b_block_collapse.getDefaultState(), 2);
        					}else if(rand.nextInt(5) == 2 || rand.nextInt(5) == 3) {
        						worldIn.setBlockState(new BlockPos(par1 + x + 12, bp.getY() - 1, par3 + z), mod_GirlFront.b_block_collapse_grass.getDefaultState(), 2);
        					}
        					else {
        						worldIn.setBlockState(new BlockPos(par1 + x + 12, bp.getY() - 1, par3 + z), Blocks.STONEBRICK.getDefaultState(), 2);
        					}
        				}
        			}
        		}
    		}
        return true;
    	}
    }
}