Skip to main content

TickContext

Struct TickContext 

Source
pub struct TickContext<'a> { /* private fields */ }
Expand description

The behaviour’s view of the client during one tick.

Reading is free; actions are written to the server in call order before this tick’s movement packet.

Implementations§

Source§

impl TickContext<'_>

Source

pub fn tick(&self) -> u64

Ticks since the connection entered the play state.

Source

pub fn version(&self) -> GameVersion

The protocol version of this connection.

Source

pub fn pose(&self) -> &Pose

The client pose now (start of the tick, before this tick’s rotation and movement).

Source

pub fn sent(&self) -> &Pose

The last pose written to the server: what it judges this tick’s actions against.

Source

pub fn eyes(&self, pose: &Pose) -> Vec3

Eye position of pose (standing or sneaking eye height of this version).

Source

pub fn world(&self) -> &dyn WorldView

The world (loaded chunk columns and their blocks).

Source

pub fn events(&self) -> &TickEvents

What happened since the previous tick.

Source

pub fn entity_id(&self) -> i32

Our entity id.

Source

pub fn swings(&self) -> u64

Arm swings (main and off hand) written so far in the session: every arm_animation, whether from TickContext::swing, an action (place, dig, attack) or the held buttons (digging swings every tick). Includes this tick’s written so far.

Source

pub fn health(&self) -> Health

Health, food and saturation.

Source

pub fn is_dead(&self) -> bool

The player is dead (waiting for TickContext::respawn).

Source

pub fn game_mode(&self) -> GameMode

Game mode.

Source

pub fn abilities(&self) -> Abilities

Abilities as the server sent them.

Source

pub fn can_fly(&self) -> bool

The server allows flight.

Source

pub fn held_slot(&self) -> u8

The selected hotbar slot (0 … 8).

Source

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

Id of the open container window, if the server opened one.

Source

pub fn dimension(&self) -> &str

The current dimension ("0" / "-1" / "1" on 1.8, the world name on 1.16).

Source

pub fn controls(&self) -> Controls

The movement controls recorded for this tick.

Source

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

The rotation target.

Source

pub fn chat(&mut self, text: impl Into<String>)

Sends a chat line or command (truncated to the version’s limit, 100 / 256 UTF-16 units, like vanilla).

Source

pub fn respawn(&mut self) -> bool

Asks the server to respawn the player. Only sent while dead; returns whether it was.

Source

pub fn select_slot(&mut self, slot: u8)

Selects a hotbar slot (0 … 8); sends held_item_slot when it changes. Out-of-range slots are ignored.

Source

pub fn swing(&mut self)

Swings the arm (arm_animation).

Source

pub fn disconnect(&mut self, reason: impl Into<String>)

Ends the session after this tick’s packets are written.

Source

pub fn set_aim(&mut self, yaw: f32, pitch: f32)

Rotation target for this tick: the client turns toward it in whole mouse counts (at most 14° yaw / 10.5° pitch per tick). Call it every tick you want to turn.

Source

pub fn set_controls(&mut self, controls: Controls)

Movement keys from now on (kept until changed); the physics turns them into movement like vanilla’s Input (sneaking scales walking by 0.3).

Source

pub fn inventory(&self) -> &Inventory

The inventory: player slots, cursor, the open window, the pending click.

Source

pub fn click(&mut self, click: Click) -> Result<ClickTicket, ClickRefused>

Clicks in the open screen (window_click, written now). Refused (nothing sent) while the player is turning (the look changed in the last movement step or an aim is set for this tick: clicks only while still) or when the inventory refuses it (one click in flight, same-tick packet order, unpredictable result, …). The result arrives in TickEvents::inventory on a later tick.

Source

pub fn open_inventory(&mut self) -> Result<(), ClickRefused>

Opens the player inventory GUI (1.8: the “open inventory” client command; 1.16: nothing is sent). Window 0 clicks need it open.

Source

pub fn close_window(&mut self) -> Result<(), ClickRefused>

Closes the open GUI (close_window with its id; 0 for the player inventory).

Source

pub fn set_buttons(&mut self, buttons: Buttons)

Mouse buttons from now on (kept until changed; released by a join, a respawn or an open window). Left held mines what the crosshair is on, right held uses / places (vanilla’s key processing, after the behaviour and before the movement packet).

Source

pub fn buttons(&self) -> Buttons

The buttons held.

Source

pub fn target(&self) -> Option<BlockHit>

What the crosshair is on as the server judges it: the first block within reach 4.5 along the sent look from the sent eyes.

Source

pub fn entities(&self) -> Option<&Entities>

The tracked entities (behaviours that ask for Interests::ENTITIES).

Source

pub fn target_entity(&self) -> Option<EntityHit>

The entity the crosshair is on as the server judges it (from the sent pose; vanilla’s entity pick: reach 3, 1.8 boxes grown by 0.1, closer than the block hit).

Source

pub fn attack(&mut self, entity: i32) -> bool

Attacks entity (use_entity attack and the arm swing in the version’s order; 1.16 resets the attack cooldown). Refused (false, nothing sent) unless the sent crosshair is on that entity.

Source

pub fn attack_strength(&self, attack_speed: f64) -> f32

1.16 attack strength 0 … 1 for an attack speed (4.0 for an empty hand, swords 1.6, axes 0.8–1.0); 1.0 on 1.8 (no cooldown).

Source

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

The block being broken with the left button and its progress 0 … 1.

Source

pub fn broken(&self) -> u64

Blocks broken so far (finish sent).

Source

pub fn using_item(&self) -> bool

Using the held item (eating, blocking, drawing a bow): movement input is slowed.

Source

pub fn dig(&mut self, pos: BlockPos, face: Face) -> bool

Starts digging pos on face (block_dig start, then an arm swing), breaking it at once when it is instant for the held item. Refused (nothing sent, false) unless the crosshair from the sent pose is on exactly that block face.

Source

pub fn place(&mut self, support: BlockPos, face: Face, hit: Vec3) -> bool

Right-clicks support’s face at the absolute point hit (block_place, then an arm swing): places the held block or activates the block. Refused (nothing sent, false) unless the crosshair from the sent pose is on exactly that block face.

Source

pub fn last_inbound(&self) -> Option<Instant>

When the last inbound bytes arrived (a gap before a setback means lag).

Source

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

The yaw / pitch this tick’s movement step will use, from this tick’s TickContext::set_aim and the digs / places written so far (incl. the turn held by crate::Client::hold_turn_on_action). Computed on a copy: the rotation’s carried budget does not change. Clicks of held buttons, which run after the behaviour, are not seen. Without an aim this tick: the current look.

Source

pub fn set_flying(&mut self, flying: bool)

Starts or stops creative-style flight: the abilities packet goes out before this tick’s movement step, like a double-tapped jump (but without the jump). Starting needs the server’s “may fly” ability; asking for the current state sends nothing.

Source

pub fn held_turns(&self) -> u64

Turns held back so far because they would have taken the crosshair off a block dug or placed on the same tick (see crate::Client::hold_turn_on_action).

Source

pub fn status(&mut self, text: &str)

Behaviour status line (logged when it changes).

Trait Implementations§

Source§

impl Debug for TickContext<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for TickContext<'a>

§

impl<'a> !Send for TickContext<'a>

§

impl<'a> !Sync for TickContext<'a>

§

impl<'a> !UnwindSafe for TickContext<'a>

§

impl<'a> Freeze for TickContext<'a>

§

impl<'a> Unpin for TickContext<'a>

§

impl<'a> UnsafeUnpin for TickContext<'a>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more