package common.block.natural;

import common.block.BlockTranslucent;
import common.block.Material;
import common.enchantment.EnchantmentHelper;
import common.entity.npc.EntityNPC;
import common.init.Blocks;
import common.item.CheatTab;
import common.item.ItemStack;
import common.rng.Random;
import common.tileentity.TileEntity;
import common.util.BlockPos;
import common.vars.Vars;
import common.world.LightType;
import common.world.State;
import common.world.World;
import common.world.AWorldServer;

public class BlockIce extends BlockTranslucent {
	public BlockIce() {
		super(Material.TRANSLUCENT);
		this.slipperiness = 0.98F;
		this.setTickRandomly();
		this.setTab(CheatTab.NATURE);
	}

	public void harvestBlock(World world, EntityNPC player, BlockPos pos, State state, TileEntity tile) {
		if(this.canSilkHarvest() && EnchantmentHelper.getSilkTouchModifier(player)) {
			ItemStack stack = this.createStackedBlock(state);
			if(stack != null)
				spawnAsEntity(world, pos, stack);
		}
		else {
			if(world.doesWaterVaporize(pos)) {
				world.setBlockToAir(pos);
				return;
			}
			int fortune = EnchantmentHelper.getFortuneModifier(player);
			this.dropBlockAsItem(world, pos, state, fortune);
			Material material = world.getState(pos.down()).getBlock().getMaterial();
			if(material.blocksMovement() || material.isLiquid())
				world.setState(pos, Blocks.flowing_water.getState());
		}
	}

	public int quantityDropped(Random rand) {
		return 0;
	}

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

	public int getMobilityFlag() {
		return 0;
	}
}
