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
impl Entity
Sourcepub fn entity_type(&self) -> EntityType
pub fn entity_type(&self) -> EntityType
Type.
Sourcepub fn is_alive(&self) -> bool
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.
Sourcepub fn class(&self) -> EntityClass
pub fn class(&self) -> EntityClass
Version-independent class.
Sourcepub fn item(&self) -> Option<&Item>
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.
Sourcepub fn dimensions(&self) -> Option<EntityDimensions>
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.
Sourcepub fn targeting_margin(&self) -> f32
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.
Sourcepub fn bounding_box(&self) -> Option<[f64; 6]>
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).
Sourcepub fn position(&self) -> [f64; 3]
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.
Sourcepub fn drawn_position(&self) -> [f64; 3]
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
entitypacket restarts the 3 steps), asLivingEntity.tickMovement/OtherClientPlayerEntity.tickMovementmove 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.
Sourcepub fn drawn_on_ground(&self) -> bool
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.
Sourcepub fn drawn_in_web(&self) -> bool
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.
Sourcepub fn drawn_bounding_box(&self) -> Option<[f64; 6]>
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.
Sourcepub fn search_order(&self) -> Option<(i32, i32, i32, u32)>
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.
Sourcepub fn drawn_rotation(&self) -> (f32, f32)
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).
Sourcepub fn interpolation(&self) -> Option<([f64; 3], u8)>
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).
Sourcepub fn estimated_velocity(&self) -> Option<[f64; 3]>
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).
Sourcepub fn position_tick(&self) -> Option<u64>
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).
Sourcepub fn spawn_tick(&self) -> Option<u64>
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).
Sourcepub fn last_hurt_tick(&self) -> Option<u64>
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).
Sourcepub fn traced(&self) -> [i64; 3]
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 (1.16: [0; 3], or the tracked position’s f64 bits for an entity the client
simulates, v1_16_5::Tracker::client_simulated).
Sourcepub fn fixed_position(&self) -> [i32; 3]
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).
Sourcepub fn yaw(&self) -> f32
pub fn yaw(&self) -> f32
Body yaw in degrees as vanilla computes it from the angle byte (b * 360 / 256f).
Sourcepub fn head_yaw(&self) -> f32
pub fn head_yaw(&self) -> f32
Head yaw in degrees (from entity_head_rotation; mobs also at spawn).
Sourcepub fn velocity(&self) -> [f64; 3]
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.
Sourcepub fn data(&self) -> i32
pub fn data(&self) -> i32
Spawn data: object data (1.8 objects / 1.16 spawn_entity), experience orb value,
painting direction.
Sourcepub fn passengers(&self) -> &[i32]
pub fn passengers(&self) -> &[i32]
Entities riding this one (1.8: at most one).
Sourcepub fn leash_holder(&self) -> Option<i32>
pub fn leash_holder(&self) -> Option<i32>
Entity holding this one’s leash.