Skip to main content

Entity

Struct Entity 

Source
pub struct Entity { /* private fields */ }
Expand description

A tracked entity, as the vanilla client knows it from the server’s packets.

Implementations§

Source§

impl Entity

Source

pub fn id(&self) -> i32

Network entity id.

Source

pub fn uuid(&self) -> Uuid

UUID (nil for 1.8 entities other than players).

Source

pub fn entity_type(&self) -> EntityType

Type.

Source

pub fn is_alive(&self) -> bool

Vanilla isAlive as far as the packets tell: false for a living entity once it died (its death event, which sets the health to 0 like LivingEntity.handleEntityEvent(3), with or without crate::Config::metadata; or the server’s health is not above 0) — it stays tracked during the death animation (about 20 ticks) until the server removes it, and the vanilla client can still pick and hit it then (the hit does no damage). true for other entities.

Source

pub fn class(&self) -> EntityClass

Version-independent class.

Source

pub fn item(&self) -> Option<&Item>

The stack of an item entity (from metadata; None before the server sent it or when metadata is not tracked; 1.16 always keeps it for item entities). Always None on 26.1, whose stacks carry data components: see v26_1::item_stack / v26_1::item_count.

Source

pub fn dimensions(&self) -> Option<EntityDimensions>

Vanilla client-side dimensions: the type’s size from ghast-data (checked against the oracle), with the variant the client applies from metadata (baby, slime size, wither skeleton, elder guardian, small / marker armor stand, 1.16 player pose). None for hanging entities (paintings, item frames, leash knots), whose box comes from facing.

Variants vanilla applies on the entity’s next client tick are applied immediately, and the old-min-corner quirk after a resize is not modelled.

Source

pub fn targeting_margin(&self) -> f32

How much the crosshair pick grows this entity’s box (vanilla getCollisionBorderSize / getTargetingMargin, from the type’s size table: 0.1 for most 1.8 types, 0 since 1.9, 1.0 for fireballs); 0 when the type has no size entry.

Source

pub fn size(&self) -> Option<(f32, f32)>

(width, height) of Entity::dimensions.

Source

pub fn bounding_box(&self) -> Option<[f64; 6]>

Vanilla bounding box at the server position, [min_x, min_y, min_z, max_x, max_y, max_z] (bit-exact EntityDimensions::bounding_box).

Source

pub fn is_player(&self) -> bool

true for players.

Source

pub fn position(&self) -> [f64; 3]

The server position: exactly the coordinates the vanilla client tracks from the packets (1.8: serverPos / 32.0; 1.12: spawn / teleport coordinates, after a relative move the tracked 1/4096 position; 1.16: the packet coordinates, rel moves applied in 1/4096 fixed point). The vanilla client draws and picks the entity at a position that interpolates towards this over 3 ticks: Entity::drawn_position.

26.1 is different: this is the entity’s current position as the client holds it (Entity.position()): position packets of interpolated entities (living entities, boats, minecarts) set a target the entity reaches over 3 calls of v26_1::Tracker::tick, others move at once. That is the position vanilla’s crosshair pick reads at tick time (with Entity::bounding_box); the packet coordinates are v26_1::server_position.

Source

pub fn drawn_position(&self) -> [f64; 3]

The position the vanilla client draws this entity at and its crosshair pick reads: the server position (Entity::position) followed over the client’s interpolation steps.

  • 1.8.9 / 1.12.2 players, mobs and armor stands: a position packet sets a target that the entity reaches over 3 client ticks (1/3, 1/2, then the rest of the remaining way; every move, look or bare entity packet restarts the 3 steps), as LivingEntity.tickMovement / OtherClientPlayerEntity.tickMovement move it.
  • 1.16.5 living entities, boats and shulkers: the 1.16 client view’s position.
  • 26.x: Entity::position (the 26.x tracker already holds the client’s position).

Needs the tracker’s track_client_motion (the ghast client turns it on with entity tracking) and its tick_client once per client tick; otherwise, and for the entities the view does not interpolate, this is Entity::position.

Source

pub fn drawn_on_ground(&self) -> bool

1.8.9 / 1.12.2 client view: onGround of the client’s copy — the last position packet’s flag (Entity::on_ground) unless a moving piston moved the copy since (its move sets it). Without the client view: Entity::on_ground.

Source

pub fn drawn_in_web(&self) -> bool

1.8.9 / 1.12.2 client view: inWeb of the client’s copy (a moving piston’s push into a cobweb sets it, its next push uses and clears it). false without the client view.

Source

pub fn drawn_bounding_box(&self) -> Option<[f64; 6]>

The bounding box at Entity::drawn_position (1.16.5: the client view’s box, which keeps its minimum corner after a growing resize until the next move), [min_x, min_y, min_z, max_x, max_y, max_z]. This is the box vanilla’s crosshair pick tests.

Source

pub fn search_order(&self) -> Option<(i32, i32, i32, u32)>

1.8.9 / 1.12.2 client view: where vanilla’s entity searches (World.getEntitiesIn, the crosshair pick) meet this entity, as a sort key — chunk x, chunk z, section, then the order in which the section’s list took it (entities move between lists at their tick). Entities overlapping on the pick ray are chosen by this order. None without the view.

