package common.item;

import java.util.List;

import common.color.TextColor;
import common.entity.npc.EntityNPC;
import common.model.Transforms;
import common.util.BlockPos;
import common.util.ExtMath;
import common.util.Facing;
import common.util.Vec3;
import common.world.World;
import common.world.AWorldServer;

public abstract class ItemWand extends Item {
	public ItemWand() {
		this.maxStackSize = 1;
		this.setTab(CheatTab.tabTools);
	}

//	public boolean canBreakBlocks() {
//		return false;
//	}
//
//	public final boolean canUseInAir() {
//		return true;
//	}

    public boolean hasEffect(ItemStack stack) {
        return true;
    }
    
//    public boolean ignoresBlocks() {
//        return true;
//    }
    
//    public boolean itemInteractionForEntity(ItemStack stack, EntityNPC playerIn, EntityLiving target)
//    {
//    	if(playerIn.worldObj.client)
//			return true;
//    	this.onUse(stack, (EntityNPCMP)playerIn, (IWorldServer)playerIn.worldObj, new Vec3(target.posX, target.posY + target.height / 2.0, target.posZ));
//        return true;
//    }
    
	public final boolean onAction(ItemStack stack, EntityNPC player, World world, ItemControl control, BlockPos block) {
		if(control == ItemControl.SECONDARY && !world.client && block == null) {
			BlockPos vec = world.getBlockTrace(player, this.getRange(stack, player));
			if(vec != null)
				this.onUse(stack, player, (AWorldServer)world, new Vec3(
						ExtMath.floord(vec.getX()) + 0.5, ExtMath.floord(vec.getY()) + 1.0, ExtMath.floord(vec.getZ()) + 0.5));
		}
		return control == ItemControl.SECONDARY;
	}

	public final boolean onItemUse(ItemStack stack, EntityNPC player, World world, BlockPos pos, Facing side, float hitX, float hitY, float hitZ) {
		if(world.client)
			return true;
//		EntityNPCMP entity = (EntityNPCMP)player;
		if(pos != null) {
//			pos = side.getAxisDirection() == AxisDirection.NEGATIVE ? pos.offset(side) : pos;
	    	this.onUse(stack, player, (AWorldServer)world, new Vec3(pos.getX() + hitX, pos.getY() + hitY, pos.getZ() + hitZ));
		}
		return true;
	}
	
	public void addInformation(ItemStack stack, EntityNPC playerIn, List<String> tooltip)
    {
		tooltip.add(TextColor.DGREEN + "Reichweite: " + TextColor.GREEN + this.getRange(stack, playerIn) + " Blöcke");
    }
	
//    public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
//		if(attacker.worldObj.client)
//			return true;
//    	this.onUse(stack, (EntityNPCMP)attacker, (IWorldServer)attacker.worldObj, new Vec3(target.posX, target.posY + target.height / 2.0, target.posZ));
//        return true;
//    }

	public abstract int getRange(ItemStack stack, EntityNPC player);
	public abstract void onUse(ItemStack stack, EntityNPC player, AWorldServer world, Vec3 vec);

    public Transforms getTransform() {
    	return Transforms.TOOL;
    }
}
