package hmggirlfront.entity.vehicle;

import java.util.List;

import gvclib.mod_GVCLib;
import gvclib.entity.living.AI_TankSet;
import gvclib.entity.living.EntityGVCLivingBase;
import gvclib.entity.living.EntityMobVehicleBase;
import gvclib.entity.living.ISoldier;
import gvclib.entity.living.PL_TankMove;
import gvclib.event.GVCSoundEvent;
import gvclib.network.GVCLMessageKeyPressed;
import gvclib.network.GVCLPacketHandler;
import hmggirlfront.mod_GirlFront;
import hmggirlfront.entity.EntityDoll;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.passive.IAnimals;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

public class EntityVe_BIKE extends EntityMobVehicleBase
{

    public EntityVe_BIKE(World worldIn)
    {
        super(worldIn);
        this.setSize(1F, 1.4F);
        this.setcanDespawn(1);
        this.setVehicleLock(true);
        this.riddng_freehand = false;
        this.hud_icon = "hmggirlfront:textures/hud/apc.png";
        this.render_hud_information_2 = "R-Click:Zoom";
        this.render_hud_information_3 = "W/S-KEY:Throttle-UP/DWON";
        this.render_hud_information_4 = "A/D-KEY:TURN-RIGHT/LEFT";
        this.render_hud_information_5 = "V-KEY:ALLY-Boarding";
        this.render_hud_information_6 = "B-KEY:ALLY-Get off";
        vehicletype = 2;
        ridding_roteplayer = false;
        roodbreak = mod_GirlFront.cfg_vehicle_breakblock;
        this.spawn_item = mod_GirlFront.ve_bike;
        
        vehicle_ridding_nofire[0] = false;
        vehicle_ridding_nofire[1] = false;
        
        this.sp = 0.07F;
        this.turnspeed = 10F;
		this.ridding_invisible = false;
		this.riddng_opentop = true;
		this.renderhud = true;
		this.render_rader = false;
		this.thmax = 5F;
		this.thmin = -2F;
		this.thmaxa = 0.2F;
		this.thmina = -0.15F;
		this.stepHeight = 1.5F;
		this.riddng_maximum = 2;
		riddingx[0]=0.0D;
		riddingy[0]=0.8D;
		riddingz[0]=0.0D;
		{
			riddingx[1]=-1.0D;
			riddingy[1]=0.4D;
			riddingz[1]=-0.1D;
		}
		
		
		ridding_view_x=0F;
		ridding_view_y=-2F;
		ridding_view_z=-5F;
		
		antibullet_0 = 0.5F;
		antibullet_1 = 0.5F;
		antibullet_2 = 1.0F;
		antibullet_3 = 1.1F;
		this.ridding_damege = 0.5F;
		
		
    }

    protected void applyEntityAttributes()
    {
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(50D);
        this.getEntityAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(20D);
    }
    
    public boolean processInteract(EntityPlayer player, EnumHand hand)
    {
    	ItemStack itemstack = player.getHeldItem(hand);
        boolean flag = !itemstack.isEmpty();
        if(!itemstack.isEmpty()&& itemstack.getItem() == mod_GirlFront.idoll_parts)
        {
        	if(this.getHealth() < this.getMaxHealth()) {
				this.setHealth(this.getHealth() + 10);
    			itemstack.shrink(1);
    			this.playSound(SoundEvents.BLOCK_ANVIL_LAND, 5F, 2F);
			}
        	return true;
        }
        else{
        	super.processInteract(player, hand);
        	return true;
        }
        
    }
    
    public boolean spawn = false;
    public void onUpdate() {
		super.onUpdate();
		this.setcanDespawn(1);
		this.riddng_freehand = false;
		float f1 = this.rotationYawHead * (2 * (float) Math.PI / 360);
		this.roadattack();
		this.setcanDespawn(1);
		//this.typeHeli(GVCSoundEvent.sound_heli);
		this.setVehicleLock(true);
		
		this.ContMobRidding();
		
		
		if (this.canBeSteered() && this.getControllingPassenger() != null && this.getHealth() > 0.0F)
		{
			if(this.getControllingPassenger() instanceof EntityPlayer)
			{
				EntityPlayer entitylivingbase = (EntityPlayer) this.getControllingPassenger();
				this.setcanDespawn(1);
				//entitylivingbase.rotationYawHead = this.rotationYaw;
				//this.rotation  = entitylivingbase.rotationYawHead;
				//this.rotationp = this.rotationPitch = entitylivingbase.rotationPitch;
				Vec3d looked = entitylivingbase.getLookVec();
				PL_TankMove.movecar(entitylivingbase, this, sp, turnspeed);

				boolean left = mod_GVCLib.proxy.leftclick();
				boolean right = mod_GVCLib.proxy.rightclick();
				boolean jump = mod_GVCLib.proxy.jumped();
				boolean kx = mod_GVCLib.proxy.keyx();
				boolean kg = mod_GVCLib.proxy.keyg();
				boolean kc = mod_GVCLib.proxy.keyc();
				if (left) {
					GVCLPacketHandler.INSTANCE.sendToServer(new GVCLMessageKeyPressed(11, this.getEntityId()));
					this.server1 = true;
				}
				if (right) {
					GVCLPacketHandler.INSTANCE.sendToServer(new GVCLMessageKeyPressed(12, this.getEntityId()));
				}
				if (jump) {
					GVCLPacketHandler.INSTANCE.sendToServer(new GVCLMessageKeyPressed(13, this.getEntityId()));
				}
				if (kx) {
					GVCLPacketHandler.INSTANCE.sendToServer(new GVCLMessageKeyPressed(14, this.getEntityId()));
				}
				if (kg) {
					GVCLPacketHandler.INSTANCE.sendToServer(new GVCLMessageKeyPressed(15, this.getEntityId()));
				}
				if (kc) {
					GVCLPacketHandler.INSTANCE.sendToServer(new GVCLMessageKeyPressed(16, this.getEntityId()));
				}

				

				
			}//player
			else if(this.getControllingPassenger() instanceof EntityGVCLivingBase) {
				
			}
		}
		
		AI_TankSet.set2(this, GVCSoundEvent.sound_car, f1, sp, 0.1F);
		
    }

   
}