Search in sources :

Example 1 with LivingHurtEvent

use of net.minecraftforge.event.entity.living.LivingHurtEvent in project Bewitchment by Um-Mitternacht.

the class ArrowDeflectionBrew method onHurt.

@Override
public void onHurt(LivingHurtEvent event, DamageSource source, EntityLivingBase affected, int amplifier) {
    amplifier++;
    affected.world.getEntitiesWithinAABB(EntityArrow.class, affected.getEntityBoundingBox().expand(amplifier / 3, 1, amplifier / 3).expand(-amplifier / 3, -1, -amplifier / 3)).parallelStream().filter(a -> a.shootingEntity != affected).filter(a -> !isInGround(a)).forEach(a -> {
        if (!affected.world.isRemote && a.pickupStatus == EntityArrow.PickupStatus.ALLOWED) {
            ItemStack arrow;
            try {
                arrow = (ItemStack) arrowstack.invoke(a);
                EntityItem ei = new EntityItem(affected.world, a.posX, a.posY, a.posZ, arrow);
                affected.world.spawnEntity(ei);
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                e.printStackTrace();
            }
        }
        a.setDead();
    });
}
Also used : EntityItem(net.minecraft.entity.item.EntityItem) World(net.minecraft.world.World) IBrew(com.bewitchment.api.cauldron.brew.IBrew) ReflectionHelper(net.minecraftforge.fml.relauncher.ReflectionHelper) BlockPos(net.minecraft.util.math.BlockPos) Field(java.lang.reflect.Field) DamageSource(net.minecraft.util.DamageSource) LivingHurtEvent(net.minecraftforge.event.entity.living.LivingHurtEvent) InvocationTargetException(java.lang.reflect.InvocationTargetException) EntityArrow(net.minecraft.entity.projectile.EntityArrow) ItemStack(net.minecraft.item.ItemStack) IBrewHurt(com.bewitchment.api.cauldron.brew.special.IBrewHurt) Minecraft(net.minecraft.client.Minecraft) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Side(net.minecraftforge.fml.relauncher.Side) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Method(java.lang.reflect.Method) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with LivingHurtEvent

use of net.minecraftforge.event.entity.living.LivingHurtEvent in project ArsMagica2 by Mithion.

the class Recoil method applyEffect.

@Override
public boolean applyEffect(EntityPlayer player, World world, ItemStack stack, ImbuementApplicationTypes matchedType, Object... params) {
    LivingHurtEvent event = (LivingHurtEvent) params[0];
    Entity e = event.source.getSourceOfDamage();
    if (e != null && e instanceof EntityLivingBase) {
        ((EntityLivingBase) e).knockBack(player, 10, player.posX - e.posX, player.posZ - e.posZ);
    }
    return true;
}
Also used : LivingHurtEvent(net.minecraftforge.event.entity.living.LivingHurtEvent) Entity(net.minecraft.entity.Entity) EntityLivingBase(net.minecraft.entity.EntityLivingBase)

Aggregations

EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 LivingHurtEvent (net.minecraftforge.event.entity.living.LivingHurtEvent)2 IBrew (com.bewitchment.api.cauldron.brew.IBrew)1 IBrewHurt (com.bewitchment.api.cauldron.brew.special.IBrewHurt)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Minecraft (net.minecraft.client.Minecraft)1 Entity (net.minecraft.entity.Entity)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityArrow (net.minecraft.entity.projectile.EntityArrow)1 ItemStack (net.minecraft.item.ItemStack)1 DamageSource (net.minecraft.util.DamageSource)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 ReflectionHelper (net.minecraftforge.fml.relauncher.ReflectionHelper)1 Side (net.minecraftforge.fml.relauncher.Side)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1