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