Skip to content

levilamina::entity

Actors: everything addressed by an ActorUniqueID, players included.

An id is an identity and not a pointer

An Entity holds one i64. The host looks the live table up again on every call, so an Entity value can be kept across ticks: once the actor dies a call returns Err rather than jumping into freed memory. The cost is one lookup per call, so a hot path caches the result itself.

A player passes through here to use actor capabilities

Player::as_entity() goes through player_resolve for the id. The reverse does not hold: an actor id is not necessarily a player, and there is no slot resolving an id back into a selector.

Entity

Rust
pub struct Entity(/* private */);

One actor. A zero-cost wrapper around an ActorUniqueID.

  • Implements: Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Display

Entity::from_id

Rust
pub fn from_id(id: i64) -> Entity
  • Parameters:
    • id : i64
  • Return type: Entity

Entity::id

Rust
pub fn id(&self) -> i64
  • Return type: i64

Entity::list

Rust
pub fn list(dim: Option<i32>) -> Vec<ActorEntry>

Enumerates live actors. A dim of None spans every dimension.

This slot has no failure bit and reports nothing while the level is not ready, so an empty table means either that the dimension holds no actor or that the level has not come up, and a caller tells them apart with Host::gaming_status().

Entity::exists

Rust
pub fn exists(&self) -> bool

Whether this id still points at a live actor.

The criterion is whether the type name can be read: every actor that resolves has one, and one that does not makes actor_get_str return false.

Entity::snapshot

Rust
pub fn snapshot(&self) -> Result<NbtValue>

Entity::num

Rust
pub fn num(&self, prop: i32) -> Result<f64>

Reads a PIER_APROP_* numeric property.

  • Parameters:
    • prop : i32
  • Return type: Result<f64>
  • Slots: actor_get_num

Entity::text

Rust
pub fn text(&self, prop: i32) -> Result<String>

Reads a PIER_ASTR_* string property.

  • Parameters:
    • prop : i32
  • Return type: Result<String>
  • Slots: actor_get_str

Entity::pos

Rust
pub fn pos(&self) -> Result<PositionF64>

The position, from Actor::getPosition. For the feet coordinate of a player see Entity::feet_pos.

Entity::feet_pos

Rust
pub fn feet_pos(&self) -> Result<PositionF64>

Entity::head_pos

Rust
pub fn head_pos(&self) -> Result<PositionF64>

Entity::velocity

Rust
pub fn velocity(&self) -> Result<PositionF64>

Entity::view_vector

Rust
pub fn view_vector(&self) -> Result<PositionF64>

The unit vector of the line of sight.

Entity::rotation

Rust
pub fn rotation(&self) -> Result<(f64, f64)>

(pitch, yaw).

Entity::act

Rust
pub fn act(&self, action: i32, sarg: &str, a: f64, b: f64, c: f64) -> Result<String>

Runs one PIER_AACT_* action and returns its output, which is an empty string for most actions.

  • Parameters:
    • action : i32
    • sarg : &str
    • a : f64
    • b : f64
    • c : f64
  • Return type: Result<String>
  • Slots: actor_action

Entity::kill

Rust
pub fn kill(&self) -> Result<()>

Entity::despawn

Rust
pub fn despawn(&self) -> Result<()>

Entity::clear_effects

Rust
pub fn clear_effects(&self) -> Result<()>

Entity::stop_fire

Rust
pub fn stop_fire(&self) -> Result<()>

Entity::remove_all_passengers

Rust
pub fn remove_all_passengers(&self) -> Result<()>

Entity::heal

Rust
pub fn heal(&self, amount: f64) -> Result<()>
  • Parameters:
    • amount : f64
  • Return type: Result<()>
  • Slots: actor_action

Entity::hurt

Rust
pub fn hurt(&self, amount: f64) -> Result<()>
  • Parameters:
    • amount : f64
  • Return type: Result<()>
  • Slots: actor_action

Entity::burn

Rust
pub fn burn(&self, damage: f64) -> Result<()>
  • Parameters:
    • damage : f64
  • Return type: Result<()>
  • Slots: actor_action

Entity::set_on_fire

Rust
pub fn set_on_fire(&self, seconds: i32) -> Result<()>
  • Parameters:
    • seconds : i32
  • Return type: Result<()>
  • Slots: actor_action

