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);
}
}
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;
}
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;
}
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);
}
}
Aggregations