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 Summary

    Fields
    Modifier and Type
    Field
    Description
    private @Nullable Optional<net.minecraft.world.entity.player.Player>
     
    private final double
     
    private final net.minecraft.world.entity.ExperienceOrb
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    XpOrbTargetingEvent(net.minecraft.world.entity.ExperienceOrb xpOrb, double scanDistance)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable net.minecraft.world.entity.player.Player
    The result of the event.
    double
    The maximum distance to scan for players.
    net.minecraft.world.entity.ExperienceOrb
    The ExperienceOrb that's looking for a player to follow.
    void
    setFollowingPlayer(@Nullable net.minecraft.world.entity.player.Player newFollowingPlayer)
    Sets a new result.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • xpOrb

      private final net.minecraft.world.entity.ExperienceOrb xpOrb
    • scanDistance

      private final double scanDistance
    • followingPlayer

      @Nullable private @Nullable Optional<net.minecraft.world.entity.player.Player> followingPlayer
  • Constructor Details

    • XpOrbTargetingEvent

      public XpOrbTargetingEvent(net.minecraft.world.entity.ExperienceOrb xpOrb, double scanDistance)
  • Method Details

    • getFollowingPlayer

      @Nullable public @Nullable net.minecraft.world.entity.player.Player getFollowingPlayer()
      The result of the event.
    • setFollowingPlayer

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

      public net.minecraft.world.entity.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.