Entity::teleport

Rust
pub fn teleport(&self, x: f64, y: f64, z: f64) -> Result<()>

Teleports elsewhere within the same dimension.

Entity::teleport_to

Rust
pub fn teleport_to(&self, dim: i32, x: f64, y: f64, z: f64) -> Result<()>

Teleports into a given dimension. A custom dimension, with an id of 3 or above, goes through here too.

  • Parameters:
    • dim : i32
    • x : f64
    • y : f64
    • z : f64
  • Return type: Result<()>
  • Slots: actor_action

Entity::set_rotation

Rust
pub fn set_rotation(&self, pitch: f64, yaw: f64) -> Result<()>
  • Parameters:
    • pitch : f64
    • yaw : f64
  • Return type: Result<()>
  • Slots: actor_action

Entity::set_velocity

Rust
pub fn set_velocity(&self, x: f64, y: f64, z: f64) -> Result<()>
  • Parameters:
    • x : f64
    • y : f64
    • z : f64
  • Return type: Result<()>
  • Slots: actor_action

Entity::apply_impulse

Rust
pub fn apply_impulse(&self, x: f64, y: f64, z: f64) -> Result<()>
  • Parameters:
    • x : f64
    • y : f64
    • z : f64
  • Return type: Result<()>
  • Slots: actor_action

Entity::set_name_tag

Rust
pub fn set_name_tag(&self, name: &str) -> Result<()>
  • Parameters:
    • name : &str
  • Return type: Result<()>
  • Slots: actor_action

Entity::set_name_tag_visible

Rust
pub fn set_name_tag_visible(&self, on: bool) -> Result<()>
  • Parameters:
    • on : bool
  • Return type: Result<()>
  • Slots: actor_action

Entity::set_score_tag

Rust
pub fn set_score_tag(&self, text: &str) -> Result<()>
  • Parameters:
    • text : &str
  • Return type: Result<()>
  • Slots: actor_action

Entity::add_tag

Rust
pub fn add_tag(&self, tag: &str) -> Result<bool>
  • Parameters:
    • tag : &str
  • Return type: Result<bool>
  • Slots: actor_action

Entity::remove_tag

Rust
pub fn remove_tag(&self, tag: &str) -> Result<bool>
  • Parameters:
    • tag : &str
  • Return type: Result<bool>
  • Slots: actor_action

Entity::has_tag

Rust
pub fn has_tag(&self, tag: &str) -> Result<bool>
  • Parameters:
    • tag : &str
  • Return type: Result<bool>
  • Slots: actor_action

Entity::add_effect

Rust
1
2
3
4
5
6
7
pub fn add_effect(
        &self,
        effect: &str,
        ticks: i32,
        amplifier: i32,
        visible: bool,
    ) -> Result<()>

Adds one status effect.

  • Parameters:
    • effect : &str
    • ticks : i32
    • amplifier : i32
    • visible : bool
  • Return type: Result<()>
  • Slots: actor_action

Entity::remove_effect

Rust
pub fn remove_effect(&self, effect: &str) -> Result<()>
  • Parameters:
    • effect : &str
  • Return type: Result<()>
  • Slots: actor_action

Entity::attribute

Rust
pub fn attribute(&self, name: &str) -> Result<f64>

Reads the current value of one attribute, named as minecraft:health is.

  • Parameters:
    • name : &str
  • Return type: Result<f64>
  • Slots: actor_action

Entity::set_variant

Rust
pub fn set_variant(&self, v: i32) -> Result<()>
  • Parameters:
    • v : i32
  • Return type: Result<()>
  • Slots: actor_action

Entity::set_mark_variant

Rust
pub fn set_mark_variant(&self, v: i32) -> Result<()>
  • Parameters:
    • v : i32
  • Return type: Result<()>
  • Slots: actor_action

Entity::set_persistent

Rust
pub fn set_persistent(&self) -> Result<()>

Entity::set_invisible

Rust
pub fn set_invisible(&self, on: bool) -> Result<()>
  • Parameters:
    • on : bool
  • Return type: Result<()>
  • Slots: actor_action

Entity::set_sneaking

