package common.block;

import common.init.Blocks;
import common.init.Config;
import common.item.CheatTab;
import common.material.Material;
import common.rng.Random;
import common.util.BlockPos;
import common.world.State;
import common.world.AWorldServer;

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

    public void updateTick(AWorldServer worldIn, BlockPos pos, State state, Random rand)
    {
        if (Config.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());
                }
                else if (iblockstate.getBlock() == Blocks.stone && rand.chance(25))
                {
                    worldIn.setState(blockpos, Blocks.blackened_stone.getState());
                }
            }
        }
    }
}
