Class LivingChangeTargetEvent
java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.entity.EntityEvent
net.neoforged.neoforge.event.entity.living.LivingEvent
net.neoforged.neoforge.event.entity.living.LivingChangeTargetEvent
- All Implemented Interfaces:
net.neoforged.bus.api.ICancellableEvent
public class LivingChangeTargetEvent
extends LivingEvent
implements net.neoforged.bus.api.ICancellableEvent
This event allows you to change the target an entity has.
This event is fired before
.
This event is fired via the
This event is
If you cancel this event, the target will not be changed and it will stay the same. Cancelling this event will prevent
from being posted.
This event does not have a result.
This event is fired on the
This event is fired before
invalid reference
LivingSetAttackTargetEvent
This event is fired via the
CommonHooks.onLivingChangeTarget(LivingEntity, LivingEntity, ILivingTargetType)
getOriginalAboutToBeSetTarget()
returns the target that should originally be set.
The return value cannot be affected by calling setNewAboutToBeSetTarget(LivingEntity)
.getNewAboutToBeSetTarget()
returns the new target that this entity will have.
The return value can be affected by calling setNewAboutToBeSetTarget(LivingEntity)
.getTargetType()
returns the target type that caused the change of targets.This event is
ICancellableEvent
.If you cancel this event, the target will not be changed and it will stay the same. Cancelling this event will prevent
invalid reference
LivingSetAttackTargetEvent
This event does not have a result.
invalid reference
Event.HasResult
This event is fired on the
NeoForge.EVENT_BUS
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
A living target type indicates what kind of system caused a change of targets.static enum
This enum contains two default living target types.Nested classes/interfaces inherited from class net.neoforged.neoforge.event.entity.living.LivingEvent
LivingEvent.LivingJumpEvent, LivingEvent.LivingVisibilityEvent
Nested classes/interfaces inherited from class net.neoforged.neoforge.event.entity.EntityEvent
EntityEvent.EnteringSection, EntityEvent.EntityConstructing, EntityEvent.Size
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate @Nullable LivingEntity
private final @Nullable LivingEntity
private final LivingChangeTargetEvent.ILivingTargetType
-
Constructor Summary
ConstructorsConstructorDescriptionLivingChangeTargetEvent
(LivingEntity entity, @Nullable LivingEntity aboutToBeSetTarget, LivingChangeTargetEvent.ILivingTargetType targetType) -
Method Summary
Modifier and TypeMethodDescription@Nullable LivingEntity
Returns the new target that this entity will begin to track..@Nullable LivingEntity
Returns the original entity MC intended to use as a target before firing this event..Returns the living target type..void
setNewAboutToBeSetTarget
(@Nullable LivingEntity newAboutToBeSetTarget) Sets the new target this entity shall have.Methods inherited from class net.neoforged.neoforge.event.entity.living.LivingEvent
getEntity
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.neoforged.bus.api.ICancellableEvent
isCanceled, setCanceled
-
Field Details
-
targetType
-
originalAboutToBeSetTarget
-
newAboutToBeSetTarget
-
-
Constructor Details
-
LivingChangeTargetEvent
public LivingChangeTargetEvent(LivingEntity entity, @Nullable @Nullable LivingEntity aboutToBeSetTarget, LivingChangeTargetEvent.ILivingTargetType targetType)
-
-
Method Details
-
getNewAboutToBeSetTarget
Returns the new target that this entity will begin to track..- Returns:
- the new target that this entity will begin to track.
-
setNewAboutToBeSetTarget
Sets the new target this entity shall have.- Parameters:
newAboutToBeSetTarget
- The new target that this entity will begin to track
-
getTargetType
Returns the living target type..- Returns:
- the living target type.
-
getOriginalAboutToBeSetTarget
Returns the original entity MC intended to use as a target before firing this event..- Returns:
- the original entity MC intended to use as a target before firing this event.
-