Rust
pub fn set_sneaking(&self, on: bool) -> Result<()>
  • Parameters:
    • on : bool
  • Return type: Result<()>
  • Slots: actor_action

Entity::set_skin_id

Rust
pub fn set_skin_id(&self, id: i32) -> Result<()>
  • Parameters:
    • id : i32
  • Return type: Result<()>
  • Slots: actor_action

Entity::set_strength

Rust
pub fn set_strength(&self, v: i32) -> Result<()>
  • Parameters:
    • v : i32
  • Return type: Result<()>
  • Slots: actor_action

Entity::set_target

Rust
pub fn set_target(&self, target: Entity) -> Result<()>
  • Parameters:
    • target : Entity
  • Return type: Result<()>
  • Slots: actor_action

Entity::set_owner

Rust
pub fn set_owner(&self, owner: Entity) -> Result<()>
  • Parameters:
    • owner : Entity
  • Return type: Result<()>
  • Slots: actor_action

Entity::set_leash_holder

Rust
pub fn set_leash_holder(&self, holder: Entity) -> Result<()>
  • Parameters:
    • holder : Entity
  • Return type: Result<()>
  • Slots: actor_action

Entity::execute_event

Rust
pub fn execute_event(&self, event: &str) -> Result<()>
  • Parameters:
    • event : &str
  • Return type: Result<()>
  • Slots: actor_action

Entity::type_name

Rust
pub fn type_name(&self) -> Result<String>

Entity::name_tag

Rust
pub fn name_tag(&self) -> Result<String>

The name shown above the head.

Entity::score_tag

Rust
pub fn score_tag(&self) -> Result<String>

The line below the name.

Entity::filtered_name

Rust
pub fn filtered_name(&self) -> Result<String>

The name after profanity filtering.

Entity::dimension

Rust
pub fn dimension(&self) -> Result<i32>

Entity::health

Rust
pub fn health(&self) -> Result<f64>

Entity::max_health

Rust
pub fn max_health(&self) -> Result<f64>

Entity::speed

Rust
pub fn speed(&self) -> Result<f64>

The current movement speed, in blocks per tick.

Entity::fall_distance

Rust
pub fn fall_distance(&self) -> Result<f64>

How many blocks the current fall has covered, used to compute fall damage on landing.

Entity::scale

Rust
pub fn scale(&self) -> Result<f64>

The size scale, where 1.0 is the original size.

Entity::variant

Rust
pub fn variant(&self) -> Result<i32>

The variant data value, whose meaning differs per actor kind.

Entity::mark_variant

Rust
pub fn mark_variant(&self) -> Result<i32>

The mark_variant data value, a different numbering from Entity::variant.

Entity::death_time

Rust
pub fn death_time(&self) -> Result<i32>

How many ticks of the death animation have played.

Entity::is_alive

Rust
pub fn is_alive(&self) -> Result<bool>

Entity::is_on_ground

Rust
pub fn is_on_ground(&self) -> Result<bool>

Entity::is_in_water

Rust
pub fn is_in_water(&self) -> Result<bool>

Entity::is_in_lava

Rust
pub fn is_in_lava(&self) -> Result<bool>

Entity::is_on_fire

Rust
pub fn is_on_fire(&self) -> Result<bool>

Entity::is_invisible

Rust
pub fn is_invisible(&self) -> Result<bool>

Entity::is_sneaking

Rust
pub fn is_sneaking(&self) -> Result<bool>

Entity::is_baby

Rust
pub fn is_baby(&self) -> Result<bool>

Entity::is_riding

Rust
pub fn is_riding(&self) -> Result<bool>

Entity::is_tame

Rust
pub fn is_tame(&self) -> Result<bool>

Entity::is_persistent

Rust
pub fn is_persistent(&self) -> Result<bool>

It is not despawned for being too far from a player.

Entity::is_leashed

Rust
pub fn is_leashed(&self) -> Result<bool>

Entity::is_invulnerable

Rust
pub fn is_invulnerable(&self) -> Result<bool>

Entity::is_frozen

Rust
pub fn is_frozen(&self) -> Result<bool>

Entity::is_in_love

Rust
pub fn is_in_love(&self) -> Result<bool>

In the breeding state.

Entity::is_in_rain

