package com.alxnns1.essemancy.entity;

import com.alxnns1.essemancy.entity.ai.AIRandomFly;
import com.alxnns1.essemancy.entity.ai.AIWatchClosest;
import com.alxnns1.essemancy.entity.ai.EsseMoveHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityFlying;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.ai.EntityAIWatchClosest2;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

import java.util.Random;

/**
 * Created by Alex on 22/11/2016.
 */
public class EntityEssence extends EntityFlying {
    public EntityEssence(World worldIn) {
        super(worldIn);
        this.moveHelper = new EsseMoveHelper(this);
        this.tasks.addTask(0, new AIRandomFly(this));
        this.tasks.addTask(0, new AIWatchClosest(this, EntityPlayer.class, 16.0F));
    }

    public void setBaseAttributes(double hp, double spd, double knckbck){
        this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(hp);
        this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(spd);
        this.getEntityAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(knckbck);
    }

    public void spawnParticle(World world, Vec3d pos, double spd, double off, Random rand) {
        double particleSpeed = spd;
        double x = pos.xCoord;
        double y = pos.yCoord + off;
        double z = pos.zCoord;
        double vx = (rand.nextDouble() * particleSpeed) - (particleSpeed/2);
        double vy = (rand.nextDouble() * particleSpeed) - (particleSpeed/2);
        double vz = (rand.nextDouble() * particleSpeed) - (particleSpeed/2);
        EnumParticleTypes type = EnumParticleTypes.CLOUD;
        world.spawnParticle(type, x, y, z, vx, vy, vz);
    }
}
