Record Class DrawCommand.Entity

java.lang.Object
java.lang.Record
com.botwithus.bot.api.draw.DrawCommand.Entity
Record Components:
key - the command's identity within this connection
style - colour, stroke, fill, order and lifetime
ref - which list serverIndex indexes
serverIndex - the entity's server-side slot; normalised to 0 for EntityRef.SELF, which carries no index because the producer re-resolves the local player's slot every tick
widthTiles - footprint width in tiles, not sub-tiles
heightTiles - footprint height in tiles
caption - the label drawn against the resolved box, or DrawCaption.NONE
All Implemented Interfaces:
DrawCommand, DrawCommand.Highlight
Enclosing interface:
DrawCommand

public static record DrawCommand.Entity(String key, DrawStyle style, EntityRef ref, int serverIndex, int widthTiles, int heightTiles, DrawCaption caption) extends Record implements DrawCommand.Highlight
A highlight that tracks a live entity — an NPC, another player, or the local player.

Carries no coordinates. The producer keeps (ref, serverIndex) and re-reads the entity's position on the game thread every tick, so the box follows a walking NPC instead of staying where the NPC was when the call was made. It reads the fractional scene position rather than the truncated tile, so it tracks smoothly rather than jumping a tile at a time, and the footprint is centred on the entity.

This is the one world kind with no height approximation in it, and that is why it exists. Every other world command is drawn at the local player's own elevation, because that is the producer's only ground-height source — so a command naming a different plane resolves unavailable rather than being drawn convincingly wrong on the player's floor (see DrawCommand.Tile). An entity carries its own height, so an entity highlight needs no plane, is exempt from that refusal, and is exact upstairs, on a slope and on a staircase. It is the recommended way to mark anything that moves.

  • Constructor Details

    • Entity

      public Entity(String key, DrawStyle style, EntityRef ref, int serverIndex, int widthTiles, int heightTiles, DrawCaption caption)
      Creates an instance of a Entity record class.
      Parameters:
      key - the value for the key record component
      style - the value for the style record component
      ref - the value for the ref record component
      serverIndex - the value for the serverIndex record component
      widthTiles - the value for the widthTiles record component
      heightTiles - the value for the heightTiles record component
      caption - the value for the caption record component
  • Method Details

    • autoKey

      public static String autoKey(EntityRef ref, int serverIndex)
      The key an entity highlight gets when the caller names none: npc:<index>, player:<index>, or bare self.

      Decimal, no padding, and no trailing field — the entity is the identity. Two highlights on one NPC with different footprints or colours are the same highlight restyled, and a key that replaces is the right answer; self carries no index because the local player does not have a stable one.

      That format is the producer's contract and it exists so a caller who omitted a key still has a way to name the highlight in order to clear it. Computed here rather than read back, so DrawBuilder.submit() can answer the key before the round-trip — and asserted against the producer by a live test rather than assumed.

    • kind

      public DrawKind kind()
      Description copied from interface: DrawCommand
      The primitive this command draws.
      Specified by:
      kind in interface DrawCommand
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • key

      public String key()
      Returns the value of the key record component.
      Specified by:
      key in interface DrawCommand
      Returns:
      the value of the key record component
    • style

      public DrawStyle style()
      Returns the value of the style record component.
      Specified by:
      style in interface DrawCommand
      Returns:
      the value of the style record component
    • ref

      public EntityRef ref()
      Returns the value of the ref record component.
      Returns:
      the value of the ref record component
    • serverIndex

      public int serverIndex()
      Returns the value of the serverIndex record component.
      Returns:
      the value of the serverIndex record component
    • widthTiles

      public int widthTiles()
      Returns the value of the widthTiles record component.
      Returns:
      the value of the widthTiles record component
    • heightTiles

      public int heightTiles()
      Returns the value of the heightTiles record component.
      Returns:
      the value of the heightTiles record component
    • caption

      public DrawCaption caption()
      Returns the value of the caption record component.
      Specified by:
      caption in interface DrawCommand.Highlight
      Returns:
      the value of the caption record component