Rust
pub fn is_in_rain(&self) -> Result<bool>

Entity::is_in_snow

Rust
pub fn is_in_snow(&self) -> Result<bool>

Entity::is_in_thunderstorm

Rust
pub fn is_in_thunderstorm(&self) -> Result<bool>

Entity::has_totem

Rust
pub fn has_totem(&self) -> Result<bool>

Holding a totem of undying in a hand or the off hand.

Entity::has_passenger

Rust
pub fn has_passenger(&self) -> Result<bool>

Entity::vehicle

Rust
pub fn vehicle(&self) -> Result<Option<Entity>>

The vehicle being ridden. Riding nothing gives Ok(None) and only a missing slot is an Err.

Entity::first_passenger

Rust
pub fn first_passenger(&self) -> Result<Option<Entity>>

Entity::owner

Rust
pub fn owner(&self) -> Result<Option<Entity>>

Entity::target

Rust
pub fn target(&self) -> Result<Option<Entity>>

Entity::distance_to

Rust
pub fn distance_to(&self, other: Entity) -> Result<f64>

The distance between two actors. The host returns a failure across dimensions.

Entity::aabb

Rust
pub fn aabb(&self) -> Result<Aabb>

The bounding box.

Entity::clone_at

Rust
pub fn clone_at(&self, dim: i32, x: f64, y: f64, z: f64) -> Result<Entity>

Clones one to a given position.

  • Parameters:
    • dim : i32
    • x : f64
    • y : f64
    • z : f64
  • Return type: Result<Entity>
  • Slots: actor_clone

Entity::equipped_item

Rust
pub fn equipped_item(&self, slot: EquipSlot) -> Result<ItemStack>

Entity::set_equipped_item

Rust
pub fn set_equipped_item(&self, slot: EquipSlot, item: &ItemStack) -> Result<()>

Entity::effects

Rust
pub fn effects(&self) -> Result<Vec<Effect>>

Every status effect on it.

Entity::status_flag

Rust
pub fn status_flag(&self, flag_index: i32) -> Result<bool>

Reads one bit of ActorFlags.

On the ABI this slot collapses the actor being gone and the bit being false into the same false, the shape contract Β§5.2 opposes. That signature is already released, so this only states it truthfully. Call Entity::exists first when the two must be told apart.

Entity::set_status_flag

Rust
pub fn set_status_flag(&self, flag_index: i32, value: bool) -> Result<()>

Entity::trace_ray

Rust
1
2
3
4
5
6
pub fn trace_ray(
        self,
        max_dist: f32,
        include_actors: bool,
        include_blocks: bool,
    ) -> Result<RayHit>

Casts a ray along the line of sight of this actor, reporting the hit as an exact coordinate.

  • Parameters:
    • max_dist : f32
    • include_actors : bool
    • include_blocks : bool
  • Return type: Result<RayHit>
  • Slots: actor_trace_ray

Entity::trace_ray_blocks

Rust
1
2
3
4
5
6
pub fn trace_ray_blocks(
        self,
        max_dist: f32,
        include_actors: bool,
        include_blocks: bool,
    ) -> Result<RayHit>

As above, reporting the hit as a block cell and carrying the face hit.

Both slots are kept because they answer different questions: placing a block needs a cell coordinate and a face while drawing a particle needs an exact coordinate, and flooring the latter into the former is off by one cell at a block boundary.

  • Parameters:
    • max_dist : f32
    • include_actors : bool
    • include_blocks : bool
  • Return type: Result<RayHit>
  • Slots: edit_trace_ray

Effect

Rust
1
2
3
4
5
6
pub struct Effect {
    pub id: String,
    pub ticks: i32,
    pub amplifier: i32,
    pub visible: bool,
}

One status effect.

  • Implements: Debug, Clone, PartialEq, Eq

Aabb

Rust
1
2
3
4
pub struct Aabb {
    pub min: PositionF64,
    pub max: PositionF64,
}

The axis-aligned bounding box of an actor.

  • Implements: Debug, Clone, Copy, PartialEq

ActorEntry

Rust
1
2
3
4
pub struct ActorEntry {
    pub id: i64,
    pub type_name: String,
}

One entry list_actors reports.

  • Implements: Debug, Clone, PartialEq, Eq