Base entity proxy

Entity

Entity is the base class for all entities in the game — mobs, animals, projectiles, dropped items, etc. Player extends this class.


Constructor

Entity(uuid: str | None = None)

Resolve an existing entity by its UUID.

entity = Entity("550e8400-e29b-41d4-a716-446655440000")

Class Methods

spawn

entity = await Entity.spawn(entity_type, location, **kwargs)

Spawn a new entity at a location.

zombie = await Entity.spawn(EntityType.ZOMBIE, player.location)
zombie = await Entity.spawn("ZOMBIE", Location(0, 64, 0, "world"))

Attributes

uuid

The entity's universally unique identifier.

type

The entity type (e.g. EntityType.ZOMBIE, EntityType.ARROW).

location

The entity's current location. Re-fetched each access.

world

The world the entity is in.

velocity

The entity's current velocity vector.

is_dead

Whether the entity is dead.

is_alive

Whether the entity is alive.

is_valid

Whether the entity handle is still valid. Becomes False when the entity is removed from the server. Always check this before interacting with an entity you've stored across ticks.

fire_ticks

Remaining fire ticks. 0 means not on fire. Each tick at 20 TPS, so 100 = 5 seconds of fire.

passengers

Entities riding on top of this entity.

custom_name

The entity's custom name, or None if not set.

is_projectile

Whether this entity is a projectile (arrow, snowball, trident, etc.).

shooter

For projectiles, the entity or block that launched it. None for non-projectiles.

is_tamed

Whether this entity is a tameable animal that has been tamed (wolf, cat, horse, etc.).

owner

The player who caused/owns this entity. Works for:

Returns None if the owner is offline or unknown.

owner_uuid

UUID of the owning player, even if they're offline.

owner_name

Name of the owning player, if known.

source

The entity that created this entity. For example, the player who lit a TNT block, or the witch that threw a potion.

@event
async def entity_damage_by_entity(e):
    # Track who's responsible for projectile kills
    damager = e.damager
    if damager.is_projectile and damager.owner:
        owner = damager.owner
        await owner.send_message(f"You hit {e.entity.type}!")

    # Check if a tamed wolf attacked something
    if damager.is_tamed:
        await damager.owner.send_message(f"Your {damager.type} attacked {e.entity.type}")

Methods

teleport

await entity.teleport(location)

Teleport the entity to a new location.

await zombie.teleport(Location(0, 100, 0, "world"))

remove

await entity.remove()

Remove the entity from the world permanently.

set_velocity

await entity.set_velocity(vector)

Set the entity's velocity. Useful for launching entities, knockback effects, etc.

# Launch entity upward
await entity.set_velocity(Vector(0, 1.5, 0))

set_fire_ticks

await entity.set_fire_ticks(ticks)

Set the entity on fire for a duration.

await entity.set_fire_ticks(100)  # 5 seconds of fire
await entity.set_fire_ticks(0)    # Extinguish

add_passenger

success = await entity.add_passenger(entity)

Make another entity ride on top of this one.

remove_passenger

success = await entity.remove_passenger(entity)

Remove a riding entity.

set_custom_name

await entity.set_custom_name(name)

Set the entity's custom name tag.

await zombie.set_custom_name("§cBoss Zombie")

set_custom_name_visible

await entity.set_custom_name_visible(value)

Show or hide the custom name tag. When True, the name is visible through walls and at a distance.


Mob AI

These methods only work on Mob entities (zombies, skeletons, etc). They will fail silently on non-mob entities like dropped items or projectiles.

target

target = entity.target

Get the mob's current attack target.

set_target

await entity.set_target(target)

Set the mob's attack target. Pass None to clear.

await zombie.set_target(player)
await zombie.set_target(None)  # clear target

is_aware

aware = entity.is_aware

Check if the mob has AI awareness (responds to environment, pathfinds, etc).

set_aware

await entity.set_aware(aware)

Enable or disable AI awareness. When disabled, the mob won't move or react.

await zombie.set_aware(False)  # freeze the mob

pathfind_to

result = entity.pathfind_to(location, speed=1.0)

Make the mob pathfind to a location using Paper's Pathfinder API.

found = zombie.pathfind_to(player.location, speed=1.5)

stop_pathfinding

await entity.stop_pathfinding()

Stop the mob's current pathfinding. The mob will stand still.

has_line_of_sight

can_see = entity.has_line_of_sight(other)

Check if this mob has line of sight to another entity.

if zombie.has_line_of_sight(player):
    await zombie.set_target(player)

look_at

await entity.look_at(location)

Make the mob face a location.

await zombie.look_at(player.location)