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<'_>
impl TickContext<'_>
Sourcepub fn version(&self) -> GameVersion
pub fn version(&self) -> GameVersion
The protocol version of this connection.
Sourcepub fn pose(&self) -> &Pose
pub fn pose(&self) -> &Pose
The client pose now (start of the tick, before this tick’s rotation and movement).
Sourcepub fn sent(&self) -> &Pose
pub fn sent(&self) -> &Pose
The last pose written to the server: what it judges this tick’s actions against.
Sourcepub fn eyes(&self, pose: &Pose) -> Vec3
pub fn eyes(&self, pose: &Pose) -> Vec3
Eye position of pose (standing or sneaking eye height of this version).
Sourcepub fn events(&self) -> &TickEvents
pub fn events(&self) -> &TickEvents
What happened since the previous tick.
Sourcepub fn swings(&self) -> u64
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.
Sourcepub fn is_dead(&self) -> bool
pub fn is_dead(&self) -> bool
The player is dead (waiting for TickContext::respawn).
Sourcepub fn open_window(&self) -> Option<i32>
pub fn open_window(&self) -> Option<i32>
Id of the open container window, if the server opened one.
Sourcepub fn dimension(&self) -> &str
pub fn dimension(&self) -> &str
The current dimension ("0" / "-1" / "1" on 1.8, the world name on 1.16).
Sourcepub fn chat(&mut self, text: impl Into<String>)
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).
Sourcepub fn respawn(&mut self) -> bool
pub fn respawn(&mut self) -> bool
Asks the server to respawn the player. Only sent while dead; returns whether it was.
Sourcepub fn select_slot(&mut self, slot: u8)
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.
Sourcepub fn disconnect(&mut self, reason: impl Into<String>)
pub fn disconnect(&mut self, reason: impl Into<String>)
Ends the session after this tick’s packets are written.
Sourcepub fn set_aim(&mut self, yaw: f32, pitch: f32)
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.
Sourcepub fn set_controls(&mut self, controls: Controls)
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).
Sourcepub fn inventory(&self) -> &Inventory
pub fn inventory(&self) -> &Inventory
The inventory: player slots, cursor, the open window, the pending click.
Sourcepub fn click(&mut self, click: Click) -> Result<ClickTicket, ClickRefused>
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.
Sourcepub fn open_inventory(&mut self) -> Result<(), ClickRefused>
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.
Sourcepub fn close_window(&mut self) -> Result<(), ClickRefused>
pub fn close_window(&mut self) -> Result<(), ClickRefused>
Closes the open GUI (close_window with its id; 0 for the player inventory).
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).
The buttons held.
Sourcepub fn target(&self) -> Option<BlockHit>
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.
Sourcepub fn entities(&self) -> Option<&Entities>
pub fn entities(&self) -> Option<&Entities>
The tracked entities (behaviours that ask for Interests::ENTITIES).
Sourcepub fn target_entity(&self) -> Option<EntityHit>
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).
Sourcepub fn attack(&mut self, entity: i32) -> bool
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.
Sourcepub fn attack_strength(&self, attack_speed: f64) -> f32
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).
Sourcepub fn mining(&self) -> Option<(BlockPos, f32)>
pub fn mining(&self) -> Option<(BlockPos, f32)>
The block being broken with the left button and its progress 0 … 1.
Sourcepub fn using_item(&self) -> bool
pub fn using_item(&self) -> bool
Using the held item (eating, blocking, drawing a bow): movement input is slowed.
Sourcepub fn dig(&mut self, pos: BlockPos, face: Face) -> bool
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.
Sourcepub fn place(&mut self, support: BlockPos, face: Face, hit: Vec3) -> bool
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.
Sourcepub fn last_inbound(&self) -> Option<Instant>
pub fn last_inbound(&self) -> Option<Instant>
When the last inbound bytes arrived (a gap before a setback means lag).
Sourcepub fn planned_look(&self) -> (f32, f32)
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.
Sourcepub fn set_flying(&mut self, flying: bool)
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.
Sourcepub fn held_turns(&self) -> u64
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).