Search in sources :

Example 1 with EntityAITaskEntry

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

the class EntityUtilities method makeSummon_PlayerFaction.

public static void makeSummon_PlayerFaction(EntityCreature entityliving, EntityPlayer player, boolean storeForRevert) {
    if (isAIEnabled(entityliving) && !(entityliving instanceof IBossDisplayData) && ExtendedProperties.For(player).getCanHaveMoreSummons()) {
        if (storeForRevert)
            storedTasks.put(entityliving.getEntityId(), new ArrayList(entityliving.targetTasks.taskEntries));
        boolean addMeleeAttack = false;
        ArrayList<EntityAITaskEntry> toRemove = new ArrayList<EntityAITaskEntry>();
        for (Object task : entityliving.tasks.taskEntries) {
            EntityAITaskEntry base = (EntityAITaskEntry) task;
            if (base.action instanceof EntityAIAttackOnCollide) {
                toRemove.add(base);
                addMeleeAttack = true;
            }
        }
        entityliving.tasks.taskEntries.removeAll(toRemove);
        if (storeForRevert)
            storedAITasks.put(entityliving.getEntityId(), toRemove);
        if (addMeleeAttack) {
            float speed = entityliving.getAIMoveSpeed();
            if (speed <= 0)
                speed = 1.0f;
            entityliving.tasks.addTask(3, new EntityAIAttackOnCollide(entityliving, EntityMob.class, speed, true));
            entityliving.tasks.addTask(3, new EntityAIAttackOnCollide(entityliving, IMob.class, speed, true));
            entityliving.tasks.addTask(3, new EntityAIAttackOnCollide(entityliving, EntitySlime.class, speed, true));
        }
        entityliving.targetTasks.taskEntries.clear();
        entityliving.targetTasks.addTask(1, new EntityAIHurtByTarget(entityliving, true));
        entityliving.targetTasks.addTask(2, new EntityAINearestAttackableTarget(entityliving, EntityMob.class, 0, true, false, SummonEntitySelector.instance));
        entityliving.targetTasks.addTask(2, new EntityAINearestAttackableTarget(entityliving, EntitySlime.class, 0, true));
        entityliving.targetTasks.addTask(2, new EntityAINearestAttackableTarget(entityliving, EntityGhast.class, 0, true));
        if (!entityliving.worldObj.isRemote && entityliving.getAttackTarget() != null && entityliving.getAttackTarget() instanceof EntityPlayer)
            AMCore.proxy.addDeferredTargetSet(entityliving, null);
        if (entityliving instanceof EntityTameable) {
            ((EntityTameable) entityliving).setTamed(true);
            ((EntityTameable) entityliving).func_152115_b(player.getCommandSenderName());
        }
        entityliving.getEntityData().setBoolean(isSummonKey, true);
        ExtendedProperties.For(player).addSummon(entityliving);
    }
}
Also used : EntitySlime(net.minecraft.entity.monster.EntitySlime) ArrayList(java.util.ArrayList) EntityGhast(net.minecraft.entity.monster.EntityGhast) EntityAIHurtByTarget(net.minecraft.entity.ai.EntityAIHurtByTarget) EntityAINearestAttackableTarget(net.minecraft.entity.ai.EntityAINearestAttackableTarget) EntityMob(net.minecraft.entity.monster.EntityMob) EntityAIAttackOnCollide(net.minecraft.entity.ai.EntityAIAttackOnCollide) IMob(net.minecraft.entity.monster.IMob) IBossDisplayData(net.minecraft.entity.boss.IBossDisplayData) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityAITaskEntry(net.minecraft.entity.ai.EntityAITasks.EntityAITaskEntry) EntityTameable(net.minecraft.entity.passive.EntityTameable)

Example 2 with EntityAITaskEntry

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

the class EntityUtilities method revertAI.

