Class Entity

java.lang.Object
org.geysermc.geyser.entity.type.Entity
Direct Known Subclasses:
AbstractArrowEntity, AreaEffectCloudEntity, BoatEntity, EnderCrystalEntity, EnderDragonPartEntity, 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 float
     
    protected float
     
    protected EntityDefinition<?>
     
    A container to store temporary metadata before it's sent to Bedrock.
    protected long
     
    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 it.unimi.dsi.fastutil.longs.LongOpenHashSet
     
    protected float
     
    protected com.nukkitx.math.vector.Vector3f
     
    protected GeyserSession
     
    protected UUID
     
    protected boolean
     
    protected float
    x = Yaw, y = Pitch, z = HeadYaw
  • Constructor Summary

    Constructors
    Constructor
    Description
    Entity​(GeyserSession session, long 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.
    <I extends Entity>
    boolean
    is​(Class<I> entityClass)
     
    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
    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)
     
    void
    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.EntityMetadata<com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose,​?> entityMetadata)
    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.
    void
    Sends the Bedrock metadata to the client
    void
    updateHeadLookRotation​(float headYaw)
    Updates an entity's head position.
    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 long 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
    • boundingBoxHeight

      protected float boundingBoxHeight
    • boundingBoxWidth

      protected float boundingBoxWidth
    • nametag

      protected String nametag
    • passengers

      protected it.unimi.dsi.fastutil.longs.LongOpenHashSet passengers
    • 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, long 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.EntityMetadata<com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose,​?> entityMetadata)
      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 void 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
    • as

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

      public <I extends Entity> boolean is(Class<I> entityClass)