package common.block;

import common.enchantment.EnchantmentHelper;
import common.entity.npc.EntityNPC;
import common.init.Blocks;
import common.init.Config;
import common.item.CheatTab;
import common.item.ItemStack;
import common.material.Material;
import common.model.BlockLayer;
import common.rng.Random;
import common.tileentity.TileEntity;
import common.util.BlockPos;
import common.world.LightType;
import common.world.State;
import common.world.World;
import common.world.AWorldServer;

public class BlockIce extends BlockBreakable
{
    public BlockIce()
    {
        super(Material.ice, false);
        this.slipperiness = 0.98F;
        this.setTickRandomly();
        this.setTab(CheatTab.tabNature);
    }

    public BlockLayer getBlockLayer()
    {
        return BlockLayer.TRANSLUCENT;
    }

    public void harvestBlock(World worldIn, EntityNPC player, BlockPos pos, State state, TileEntity te)
    {
//        player.triggerAchievement(StatRegistry.mineBlockStatArray[BlockRegistry.getIdFromBlock(this)]);

        if (this.canSilkHarvest() && EnchantmentHelper.getSilkTouchModifier(player))
        {
            ItemStack itemstack = this.createStackedBlock(state);

            if (itemstack != null)
            {
                spawnAsEntity(worldIn, pos, itemstack);
            }
        }
        else
        {
            if (worldIn.doesWaterVaporize(pos))
            {
                worldIn.setBlockToAir(pos);
                return;
            }

            int i = EnchantmentHelper.getFortuneModifier(player);
            this.dropBlockAsItem(worldIn, pos, state, i);
            Material material = worldIn.getState(pos.down()).getBlock().getMaterial();

            if (material.blocksMovement() || material.isLiquid())
            {
                worldIn.setState(pos, Blocks.flowing_water.getState());
            }
        }
    }

    /**
     * Returns the quantity of items to drop on block destruction.
     */
    public int quantityDropped(Random random)
    {
        return 0;
    }

    public void updateTick(AWorldServer worldIn, BlockPos pos, State state, Random rand)
    {
        if (Config.iceMelt && ((worldIn.getLightFor(LightType.BLOCK, pos) > 11 - this.getLightOpacity()) || !worldIn.canFreezeAt(pos)))
        {
            if (worldIn.doesWaterVaporize(pos))
            {
                worldIn.setBlockToAir(pos);
            }
            else
            {
                this.dropBlockAsItem(worldIn, pos, worldIn.getState(pos), 0);
                worldIn.setState(pos, Blocks.water.getState());
            }
        }
    }

    public int getMobilityFlag()
    {
        return 0;
    }
}