public static boolean revertAI(EntityCreature entityliving) {
    int ownerID = getOwner(entityliving);
    Entity owner = entityliving.worldObj.getEntityByID(ownerID);
    if (owner != null && owner instanceof EntityLivingBase) {
        ExtendedProperties.For((EntityLivingBase) owner).removeSummon();
        if (ExtendedProperties.For((EntityLivingBase) owner).isManaLinkedTo(entityliving)) {
            ExtendedProperties.For((EntityLivingBase) owner).updateManaLink(entityliving);
            ExtendedProperties.For((EntityLivingBase) owner).forceSync();
        }
    }
    entityliving.getEntityData().setBoolean(isSummonKey, false);
    setOwner(entityliving, null);
    if (storedTasks.containsKey(entityliving.getEntityId())) {
        entityliving.targetTasks.taskEntries.clear();
        entityliving.targetTasks.taskEntries.addAll(storedTasks.get(entityliving.getEntityId()));
        storedTasks.remove(entityliving.getEntityId());
        if (storedAITasks.get(entityliving.getEntityId()) != null) {
            ArrayList<EntityAITaskEntry> toRemove = new ArrayList<EntityAITaskEntry>();
            for (Object task : entityliving.tasks.taskEntries) {
                EntityAITaskEntry base = (EntityAITaskEntry) task;
                if (base.action instanceof EntityAIAttackOnCollide || base.action instanceof EntityAISummonFollowOwner) {
                    toRemove.add(base);
                }
            }
            entityliving.tasks.taskEntries.removeAll(toRemove);
            entityliving.tasks.taskEntries.addAll(storedAITasks.get(entityliving.getEntityId()));
            storedAITasks.remove(entityliving.getEntityId());
        }
        if (!entityliving.worldObj.isRemote && entityliving.getAttackTarget() != null)
            AMCore.proxy.addDeferredTargetSet(entityliving, null);
        if (entityliving instanceof EntityTameable) {
            ((EntityTameable) entityliving).setTamed(false);
        }
        return true;
    }
    return false;
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) EntityAIAttackOnCollide(net.minecraft.entity.ai.EntityAIAttackOnCollide) EntityLivingBase(net.minecraft.entity.EntityLivingBase) ArrayList(java.util.ArrayList) EntityAISummonFollowOwner(am2.entities.ai.EntityAISummonFollowOwner) EntityAITaskEntry(net.minecraft.entity.ai.EntityAITasks.EntityAITaskEntry) EntityTameable(net.minecraft.entity.passive.EntityTameable)

Example 3 with EntityAITaskEntry

use of net.minecraft.entity.ai.EntityAITasks.EntityAITaskEntry 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)

Example 4 with EntityAITaskEntry

use of net.minecraft.entity.ai.EntityAITasks.EntityAITaskEntry in project Railcraft by Railcraft.

the class EntityAIMateBreeding method modifyAI.

public static void modifyAI(EntityAnimal animal) {
    boolean tame = animal instanceof EntityTameable;
    int matePriority = -1;
    int sitPriority = -1;
    boolean hasDespawn = false;
    Iterator<EntityAITaskEntry> it = animal.tasks.taskEntries.iterator();
    while (it.hasNext()) {
        EntityAITaskEntry task = it.next();
        if (tame && task.action instanceof EntityAISit) {
            sitPriority = task.priority;
            it.remove();
        } else if (task.action instanceof EntityAIMate) {
            matePriority = task.priority;
            it.remove();
        } else if (task.action instanceof EntityAIDespawn) {
            hasDespawn = true;
        }
    }
    if (tame) {
        ((EntityTameable) animal).setTamed(true);
    }
    if (!hasDespawn) {
        animal.tasks.addTask(0, new EntityAIDespawn(animal));
    }
    if (matePriority > 0) {
        animal.tasks.addTask(matePriority, new EntityAIMateBreeding(animal, 0.25f));
        if (tame) {
            animal.tasks.addTask(6, new EntityAISitRandom((EntityTameable) animal));
        }
    }
    if (sitPriority > 0) {
        EntityAISitBred aiSit = new EntityAISitBred((EntityTameable) animal);
        animal.tasks.addTask(sitPriority, aiSit);
        //            ObfuscationReflectionHelper.setPrivateValue(EntityTameable.class, (EntityTameable)animal, aiSit, "d", "aiSit");
        ObfuscationReflectionHelper.setPrivateValue(EntityTameable.class, (EntityTameable) animal, aiSit, 0);
    }
}
Also used : EntityAISit(net.minecraft.entity.ai.EntityAISit) EntityAIMate(net.minecraft.entity.ai.EntityAIMate) EntityAITaskEntry(net.minecraft.entity.ai.EntityAITasks.EntityAITaskEntry)

Aggregations

EntityAITaskEntry (net.minecraft.entity.ai.EntityAITasks.EntityAITaskEntry)4 EntityAIAttackOnCollide (net.minecraft.entity.ai.EntityAIAttackOnCollide)3 ArrayList (java.util.ArrayList)2 EntityMob (net.minecraft.entity.monster.EntityMob)2 EntityTameable (net.minecraft.entity.passive.EntityTameable)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 EntityDarkMage (am2.entities.EntityDarkMage)1 EntityLightMage (am2.entities.EntityLightMage)1 EntityAISummonFollowOwner (am2.entities.ai.EntityAISummonFollowOwner)1 Iterator (java.util.Iterator)1 Entity (net.minecraft.entity.Entity)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityAIArrowAttack (net.minecraft.entity.ai.EntityAIArrowAttack)1 EntityAIHurtByTarget (net.minecraft.entity.ai.EntityAIHurtByTarget)1 EntityAIMate (net.minecraft.entity.ai.EntityAIMate)1 EntityAINearestAttackableTarget (net.minecraft.entity.ai.EntityAINearestAttackableTarget)1 EntityAISit (net.minecraft.entity.ai.EntityAISit)1 IBossDisplayData (net.minecraft.entity.boss.IBossDisplayData)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityEnderman (net.minecraft.entity.monster.EntityEnderman)1