Class Entity

java.lang.Object
org.geysermc.geyser.entity.type.Entity
Direct Known Subclasses:
AbstractArrowEntity, AreaEffectCloudEntity, BoatEntity, EnderCrystalEntity, EnderDragonPartEntity, EvokerFangsEntity, ExpOrbEntity, FallingBlockEntity, FireworkEntity, ItemFrameEntity, LeashKnotEntity, LightningEntity, LivingEntity, MinecartEntity, PaintingEntity, ThrowableEntity, TNTEntity

public class Entity extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected EntityDefinition<?>
     
    A container to store temporary metadata before it's sent to Bedrock.
    protected int
     
    protected com.nukkitx.protocol.bedrock.data.entity.EntityFlags
    The entity flags for the Bedrock entity.
    protected long
     
    protected float
     
    protected com.nukkitx.math.vector.Vector3f
     
    protected String
     
    protected boolean
    Saves if the entity should be on the ground.
    protected List<Entity>
     
    protected float
     
    protected com.nukkitx.math.vector.Vector3f
     
    protected GeyserSession
     
    protected UUID
     
    protected boolean
    Indicates if the entity has been initialized and spawned
    protected Entity
     
    protected float
    x = Yaw, y = Pitch, z = HeadYaw
  • Constructor Summary

    Constructors
    Constructor
    Description
    Entity​(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, com.nukkitx.math.vector.Vector3f position, com.nukkitx.math.vector.Vector3f motion, float yaw, float pitch, float headYaw)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addAdditionalSpawnData​(com.nukkitx.protocol.bedrock.packet.AddEntityPacket addEntityPacket)
    To be overridden in other entity classes, if additional things need to be done to the spawn entity packet.
    <I extends Entity>
    I
    as​(Class<I> entityClass)
     
    boolean
    Despawns the entity
    com.nukkitx.math.vector.Vector3f
    x = Pitch, y = HeadYaw, z = Yaw
    boolean
    getFlag​(com.nukkitx.protocol.bedrock.data.entity.EntityFlag flag)
     
    protected int
     
    protected void
    Called on entity spawn.
    interact​(com.github.steveice10.mc.protocol.data.game.entity.player.Hand hand)
    Simulates interacting with an entity.
    interactAt​(com.github.steveice10.mc.protocol.data.game.entity.player.Hand hand)
    Simulates interacting with this entity at a specific click point.
    boolean
     
    protected boolean
    If true, the entity should be shaking on the client's end.
    void
    moveAbsolute​(com.nukkitx.math.vector.Vector3f position, float yaw, float pitch, boolean isOnGround, boolean teleported)
     
    void
    moveAbsolute​(com.nukkitx.math.vector.Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported)
     
    void
    moveRelative​(double relX, double relY, double relZ, float yaw, float pitch, boolean isOnGround)
     
    void
    moveRelative​(double relX, double relY, double relZ, float yaw, float pitch, float headYaw, boolean isOnGround)
     
    void
    playEntityEvent​(com.nukkitx.protocol.bedrock.data.entity.EntityEventType type)
    Send an entity event of the specified type to the Bedrock player from this entity.
    void
    playEntityEvent​(com.nukkitx.protocol.bedrock.data.entity.EntityEventType type, int data)
    Send an entity event of the specified type with the specified data to the Bedrock player from this entity.
    void
    setAir​(com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata entityMetadata)
    Set an int from 0 - this entity's maximum air - (air / maxAir) represents the percentage of bubbles left
    protected void
    setAirSupply​(int amount)
     
    boolean
    setBoundingBoxHeight​(float height)
     
    void
    setBoundingBoxWidth​(float width)
     
    protected void
    setDimensions​(com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose pose)
    Set the height and width of the entity's bounding box
    void
    setDisplayName​(com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata<Optional<net.kyori.adventure.text.Component>,​?> entityMetadata)
     
    void
    setDisplayNameVisible​(com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata entityMetadata)
     
    void
    setFlag​(com.nukkitx.protocol.bedrock.data.entity.EntityFlag flag, boolean value)
    Updates a flag value and determines if the flags would need synced with the Bedrock client.
    void
    setFlags​(com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata entityMetadata)
     
    float
    setFreezing​(com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata entityMetadata)
    Set a float from 0-1 - how strong the "frozen" overlay should be on screen.
    void
    setGravity​(com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata entityMetadata)
     
    protected void
    setInvisible​(boolean value)
    Set a boolean - whether the entity is invisible or visible
    void
    setPose​(com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose pose)
    Usually used for bounding box and not animation.
    void
    setRiderSeatPosition​(com.nukkitx.math.vector.Vector3f position)
     
    void
     
    void
    teleport​(com.nukkitx.math.vector.Vector3f position, float yaw, float pitch, boolean isOnGround)
    Teleports an entity to a new location.
    protected InteractiveTag
    testInteraction​(com.github.steveice10.mc.protocol.data.game.entity.player.Hand hand)
    Test interacting with the given hand to see if we should send a tag to the Bedrock client.
    void
    Sends the Bedrock metadata to the client
    void
    updateHeadLookRotation​(float headYaw)
    Updates an entity's head position.
    void
    Update the suggestion that the client currently has on their screen for this entity (for example, "Feed" or "Ride")
    protected void
    Update this entity's mount offset
    protected void
    Update the mount offsets of each passenger on this vehicle
    void
    updatePositionAndRotation​(double moveX, double moveY, double moveZ, float yaw, float pitch, boolean isOnGround)
    Updates an entity's position and rotation.
    void
    updateRotation​(float yaw, float pitch, boolean isOnGround)
    Updates an entity's rotation.

    Methods inherited from class java.lang.Object

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

    • session

      protected final GeyserSession session
    • entityId

      protected int entityId
    • geyserId

      protected final long geyserId
    • uuid

      protected UUID uuid
    • position

      protected com.nukkitx.math.vector.Vector3f position
    • motion

      protected com.nukkitx.math.vector.Vector3f motion
    • yaw

      protected float yaw
      x = Yaw, y = Pitch, z = HeadYaw
    • pitch

      protected float pitch
    • headYaw

      protected float headYaw
    • onGround

      protected boolean onGround
      Saves if the entity should be on the ground. Otherwise entities like parrots are flapping when rotating
    • definition

      protected EntityDefinition<?> definition
    • valid

      protected boolean valid
      Indicates if the entity has been initialized and spawned
    • nametag

      protected String nametag
    • passengers

      protected List<Entity> passengers
    • vehicle

      protected Entity vehicle
    • dirtyMetadata

      protected final GeyserDirtyMetadata dirtyMetadata
      A container to store temporary metadata before it's sent to Bedrock.
    • flags

      protected final com.nukkitx.protocol.bedrock.data.entity.EntityFlags flags
      The entity flags for the Bedrock entity. These must always be saved - if flags are updated and the other values aren't present, the Bedrock client will think they are set to false.
  • Constructor Details

    • Entity

      public Entity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, com.nukkitx.math.vector.Vector3f position, com.nukkitx.math.vector.Vector3f motion, float yaw, float pitch, float headYaw)
  • Method Details

    • initializeMetadata

      protected void initializeMetadata()
      Called on entity spawn. Used to populate the entity metadata and flags with default values.
    • spawnEntity

      public void spawnEntity()
    • addAdditionalSpawnData

      public void addAdditionalSpawnData(com.nukkitx.protocol.bedrock.packet.AddEntityPacket addEntityPacket)
      To be overridden in other entity classes, if additional things need to be done to the spawn entity packet.
    • despawnEntity

      public boolean despawnEntity()
      Despawns the entity
      Returns:
      can be deleted
    • moveRelative

      public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, boolean isOnGround)
    • moveRelative

      public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, float headYaw, boolean isOnGround)
    • moveAbsolute

      public void moveAbsolute(com.nukkitx.math.vector.Vector3f position, float yaw, float pitch, boolean isOnGround, boolean teleported)
    • moveAbsolute

      public void moveAbsolute(com.nukkitx.math.vector.Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported)
    • teleport

      public void teleport(com.nukkitx.math.vector.Vector3f position, float yaw, float pitch, boolean isOnGround)
      Teleports an entity to a new location. Used in JavaTeleportEntityTranslator.
      Parameters:
      position - The new position of the entity.
      yaw - The new yaw of the entity.
      pitch - The new pitch of the entity.
      isOnGround - Whether the entity is currently on the ground.
    • updateHeadLookRotation

      public void updateHeadLookRotation(float headYaw)
      Updates an entity's head position. Used in JavaRotateHeadTranslator.
      Parameters:
      headYaw - The new head rotation of the entity.
    • updatePositionAndRotation

      public void updatePositionAndRotation(double moveX, double moveY, double moveZ, float yaw, float pitch, boolean isOnGround)
      Updates an entity's position and rotation. Used in JavaMoveEntityPosRotTranslator.
      Parameters:
      moveX - The new X offset of the current position.
      moveY - The new Y offset of the current position.
      moveZ - The new Z offset of the current position.
      yaw - The new yaw of the entity.
      pitch - The new pitch of the entity.
      isOnGround - Whether the entity is currently on the ground.
    • updateRotation

      public void updateRotation(float yaw, float pitch, boolean isOnGround)
      Updates an entity's rotation. Used in JavaMoveEntityRotTranslator.
      Parameters:
      yaw - The new yaw of the entity.
      pitch - The new pitch of the entity.
      isOnGround - Whether the entity is currently on the ground.
    • getFlag

      public final boolean getFlag(com.nukkitx.protocol.bedrock.data.entity.EntityFlag flag)
    • setFlag

      public final void setFlag(com.nukkitx.protocol.bedrock.data.entity.EntityFlag flag, boolean value)
      Updates a flag value and determines if the flags would need synced with the Bedrock client.
    • updateBedrockMetadata

      public void updateBedrockMetadata()
      Sends the Bedrock metadata to the client
    • setFlags

      public void setFlags(com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata entityMetadata)
    • setInvisible

      protected void setInvisible(boolean value)
      Set a boolean - whether the entity is invisible or visible
      Parameters:
      value - true if the entity is invisible
    • setAir

      public final void setAir(com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata entityMetadata)
      Set an int from 0 - this entity's maximum air - (air / maxAir) represents the percentage of bubbles left
    • setAirSupply

      protected void setAirSupply(int amount)
    • getMaxAir

      protected int getMaxAir()
    • setDisplayName

      public void setDisplayName(com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata<Optional<net.kyori.adventure.text.Component>,​?> entityMetadata)
    • setDisplayNameVisible

      public void setDisplayNameVisible(com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata entityMetadata)
    • setGravity

      public void setGravity(com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata entityMetadata)
    • setPose

      public void setPose(com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose pose)
      Usually used for bounding box and not animation.
    • setDimensions

      protected void setDimensions(com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose pose)
      Set the height and width of the entity's bounding box
    • setBoundingBoxHeight

      public boolean setBoundingBoxHeight(float height)
    • setBoundingBoxWidth

      public void setBoundingBoxWidth(float width)
    • setFreezing

      public float setFreezing(com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata entityMetadata)
      Set a float from 0-1 - how strong the "frozen" overlay should be on screen.
    • setRiderSeatPosition

      public void setRiderSeatPosition(com.nukkitx.math.vector.Vector3f position)
    • isShaking

      protected boolean isShaking()
      If true, the entity should be shaking on the client's end.
      Returns:
      whether EntityFlag.SHAKING should be set to true.
    • getBedrockRotation

      public com.nukkitx.math.vector.Vector3f getBedrockRotation()
      x = Pitch, y = HeadYaw, z = Yaw
      Returns:
      the bedrock rotation
    • updatePassengerOffsets

      protected void updatePassengerOffsets()
      Update the mount offsets of each passenger on this vehicle
    • updateMountOffset

      protected void updateMountOffset()
      Update this entity's mount offset
    • isAlive

      public boolean isAlive()
    • updateInteractiveTag

      public final void updateInteractiveTag()
      Update the suggestion that the client currently has on their screen for this entity (for example, "Feed" or "Ride")
    • testInteraction

      protected InteractiveTag testInteraction(com.github.steveice10.mc.protocol.data.game.entity.player.Hand hand)
      Test interacting with the given hand to see if we should send a tag to the Bedrock client. Should usually mirror interact(Hand) without any side effects.
    • interact

      public InteractionResult interact(com.github.steveice10.mc.protocol.data.game.entity.player.Hand hand)
      Simulates interacting with an entity. The code here should mirror Java Edition code to the best of its ability, to ensure packet parity as well as functionality parity (such as sound effect responses).
    • interactAt

      public InteractionResult interactAt(com.github.steveice10.mc.protocol.data.game.entity.player.Hand hand)
      Simulates interacting with this entity at a specific click point. As of Java Edition 1.18.1, this is only used for armor stands.
    • playEntityEvent

      public final void playEntityEvent(com.nukkitx.protocol.bedrock.data.entity.EntityEventType type)
      Send an entity event of the specified type to the Bedrock player from this entity.
    • playEntityEvent

      public final void playEntityEvent(com.nukkitx.protocol.bedrock.data.entity.EntityEventType type, int data)
      Send an entity event of the specified type with the specified data to the Bedrock player from this entity.
    • as

      public <I extends Entity> I as(Class<I> entityClass)