package common.block;

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

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

    public void updateTick(AWorldServer worldIn, BlockPos pos, State state, Random rand)
    {
        if (worldIn.getLightFromNeighbors(pos.up()) < 2 && worldIn.getState(pos.up()).getBlock().getLightOpacity() > 6)
        {
        	if(Config.darkSoilDecay)
        		worldIn.setState(pos, Blocks.blackened_dirt.getState());
        }
        else if (Config.darkSoilSpread && worldIn.getLightFromNeighbors(pos.up()) >= 1)
        {
            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 || iblockstate.getBlock() == Blocks.grass || iblockstate.getBlock() == Blocks.blackened_dirt) && worldIn.getLightFromNeighbors(blockpos.up()) >= 2 && block.getLightOpacity() <= 6)
                {
                    worldIn.setState(blockpos, Blocks.blackened_soil.getState());
                }
            }
        }
    }

    public Item getItemDropped(State state, Random rand, int fortune)
    {
        return Blocks.blackened_dirt.getItemDropped(Blocks.blackened_dirt.getState(), rand, fortune);
    }

    public Model getModel(ModelProvider provider, String name, State state) {
    	return provider.getModel("blackened_dirt").add().d().u("blackened_soil_top").nswe("blackened_soil_side");
    }
}
