package com.harry9137.ct.event;

import com.harry9137.ct.achievement.AchievementIdiot;
import com.harry9137.ct.init.modItems;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentText;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import java.util.Iterator;
import java.util.List;

public class EntityDeathEventHooks {
    @SubscribeEvent
    public void onDeathDrops(LivingDropsEvent event){
        if(event.entityLiving instanceof EntityCreeper){
            EntityItem item = new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, new ItemStack(modItems.itemCreepLeaf, 1));
            if(((EntityCreeper)event.entity).getPowered()){
                item = new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, new ItemStack(modItems.itemChargedCreepLeaf, 1));
            }
            event.drops.add(item);
        }
        else if(event.entityLiving.getDisplayName().equals("Harry9137")){
            if(event.source.getEntity() instanceof EntityPlayer){
                EntityPlayer badperson = (EntityPlayer)event.source.getEntity();
                badperson.addChatMessage(new ChatComponentText("§4§lYou Don't Know What You've Done..."));
            }
        }
    }
    @SubscribeEvent
    public void onDeath(LivingDeathEvent event){
        if(event.entity instanceof EntityPlayer && event.source.damageType.equals("explosion.player") && event.source.getSourceOfDamage().getDisplayName().equals(event.entity.getDisplayName())){
            ((EntityPlayer) event.entity).addStat(AchievementIdiot.IdiotAchievement, 1);
        }
    }
}