Search in sources :

Example 1 with EntityAIArrowAttack

use of net.minecraft.entity.ai.EntityAIArrowAttack in project ArsMagica2 by Mithion.

the class Disarm method applyEffectEntity.

@Override
public boolean applyEffectEntity(ItemStack stack, World world, EntityLivingBase caster, Entity target) {
    if (target instanceof EntityLightMage || target instanceof EntityDarkMage)
        return false;
    if (target instanceof EntityPlayer && (!AMCore.config.getDisarmAffectsPlayers() || (!world.isRemote && !MinecraftServer.getServer().isPVPEnabled())))
        return false;
    if (target instanceof EntityPlayer && ((EntityPlayer) target).getHeldItem() != null && !target.worldObj.isRemote) {
        if (EnchantmentHelper.getEnchantmentLevel(AMEnchantments.soulbound.effectId, ((EntityPlayer) target).getHeldItem()) > 0)
            return true;
        ((EntityPlayer) target).dropOneItem(true);
        return true;
    } else if (target instanceof EntityMob && ((EntityMob) target).getHeldItem() != null) {
        if (EnchantmentHelper.getEnchantmentLevel(AMEnchantments.soulbound.effectId, ((EntityMob) target).getHeldItem()) > 0)
            return true;
        if (!world.isRemote) {
            EntityItem item = new EntityItem(world);
            ItemStack dropstack = ((EntityMob) target).getHeldItem().copy();
            if (dropstack.getMaxDamage() > 0)
                dropstack.setItemDamage((int) Math.floor(dropstack.getMaxDamage() * (0.8f + (world.rand.nextFloat() * 0.19f))));
            item.setEntityItemStack(dropstack);
            item.setPosition(target.posX, target.posY, target.posZ);
            world.spawnEntityInWorld(item);
        }
        ((EntityMob) target).setCurrentItemOrArmor(0, null);
        ((EntityMob) target).setAttackTarget(caster);
        Iterator it = ((EntityMob) target).tasks.taskEntries.iterator();
        boolean removed = false;
        while (it.hasNext()) {
            EntityAITaskEntry task = (EntityAITaskEntry) it.next();
            if (task.action instanceof EntityAIArrowAttack) {
                it.remove();
                removed = true;
                break;
            }
        }
        if (removed) {
            ((EntityMob) target).tasks.addTask(5, new EntityAIAttackOnCollide((EntityCreature) target, 0.5, true));
            ((EntityMob) target).setCanPickUpLoot(true);
        }
    } else if (target instanceof EntityEnderman) {
        int blockID = ((EntityEnderman) target).getCarryingData();
        int meta = ((EntityEnderman) target).getCarryingData();
        if (blockID > 0) {
            ((EntityEnderman) target).setCarryingData(0);
            ItemStack dropstack = new ItemStack(Block.getBlockById(blockID), 1, meta);
            EntityItem item = new EntityItem(world);
            item.setEntityItemStack(dropstack);
            item.setPosition(target.posX, target.posY, target.posZ);
            world.spawnEntityInWorld(item);
        }
        ((EntityMob) target).setAttackTarget(caster);
    }
    return false;
}
Also used : EntityMob(net.minecraft.entity.monster.EntityMob) EntityAIAttackOnCollide(net.minecraft.entity.ai.EntityAIAttackOnCollide) EntityLightMage(am2.entities.EntityLightMage) EntityDarkMage(am2.entities.EntityDarkMage) EntityAIArrowAttack(net.minecraft.entity.ai.EntityAIArrowAttack) Iterator(java.util.Iterator) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) EntityEnderman(net.minecraft.entity.monster.EntityEnderman) EntityItem(net.minecraft.entity.item.EntityItem) EntityAITaskEntry(net.minecraft.entity.ai.EntityAITasks.EntityAITaskEntry)

Aggregations

EntityDarkMage (am2.entities.EntityDarkMage)1 EntityLightMage (am2.entities.EntityLightMage)1 Iterator (java.util.Iterator)1 EntityAIArrowAttack (net.minecraft.entity.ai.EntityAIArrowAttack)1 EntityAIAttackOnCollide (net.minecraft.entity.ai.EntityAIAttackOnCollide)1 EntityAITaskEntry (net.minecraft.entity.ai.EntityAITasks.EntityAITaskEntry)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityEnderman (net.minecraft.entity.monster.EntityEnderman)1 EntityMob (net.minecraft.entity.monster.EntityMob)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1