Skip to main content

Tracker

Struct Tracker 

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

The bot’s entity view on a modern (26.1 / 26.2) connection. Dereferences to the shared Entities.

Implementations§

Source§

impl Tracker

Source

pub fn new(config: Config) -> Self

An empty tracker.

Source

pub fn tick_seq(&self, id: i32) -> Option<u64>

The entity’s place in the client’s tick list (ClientLevel.tickingEntities, the order tickEntities runs them in and, within a chunk section, the order getEntities lists them in): a number that grows with each entity that starts ticking; None while it does not tick. Entities start ticking when they spawn into a loaded chunk column, when their column loads, or when they move into a loaded column; they stop when removed or when their column unloads, and re-enter at the end. The local player (its id from the login packet) enters first at login and at a dimension change, and last at a respawn in the same dimension. Several entities entering at the same moment for a column load or a move are ordered by id (vanilla’s order there follows its section storage). After 2³² − 1 entries the numbers restart from 1 with the order kept.

Source

pub fn tick_order(&self) -> Vec<i32>

The ids of the ticking entities (the local player included) in the client’s tick order (see Tracker::tick_seq).

Source

pub fn store_mut(&mut self) -> &mut Entities

The shared store, mutable for Entities::drain_events.

Source

pub fn wants(&self, id: i32) -> bool

true when this tracker wants packet id (for a PacketFilter).

Source

pub fn packet_ids(&self) -> impl Iterator<Item = i32> + '_

Every packet id this tracker wants.

Source

pub fn chunk_loaded(&self, p: [f64; 3]) -> bool

true when the chunk column holding p is loaded (its entities tick).

Source

pub fn mark_column_loaded(&mut self, x: i32, z: i32)

A chunk column became loaded (what a map_chunk packet does here; for a tracker started while chunks are already loaded): its entities tick again.

Source

pub fn mark_column_unloaded(&mut self, x: i32, z: i32)

A chunk column was unloaded (unload_chunk): its entities stop ticking.

Source

pub fn is_ticking(&self, e: &Entity) -> bool

ClientLevel.isTickingEntity: players always tick, other entities while their chunk column is loaded.

Source

pub fn pickable(&self, e: &Entity) -> bool

Whether vanilla’s crosshair pick can hit e: its type is pickable (isPickable), it is not an armor stand marker, and not a spectator (players: tab list game mode 3).

Source

pub fn game_mode(&self, e: &Entity) -> Option<i32>

The game mode vanilla’s client knows for player entity e (AbstractClientPlayer.getPlayerInfo): its tab-list entry (full list or Config::player_names); an entity that already looked its entry up keeps that entry’s last game mode after the entry left the tab list. None for other entities, or without a tab list.

Source

pub fn is_spectator(&self, e: &Entity) -> bool

isSpectator of a player entity (game mode 3, see Tracker::game_mode): spectators are not pickable, not pushable and never on the ground. false for other entities.

Source

pub fn scoreboard_name<'a>(&'a self, e: &'a Entity) -> Option<&'a str>

getScoreboardName (what team rules match): a player’s profile name (the tab-list entry it spawned with, kept after the entry left), else None; vanilla uses the UUID string for other entities. Needs the full tab list or Config::player_names.

Source

pub fn tick(&mut self)

One client tick of the tracked entities (ClientLevel.tickEntities): every entity in a loaded chunk takes one interpolation step and one head-rotation step. Call it once per client tick, after the tick’s crosshair pick (see the module docs). Assumes the moved interpolation target never collides; use Tracker::tick_with for vanilla’s check.

Source

pub fn tick_with(&mut self, no_collision: impl FnMut(&Entity, [f64; 6]) -> bool)

Tracker::tick with vanilla’s collision test: when an entity moved since its last interpolation step (a snap, a teleport, a bed position), the step first moves the target along, but only if no_collision(entity, box) says the entity’s box at the moved target ([min_x, min_y, min_z, max_x, max_y, max_z]) is free (Level.noCollision: blocks, collidable entities, world border).

Source

pub fn tick_early( &mut self, id: i32, no_collision: impl FnMut(&Entity, [f64; 6]) -> bool, ) -> Option<[f64; 3]>

Ticks entity id now, ahead of the rest of this client tick (a vehicle ticks before its passenger: the local player riding a vehicle the server moves reads where the vehicle is after its tick). The next Tracker::tick_with skips it once. Returns its position after the tick (None: not tracked).

Source

pub fn apply(&mut self, raw: &RawPacket) -> Result<Applied, DecodeError>

Applies one clientbound play packet.

§Errors

A malformed body (multi-entry packets may be partly applied).

Source

pub fn apply_body( &mut self, packet_id: i32, body: &Bytes, ) -> Result<Applied, DecodeError>

Tracker::apply with the packet id and body.

§Errors

See Tracker::apply.

Methods from Deref<Target = Entities>§

Source

pub fn get(&self, id: i32) -> Option<&Entity>

The entity with this id (including the bot’s own entry, see Entities::self_id).

Source

pub fn len(&self) -> usize

Number of tracked entities (including the bot’s own entry).

Source

pub fn is_empty(&self) -> bool

true when nothing is tracked.

Source

pub fn iter(&self) -> impl Iterator<Item = &Entity>

Other entities (the bot’s own entry is skipped), arbitrary order.

Source

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

The bot’s own entity id (from login). Its entry carries metadata, effects, equipment and riding state, but no position: the client owns its own position.

Source

pub fn me(&self) -> Option<&Entity>

The bot’s own entry.

Source

pub fn within(&self, p: [f64; 3], radius: f64) -> impl Iterator<Item = &Entity>

Entities whose server position is within radius of p (linear scan).

Source

pub fn near(&self, p: [f64; 3], radius: f64) -> impl Iterator<Item = &Entity>

Alias of Entities::within.

Source

pub fn player_info(&self, uuid: &Uuid) -> Option<&PlayerInfo>

The tab list.

Source

pub fn players(&self) -> impl Iterator<Item = (&Uuid, &PlayerInfo)>

All tab-list entries.

Source

pub fn player_name(&self, id: i32) -> Option<&str>

Name of a player entity (from the tab list: the full one, or the names-only one of Config::player_names).

Source

pub fn tab_name(&self, uuid: &Uuid) -> Option<&str>

Profile name of a tab-list entry (full list or names only).

Source

pub fn tab_game_mode(&self, uuid: &Uuid) -> Option<i32>

Game mode of a tab-list entry (full list or names only).

Source

pub fn tab_len(&self) -> usize

Number of tab-list entries kept (full list or names only).

Source

pub fn config(&self) -> Config

The configuration.

Trait Implementations§

Source§

impl Clone for Tracker

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 Tracker

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Deref for Tracker

Source§

type Target = Entities

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Entities

Dereferences the value.

Auto Trait Implementations§

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.