package common.block.natural;

import common.biome.Biome;
import common.block.Block;
import common.block.Material;
import common.init.Blocks;
import common.item.CheatTab;
import common.rng.Random;
import common.util.BlockPos;
import common.vars.Vars;
import common.world.State;
import common.world.AWorldServer;

public class BlockBlackenedDirt extends Block
{
    public BlockBlackenedDirt()
    {
        super(Material.LOOSE);
        this.setTickRandomly();
        this.setTab(CheatTab.NATURE);
    }

    public void updateTick(AWorldServer worldIn, BlockPos pos, State state, Random rand)
    {
        if (Vars.darkDirtSpread)
        {
            for (int i = 0; i < 4; i++)
            {
                BlockPos blockpos = pos.add(rand.zrange(3) - 1, rand.zrange(5) - 3, rand.zrange(3) - 1);
                Block block = worldIn.getState(blockpos.up()).getBlock();
                State iblockstate = worldIn.getState(blockpos);

                if (iblockstate.getBlock() == Blocks.dirt)
                {
                    worldIn.setState(blockpos, Blocks.blackened_dirt.getState());
                }
                else if (iblockstate.getBlock() == Blocks.grass && worldIn.getLightFromNeighbors(blockpos.up()) >= 2 && block.getLightOpacity() <= 6)
                {
                    worldIn.setState(blockpos, Blocks.blackened_soil.getState());
                    worldIn.setBiome(blockpos, Biome.BLACKENED);
                }
                else if (iblockstate.getBlock() == Blocks.stone && rand.chance(25))
                {
                    worldIn.setState(blockpos, Blocks.blackened_stone.getState());
                }
            }
        }
    }
}
