Search in sources :

Example 6 with AttackEntityEvent

use of org.spongepowered.api.event.entity.AttackEntityEvent in project SpongeCommon by SpongePowered.

the class MixinEntityMinecartTNT method onAttackEntityFrom.

@Inject(method = "attackEntityFrom", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/EntityMinecartTNT;explodeCart(D)V"))
private void onAttackEntityFrom(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
    try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
        frame.pushCause(source);
        AttackEntityEvent event = SpongeEventFactory.createAttackEntityEvent(frame.getCurrentCause(), new ArrayList(), this, 0, amount);
        SpongeImpl.postEvent(event);
        if (event.isCancelled()) {
            cir.setReturnValue(true);
        }
    }
}
Also used : AttackEntityEvent(org.spongepowered.api.event.entity.AttackEntityEvent) CauseStackManager(org.spongepowered.api.event.CauseStackManager) ArrayList(java.util.ArrayList) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

ArrayList (java.util.ArrayList)6 AttackEntityEvent (org.spongepowered.api.event.entity.AttackEntityEvent)6 Inject (org.spongepowered.asm.mixin.injection.Inject)5 CauseStackManager (org.spongepowered.api.event.CauseStackManager)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ItemStack (net.minecraft.item.ItemStack)2 DamageSource (net.minecraft.util.DamageSource)2 DamageFunction (org.spongepowered.api.event.cause.entity.damage.DamageFunction)2 Overwrite (org.spongepowered.asm.mixin.Overwrite)2 Vector3d (com.flowpowered.math.vector.Vector3d)1 GameProfile (com.mojang.authlib.GameProfile)1 List (java.util.List)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 EnchantmentHelper (net.minecraft.enchantment.EnchantmentHelper)1 Entity (net.minecraft.entity.Entity)1 EnumCreatureAttribute (net.minecraft.entity.EnumCreatureAttribute)1 IEntityMultiPart (net.minecraft.entity.IEntityMultiPart)1