package com.zivilon.cinder_loe.entity.npc.radagast;

import com.zivilon.cinder_loe.CinderLoE;

import lotr.common.LOTRAchievement;
import lotr.common.LOTRFoods;
import lotr.common.LOTRMod;
import lotr.common.entity.ai.LOTREntityAIAttackOnCollide;
import lotr.common.entity.ai.LOTREntityAIFollowHiringPlayer;
import lotr.common.entity.ai.LOTREntityAIHiredRemainStill;
import lotr.common.entity.npc.LOTREntityNPC;
import lotr.common.fac.LOTRFaction;
import lotr.common.quest.LOTRMiniQuest;
import lotr.common.quest.LOTRMiniQuestFactory;
import lotr.common.world.LOTRWorldChunkManager;
import lotr.common.world.biome.LOTRBiome;
import lotr.common.world.biome.variant.LOTRBiomeVariant;
import lotr.common.world.structure.LOTRChestContents;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IEntityLivingData;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIOpenDoor;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.ai.EntityAIWatchClosest2;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MathHelper;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.biome.WorldChunkManager;

public abstract class FangornAnimal extends LOTREntityNPC {
    public FangornAnimal(World world) {
        super(world);
        setSize(1.6F, 1.8F);
        getNavigator().setAvoidsWater(true);
        ((EntityLiving)this).tasks.addTask(0, (EntityAIBase)new EntityAISwimming((EntityLiving)this));
        ((EntityLiving)this).tasks.addTask(1, (EntityAIBase)new LOTREntityAIHiredRemainStill(this));
        ((EntityLiving)this).tasks.addTask(2, (EntityAIBase)new LOTREntityAIAttackOnCollide(this, 1.6D, false));
        ((EntityLiving)this).tasks.addTask(3, (EntityAIBase)new LOTREntityAIFollowHiringPlayer(this));
        ((EntityLiving)this).tasks.addTask(4, (EntityAIBase)new EntityAIWander(this, 1.0D));
        ((EntityLiving)this).tasks.addTask(5, (EntityAIBase)new EntityAIWatchClosest2((EntityLiving)this, EntityPlayer.class, 8.0F, 0.02F));
        ((EntityLiving)this).tasks.addTask(6, (EntityAIBase)new EntityAIWatchClosest2((EntityLiving)this, LOTREntityNPC.class, 5.0F, 0.02F));
        ((EntityLiving)this).tasks.addTask(7, (EntityAIBase)new EntityAIWatchClosest((EntityLiving)this, EntityLiving.class, 8.0F, 0.02F));
        ((EntityLiving)this).tasks.addTask(8, (EntityAIBase)new EntityAILookIdle((EntityLiving)this));
        addTargetTasks(true);
    }

    public boolean canWorldGenSpawnAt(int i, int j, int k, LOTRBiome biome, LOTRBiomeVariant variant) {
        int trees = biome.decorator.getVariantTreesPerChunk(variant);
        return (trees >= 1);
    }

    public LOTRFaction getFaction() {
        return LOTRFaction.FANGORN;
    }

    public float getAlignmentBonus() {
        return 0.0F;
    }

	public boolean getCanSpawnHere() {
	    WorldChunkManager worldChunkMgr = ((Entity)this).worldObj.getWorldChunkManager();
	    if (worldChunkMgr instanceof LOTRWorldChunkManager) {
			int i = MathHelper.floor_double(((Entity)this).posX);
			int j = MathHelper.floor_double(((Entity)this).boundingBox.minY);
			int k = MathHelper.floor_double(((Entity)this).posZ);
			LOTRBiome biome = (LOTRBiome)((Entity)this).worldObj.getBiomeGenForCoords(i, k);
			LOTRBiomeVariant variant = ((LOTRWorldChunkManager)worldChunkMgr).getBiomeVariantAt(i, k);
			return (super.getCanSpawnHere() && canWorldGenSpawnAt(i, j, k, biome, variant));
	    } 
	    return super.getCanSpawnHere();
	}
    

}
