package projectzombie.tiles;

import gl_engine.vec.Vec2i;
import projectzombie.entity.Entity;
import projectzombie.entity.particle.ParticleWater;
import projectzombie.entity.player.EntityPlayer;
import projectzombie.init.Items;
import projectzombie.init.Models;
import projectzombie.items.ItemTool;
import projectzombie.items.ItemToolType;
import projectzombie.items.modifier.ItemModifierMeta;
import projectzombie.model.Model;
import projectzombie.util.ItemStack;
import projectzombie.util.TileState;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;

public class TileWater extends Tile
{

	public TileWater() {
		this.slowness = 0.5;
		this.unbreakable = true;
		this.hardness = 800;
	}
	
	@Override
	public void onWalkedOn(Chunk chunk, Layer layer, Vec2i pos, Entity entity, TileState state)
	{
		// Call super
		super.onWalkedOn(chunk, layer, pos, entity, state);
		
		if(entity.getVelocity().xz().length() > 1/64.0) {
			layer.spawnEntity(new ParticleWater(entity.getPos(), entity.getVelocity()));
		}
	}
	
	@Override
	public boolean onActivated(Layer layer, Vec2i tpos, Entity entity, TileState state) {
		super.onActivated(layer, tpos, entity, state);
		
		if(entity instanceof EntityPlayer) {
			((EntityPlayer) entity).rehydrate();
		}
		
		return true;
	}
	
	@Override
	public boolean canTileBreak(TileState state, ItemStack stack, ItemTool tool) {
		return (tool != null && tool.toolType(stack) == ItemToolType.SHOVEL);
	}
	
	@Override
	public boolean canTileSpeedBreak(TileState state, ItemStack stack, ItemTool tool) {
		return canTileBreak(state, stack, tool);
	}
	
	@Override
	public boolean doBreak(Layer layer, Chunk chunk, TileState state, Vec2i pos) {
		return false;
	}
	
	@Override
	public ItemStack[] getTileDrops(TileState state) {
		return new ItemStack[] {
				new ItemStack(Items.ROCK, 2, new ItemModifierMeta(3)),
		};
	}
	
	@Override
	public Model getModel(byte meta) {
		return Models.TILE_WATER;
	}
	
	@Override
	public double getResistance(TileState state) {
		return 0.5;
	}
	
	@Override
	public double getSlipperiness(TileState state) {
		return 0.9;
	}

}
