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
Creates a new entity in the specified world.Parameters:
level- World to spawn inuseSmallId- Use optimized small ID (for most entities)
Position & Movement
Sets entity position and updates bounding box.Parameters:
x, y, z- New world coordinates
Moves entity to position with rotation.Parameters:
yRot- Yaw rotation in degreesxRot- Pitch rotation in degrees
Absolute move without interpolation (teleport).
Moves entity with collision detection.Parameters:
xa, ya, za- Movement deltanoEntityCubes- Ignore entity collisions
xd, yd, zd based on actual movement after collisions.Rotates entity.Parameters:
xo- Pitch changeyo- Yaw change
Sets rotation directly.
Applies relative movement based on current rotation.Parameters:
xa, za- Strafe and forward movementspeed- Movement multiplier
Collision & Physics
Checks if entity can move to an offset position.Returns:
true if no collision at new positionGets 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.
Applies push/knockback force.
Size & Bounding Box
Sets entity dimensions.Parameters:
w- Width (X and Z)h- Height (Y)
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).
Calculates distance to coordinates.
Calculates squared distance to coordinates.
Tick & Update
Updates entity for one game tick (1/20 second).Override: Implement entity-specific behavior
Performs common tick operations.
- Updates position history
- Handles fire damage
- Updates air supply
- Manages invulnerability frames
Damage & Death
Applies damage to entity.Parameters:
source- Source of damage (entity, lava, fall, etc.)damage- Damage amount
true if damage was appliedApplies fire damage.Parameters:
dmg- Damage amount
Sets entity on fire.Parameters:
numberOfSeconds- Duration in seconds
Extinguishes fire.
Checks if entity is immune to fire.
Water & Breathing
Checks if entity is in water.
Checks if entity is in lava.
Checks if entity is wet.
Updates water collision state.Returns:
true if in waterGets remaining air ticks while underwater.Returns: Air ticks (max 300)
Sets air supply.
Fall Damage
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
Checks if entity can be clicked/targeted.
Checks if entity can be pushed by other entities.
Checks if entity can be hit by projectiles.
Riding & Vehicles
Mounts another entity.Parameters:
e- Entity to ride (minecart, pig, boat, etc.)
Updates riding state each tick.
Positions the rider entity.Override: Customize rider position on vehicle
Gets height offset for rider.
Gets mount point height.
Checks if entity is riding something.
Rendering & Display
Checks if entity should be rendered from camera position.Parameters:
c- Camera position
Checks if entity should render at distance.
Gets lighting brightness for rendering.Parameters:
a- Partial tick (0.0-1.0)
Gets packed light color value.Returns: Combined sky and block light
Flags & State
Checks if entity is burning.
Checks if entity is sneaking.
Sets sneaking state.
Checks if entity is sprinting.
Sets sprinting state.
Checks if entity is invisible.
Sets invisibility.
Lifecycle
Marks entity for removal from world.
Checks if entity is alive (not removed).
Data Persistence
Saves entity to NBT tag.Returns:
true if saved successfullyLoads entity from NBT tag.
Reads entity-specific NBT data.Note: Abstract - must be implemented
Writes entity-specific NBT data.Note: Abstract - must be implemented
Type System
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