Class XpOrbTargetingEvent

java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.entity.XpOrbTargetingEvent

public class XpOrbTargetingEvent extends net.neoforged.bus.api.Event
Event to determine which player an XP Orb should follow.

This is fired once a second when an XP Orbit find itself without a player to move toward.

The default (nearest player within getScanDistance()) can be overridden with either a new (Fake)Player or null to cancel the attraction.

Note that providing a player that is more than 8 blocks away does work, but it will cause this event to be fired again after 20 ticks.

See also: PlayerXpEvent.PickupXp for cancelling the pickup.

This event is fired on both server and client on the NeoForge.EVENT_BUS.

  • Field Details

    • xpOrb

      private final ExperienceOrb xpOrb
    • scanDistance

      private final double scanDistance
    • followingPlayer

      private Optional<Player> followingPlayer
  • Constructor Details

    • XpOrbTargetingEvent

      public XpOrbTargetingEvent(ExperienceOrb xpOrb, double scanDistance)
  • Method Details

    • getFollowingPlayer

      @Nullable public @Nullable Player getFollowingPlayer()
      The result of the event.
    • setFollowingPlayer

      public void setFollowingPlayer(@Nullable @Nullable Player newFollowingPlayer)
      Sets a new result. Can be null to cancel the default search.
    • getXpOrb

      public ExperienceOrb getXpOrb()
      The ExperienceOrb that's looking for a player to follow.

      You can get the Level from this.

    • getScanDistance

      public double getScanDistance()
      The maximum distance to scan for players. This is 8 for vanilla orbs.