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 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 rendered position interpolates towards this over 3 ticks in vanilla; a bot does not need that.

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 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

§

impl Move for Entity

§

impl RefUnwindSafe for Entity

§

impl Send for Entity

§

impl Sync for Entity

§

impl Unpin for Entity

§

impl UnsafeUnpin for Entity

§

impl UnwindSafe for Entity

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.