Overview
The Entity API provides the foundation for all moving and interactive objects in Minecraft Community Edition. This includes players, mobs, items, projectiles, and vehicles.Class Hierarchy
Entity Class
Abstract base class for all entities. Header:Minecraft.World/Entity.hInherits:
enable_shared_from_this<Entity>
Constants
Core Members
Constructor
constructor
Creates a new entity in the specified world.Parameters:
level- World to spawn inuseSmallId- Use optimized small ID (for most entities)
Position & Movement
void
Sets entity position and updates bounding box.Parameters:
x, y, z- New world coordinates
void
Moves entity to position with rotation.Parameters:
yRot- Yaw rotation in degreesxRot- Pitch rotation in degrees
void
Absolute move without interpolation (teleport).
void
Moves entity with collision detection.Parameters:
xa, ya, za- Movement deltanoEntityCubes- Ignore entity collisions
xd, yd, zd based on actual movement after collisions.void
Rotates entity.Parameters:
xo- Pitch changeyo- Yaw change
void
Sets rotation directly.
void
Applies relative movement based on current rotation.Parameters:
xa, za- Strafe and forward movementspeed- Movement multiplier
Collision & Physics
bool
Checks if entity can move to an offset position.Returns:
true if no collision at new positionAABB*
Gets the collision bounding box.Returns: Pointer to AABB or null if non-solid
Gets the box other entities collide against.Returns: AABB for entity-entity collisions
Handles entity-to-entity collision.
void
Applies push/knockback force.
Size & Bounding Box
void
Sets entity dimensions.Parameters:
w- Width (X and Z)h- Height (Y)
float
Gets eye/camera height.Returns: Height offset from feet to eyes
Distance Calculations
Calculates distance to another entity.Returns: Distance in blocks
Calculates squared distance (faster - no sqrt).
double
Calculates distance to coordinates.
double
Calculates squared distance to coordinates.
Tick & Update
void
Updates entity for one game tick (1/20 second).Override: Implement entity-specific behavior
void
Performs common tick operations.
- Updates position history
- Handles fire damage
- Updates air supply
- Manages invulnerability frames
Damage & Death
bool
Applies damage to entity.Parameters:
source- Source of damage (entity, lava, fall, etc.)damage- Damage amount
true if damage was appliedvoid
Applies fire damage.Parameters:
dmg- Damage amount
void
Sets entity on fire.Parameters:
numberOfSeconds- Duration in seconds
void
Extinguishes fire.
bool
Checks if entity is immune to fire.
Water & Breathing
bool
Checks if entity is in water.
bool
Checks if entity is in lava.
bool
Checks if entity is wet.
bool
Updates water collision state.Returns:
true if in waterint
Gets remaining air ticks while underwater.Returns: Air ticks (max 300)
void
Sets air supply.
Fall Damage
void
Applies fall damage based on distance.Parameters:
distance- Fall distance in blocks
Interaction
Handles player right-click interaction.Returns:
true if interaction was handledExamples: Riding minecart, breeding animal, trading with villagerHandles player collision/touch.Examples: Item pickup, damage from cactus/mob
bool
Checks if entity can be clicked/targeted.
bool
Checks if entity can be pushed by other entities.
bool
Checks if entity can be hit by projectiles.
Riding & Vehicles
Mounts another entity.Parameters:
e- Entity to ride (minecart, pig, boat, etc.)
void
Updates riding state each tick.
void
Positions the rider entity.Override: Customize rider position on vehicle
double
Gets height offset for rider.
double
Gets mount point height.
bool
Checks if entity is riding something.
Rendering & Display
bool
Checks if entity should be rendered from camera position.Parameters:
c- Camera position
double
Checks if entity should render at distance.
float
Gets lighting brightness for rendering.Parameters:
a- Partial tick (0.0-1.0)
int
Gets packed light color value.Returns: Combined sky and block light
Flags & State
bool
Checks if entity is burning.
bool
Checks if entity is sneaking.
void
Sets sneaking state.
bool
Checks if entity is sprinting.
void
Sets sprinting state.
bool
Checks if entity is invisible.
void
Sets invisibility.
Lifecycle
void
Marks entity for removal from world.
bool
Checks if entity is alive (not removed).
Data Persistence
bool
Saves entity to NBT tag.Returns:
true if saved successfullyvoid
Loads entity from NBT tag.
void
Reads entity-specific NBT data.Note: Abstract - must be implemented
void
Writes entity-specific NBT data.Note: Abstract - must be implemented
Type System
eINSTANCEOF
Gets entity type enum.Returns: Type constant (eTYPE_PLAYER, eTYPE_MOB, etc.)Use case: Fast type checking without dynamic_cast
Entity Damage Types
Example Usage
Creating & Spawning
Movement & Collision
Proximity Checks
Type Checking
See Also
- Player API - Player-specific entity functionality
- Mob API - Living entity base class
- Level API - Entity management in worlds
- Chunk API - Entity storage in chunks