Source

pub fn drawn_rotation(&self) -> (f32, f32)

The drawn (yaw, pitch) (1.8.9 / 1.12.2 interpolated like Entity::drawn_position; otherwise Entity::yaw / Entity::pitch).

Source

pub fn interpolation(&self) -> Option<([f64; 3], u8)>

1.8.9 / 1.12.2: the interpolation target and the client ticks left to reach it (None when the drawn position is not interpolating or the view is off).

Source

pub fn estimated_velocity(&self) -> Option<[f64; 3]>

Estimated velocity in blocks per tick: the change between the last two server positions divided by the ticks between them (players are often updated every 2 ticks). It is not reset when the updates stop (compare Entity::position_tick with the current tick). None without the client view (living entities only).

Source

pub fn position_tick(&self) -> Option<u64>

The tick (the clock the client sets with Entities::set_tick; the ghast client uses TickContext::tick) of the last server position change (the spawn tick before the first one). None without the client view (living entities only).

Source

pub fn spawn_tick(&self) -> Option<u64>

The tick this entity spawned (a re-spawn with the same id is a new entity with a new spawn tick). None without the client view (living entities only).

Source

pub fn last_hurt_tick(&self) -> Option<u64>

The tick of the last hurt (1.8: entity status 2; 1.12 / 1.16 also the thorns, drowning, burning and berry-bush statuses; 26.x the damage event). None before the first one and without the client view (living entities only).

Source

pub fn traced(&self) -> [i64; 3]

The tracked server position in packet units (tracedX …): 1.8 1/32 blocks, 1.12 1/4096 blocks (relative moves add to it even while the bot steers the entity). Not kept in 1.16 and later.

Source

pub fn fixed_position(&self) -> [i32; 3]

1.8 only: the raw server position in 1/32 blocks ([0; 3] in 1.12 and 1.16).

Source

pub fn yaw(&self) -> f32

Body yaw in degrees as vanilla computes it from the angle byte (b * 360 / 256f).

Source

pub fn pitch(&self) -> f32

Pitch in degrees.

Source

pub fn head_yaw(&self) -> f32

Head yaw in degrees (from entity_head_rotation; mobs also at spawn).

Source

pub fn velocity(&self) -> [f64; 3]

Last velocity the server sent (blocks per tick), from the spawn packet or entity_velocity. Not integrated over time.

Source

pub fn on_ground(&self) -> bool

On-ground flag of the last movement packet.

Source

pub fn data(&self) -> i32

Spawn data: object data (1.8 objects / 1.16 spawn_entity), experience orb value, painting direction.

Source

pub fn vehicle(&self) -> Option<i32>

Entity this one rides.

Source

pub fn passengers(&self) -> &[i32]

Entities riding this one (1.8: at most one).

Source

pub fn leash_holder(&self) -> Option<i32>

Entity holding this one’s leash.

Source

pub fn metadata(&self) -> &Metadata

Metadata (empty unless metadata tracking is enabled).

Source

pub fn equipment(&self, slot: usize) -> Option<&Item>

Equipment slot (see EQUIPMENT_SLOTS); None if never sent or empty.

Source

pub fn effects(&self) -> &[Effect]

Active effects as last reported.

Source

pub fn effect(&self, id: u8) -> Option<&Effect>

The effect with this id, if active.

Trait Implementations§

Source§

impl Clone for Entity

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Entity

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for Entity

§

impl Freeze for Entity
where &'static VanillaEntitySize: Freeze, *const [(u8, MetaValue)] is !null: Freeze, PhantomData<[(u8, MetaValue)]>: Freeze, *const [Option<Item>; 8] is !null: Freeze, PhantomData<[Option<Item>; 8]>: Freeze, *const Links is !null: Freeze, PhantomData<Links>: Freeze, *const Client is !null: Freeze, PhantomData<Client>: Freeze, *const State is !null: Freeze, PhantomData<State>: Freeze,

§

impl Move for Entity

§

impl RefUnwindSafe for Entity

§

impl Send for Entity
where &'static VanillaEntitySize: Send, BoxRaw<[(u8, MetaValue)]>: Send, BoxRaw<[Option<Item>; 8]>: Send, BoxRaw<Links>: Send, BoxRaw<Client>: Send, BoxRaw<State>: Send,

§

impl Sync for Entity
where BoxRaw<[(u8, MetaValue)]>: Sync, BoxRaw<[Option<Item>; 8]>: Sync, BoxRaw<Links>: Sync, BoxRaw<Client>: Sync, BoxRaw<State>: Sync,

§

impl Unpin for Entity
where &'static VanillaEntitySize: Unpin, Box<[(u8, MetaValue)]>: Unpin, Box<[Option<Item>; 8]>: Unpin, Box<Links>: Unpin, Box<Client>: Unpin, Box<State>: Unpin,

§

impl UnsafeUnpin for Entity

§

impl UnwindSafe for Entity
where &'static VanillaEntitySize: UnwindSafe, BoxRaw<[(u8, MetaValue)]>: UnwindSafe, BoxRaw<[Option<Item>; 8]>: UnwindSafe, BoxRaw<Links>: UnwindSafe, BoxRaw<Client>: UnwindSafe, BoxRaw<State>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.