Class EntityPositionProvider

All Implemented Interfaces:
InfoProvider, IPositionProvider, IPositionSet

public class EntityPositionProvider extends PositionProvider implements IPositionSet
Helper class to implement PositionProvider interface for an entity target.

When the entity target becomes invalid hasPosition() will return false.

Also implements IPositionSet: in single-target mode it reports a size of 1 (the primary getTarget()), and in multi-target mode a sensor accumulates every match via addTarget(Ref, ComponentAccessor) with the primary at index 0.

  • Constructor Details

    • EntityPositionProvider

      public EntityPositionProvider()
    • EntityPositionProvider

      public EntityPositionProvider(ParameterProvider parameterProvider)
  • Method Details

    • setIncludeDead

      public void setIncludeDead(boolean includeDead)
      Sets whether dead targets (those with a DeathComponent) should be retained instead of being treated as invalid.
    • clear

      public void clear()
      Reset position provider and clear target reference (including the multi-target list).
      Specified by:
      clear in interface IPositionProvider
      Overrides:
      clear in class PositionProvider
    • setTarget

      public Ref<EntityStore> setTarget(@Nullable Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Set entity and position to be returned from PositionProvider.
      Overrides:
      setTarget in class PositionProvider
      Parameters:
      ref - Reference to the target
      componentAccessor - The component accessor
      Returns:
      null if target is null, removed, or dead (unless includeDead is set), else target
    • addTarget

      public void addTarget(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Appends a matched target for multi-target mode, resolving and storing its current position so the provider can serve it from getPosition(int, Vector3d). The primary (the prioritiser pick) should be added first so it occupies index 0. Invalid or dead targets (per includeDead) are skipped.
    • clearTargets

      public void clearTargets()
      Clears the accumulated multi-target list. Sensors call this at the start of each match pass before re-populating. Unlike clear() it leaves the primary single-target state untouched.
    • promotePrimary

      public void promotePrimary(@Nonnull Ref<EntityStore> ref)
      Ensures ref is the first element (index 0) of the multi-target list by moving it from wherever it currently sits, or inserting it if absent. No-op when the list is empty (single-target mode).
    • getTarget

      @Nullable public Ref<EntityStore> getTarget()
      Description copied from interface: IPositionProvider
      Return target entity if sensor provides it currently.

      A sensor might return a valid position but return a null value here if this position does not correlate to an entity.

      Specified by:
      getTarget in interface IPositionProvider
      Overrides:
      getTarget in class PositionProvider
      Returns:
      entity ref if sensor is matching and result refers to an entity, else null.
    • hasPosition

      public boolean hasPosition()
      Description copied from interface: IPositionProvider
      Test if PositionProvider does return a position currently.
      Specified by:
      hasPosition in interface InfoProvider
      Specified by:
      hasPosition in interface IPositionProvider
      Overrides:
      hasPosition in class PositionProvider
      Returns:
      if true providePosition and getX/Y/Z will return positional result of sensor
    • size

      public int size()
      Specified by:
      size in interface IPositionSet
      Returns:
      the number of elements in the set (0 when empty).
    • getTarget

      @Nullable public Ref<EntityStore> getTarget(int index)
      Specified by:
      getTarget in interface IPositionSet
      Returns:
      the entity associated with element index, or null when the element is a bare position with no entity (e.g. a computed point), when index is out of range, or when the entity is no longer valid.
    • getPosition

      public boolean getPosition(int index, @Nonnull org.joml.Vector3d out)
      Description copied from interface: IPositionSet
      Writes the position of element index into out.
      Specified by:
      getPosition in interface IPositionSet
      Returns:
      true if a position was written. false if index is out of range.
    • getOrientation

      public boolean getOrientation(int index, @Nonnull Rotation3f out)
      Description copied from interface: IPositionSet
      Writes the orientation of element index into out, when that element carries one.
      Specified by:
      getOrientation in interface IPositionSet
      Returns:
      true if an orientation was written, false otherwise (in which case out is left untouched).