mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 08:17:35 +00:00
Add a cancellable event that gets fired when a Totem of Undying is used (#9069)
This commit is contained in:
1 parent
aae628cd18
commit
be5dab5801
3 files changed
+78
No files matched your search
@@ -138,6 +138,7 @@ import net.minecraftforge.event.entity.living.LivingFallEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingKnockBackEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingUseTotemEvent;
|
||||
import net.minecraftforge.event.entity.living.LootingLevelEvent;
|
||||
import net.minecraftforge.event.entity.living.ShieldBlockEvent;
|
||||
import net.minecraftforge.event.entity.player.AdvancementEvent;
|
||||
@@ -317,6 +318,11 @@ public class ForgeHooks
|
||||
return event;
|
||||
}
|
||||
|
||||
public static boolean onLivingUseTotem(LivingEntity entity, DamageSource damageSource, ItemStack totem, InteractionHand hand)
|
||||
{
|
||||
return !MinecraftForge.EVENT_BUS.post(new LivingUseTotemEvent(entity, damageSource, totem, hand));
|
||||
}
|
||||
|
||||
public static float onLivingHurt(LivingEntity entity, DamageSource src, float amount)
|
||||
{
|
||||
LivingHurtEvent event = new LivingHurtEvent(entity, src, amount);
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
* Fired when an Entity attempts to use a totem to prevent its death.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If this event is cancelled, the totem will not prevent the entity's death.</p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#SERVER logical server}.</p>
|
||||
*/
|
||||
@Cancelable
|
||||
public class LivingUseTotemEvent extends LivingEvent
|
||||
{
|
||||
private final DamageSource source;
|
||||
private final ItemStack totem;
|
||||
private final InteractionHand hand;
|
||||
|
||||
public LivingUseTotemEvent(LivingEntity entity, DamageSource source, ItemStack totem, InteractionHand hand)
|
||||
{
|
||||
super(entity);
|
||||
this.source = source;
|
||||
this.totem = totem;
|
||||
this.hand = hand;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the damage source that caused the entity to die}
|
||||
*/
|
||||
public DamageSource getSource()
|
||||
{
|
||||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the totem of undying being used from the entity's inventory}
|
||||
*/
|
||||
public ItemStack getTotem()
|
||||
{
|
||||
return totem;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the hand holding the totem}
|
||||
*/
|
||||
public InteractionHand getHandHolding()
|
||||
{
|
||||
return hand;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user