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
invalid reference
LivingSetAttackTargetEvent
.

This event is fired via the CommonHooks.onLivingChangeTarget(LivingEntity, LivingEntity, ILivingTargetType)

getOriginalTarget() returns the target that should originally be set. The return value cannot be affected by calling setNewTarget(LivingEntity).
getNewTarget() returns the new target that this entity will have. The return value can be affected by calling setNewTarget(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
from being posted.

This event does not have a result.
invalid reference
Event.HasResult


This event is fired on the NeoForge.EVENT_BUS.
  • Field Details

  • Constructor Details

  • Method Details

    • getNewTarget

      public LivingEntity getNewTarget()
      Returns the new target of this entity..
      Returns:
      the new target of this entity.
    • setNewTarget

      public void setNewTarget(LivingEntity newTarget)
      Sets the new target this entity shall have.
      Parameters:
      newTarget - The new target of this entity.
    • getTargetType

      Returns the living target type..
      Returns:
      the living target type.
    • getOriginalTarget

      public LivingEntity getOriginalTarget()
      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.