ghast-client 0.5.6

Headless Minecraft Java Edition client for the ghast library: connection, login, fixed 50 ms tick loop and a version-agnostic bot API (1.8.9, 1.12.2, 1.16.5, 26.1, 26.2 and 26.3)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
//! [`TickContext`], the behaviour's view of one tick: its state readers (pose, world, events,
//! health, effects, HUD, time, abilities, slots) and the simple actions and intents (chat, tab
//! completion, respawn, slot selection, swing, drop and swap keys, raw packets, disconnect,
//! aim, controls). Windows, dialogs and the world actions are in `windows.rs` and
//! `actions.rs`.

use super::view::shared_getters;
use super::*;

/// 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.
pub struct TickContext<'a> {
    pub(super) core: &'a mut Core,
    pub(super) world: &'a dyn Sim,
    pub(super) held: Option<hands::HeldItem>,
    /// The sent-pose crosshair, picked on the first ask: nothing a behaviour does during its
    /// tick changes the sent pose, the game mode or the world.
    pub(super) crosshair: std::cell::OnceCell<(Option<BlockHit>, Option<hands::EntityHit>)>,
    /// Vanilla's check of a dialog command (`verifyCommand`).
    pub(super) commands: &'a dyn Fn(&str) -> crate::dialog::CommandCheck,
}

impl std::fmt::Debug for TickContext<'_> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("TickContext")
            .field("tick", &self.core.tick)
            .field("pose", &self.core.pose)
            .finish_non_exhaustive()
    }
}

#[cfg(all(test, feature = "v1_8"))]
impl TickContext<'_> {
    /// Test hook: this tick's look without a rotation step.
    pub(crate) fn test_force_look(&mut self, yaw: f32, pitch: f32) {
        self.core.forced_look = Some((yaw, pitch));
    }

    /// Test hook: the rotation controller (to predict a step).
    pub(crate) fn test_rotation(&self) -> Rotation {
        self.core.rotation
    }
}

impl TickContext<'_> {
    /// Ticks since the connection entered the play state.
    #[must_use]
    pub fn tick(&self) -> u64 {
        self.core.tick
    }

    /// The protocol version of this connection.
    #[must_use]
    pub fn version(&self) -> GameVersion {
        self.core.opts.caps.version
    }

    /// The client pose now (start of the tick, before this tick's rotation and movement).
    #[must_use]
    pub fn pose(&self) -> &Pose {
        &self.core.pose
    }

    /// The last pose written to the server: what it judges this tick's actions against.
    #[must_use]
    pub fn sent(&self) -> &Pose {
        &self.core.sent
    }

    /// The player's velocity now (blocks per tick): [`Pose::motion`] after the last movement
    /// step plus what arrived since — the server's velocity for our entity (knockback, a
    /// setback's velocity) and explosion pushes. This tick's movement step starts from it,
    /// after the slow-down of this tick's attacks (applied once the behaviour and the buttons
    /// are done, see [`TickContext::attack`]).
    #[must_use]
    pub fn velocity(&self) -> Vec3 {
        self.world.velocity_now()
    }

    /// The last movement step hit a wall (`horizontalCollision`: the move was cut on x or z).
    /// Vanilla stops a sprint on it (1.8 – 1.16.5; 26.x only on a head-on hit, the minor
    /// collisions keep it).
    #[must_use]
    pub fn horizontal_collision(&self) -> bool {
        self.world.collisions().0
    }

    /// The last movement step was cut vertically (`verticalCollision`: floor or ceiling).
    #[must_use]
    pub fn vertical_collision(&self) -> bool {
        self.world.collisions().1
    }

    shared_getters!(piston_uncertain);

    /// The flags byte (entity data index 0) the server last sent for our entity: 0x01 on
    /// fire, 0x02 sneaking, 0x08 sprinting, 0x10 using an item on 1.8 / swimming on 1.13+,
    /// 0x20 invisible, 0x80 gliding (1.9+). `None` before the server sent one (after a respawn
    /// too, unless the 26.x respawn keeps the entity data). Read without entity tracking.
    ///
    /// The client applies its sprint bit (and 1.9+ gliding, 1.13+ swimming) like vanilla's
    /// entity data: it sets the flag `isSprinting()` reads, not the sprint speed. Sneaking stays
    /// the input's.
    #[must_use]
    pub fn server_flags(&self) -> Option<u8> {
        self.world.server_flags()
    }

    /// The server's last flags byte for us has the sprint bit ([`TickContext::server_flags`];
    /// `false` before any).
    #[must_use]
    pub fn server_sprinting(&self) -> bool {
        self.server_flags().is_some_and(|f| f & 0x08 != 0)
    }

    /// The client's sprint flag now (vanilla's `isSprinting`): after this tick's server packets
    /// (the flags byte of our entity data sets it, [`TickContext::server_flags`]), before this
    /// tick's attacks and movement step. [`TickContext::pose`]'s `sprinting` is the flag after
    /// the last movement step; this one is what an attack issued now reads.
    #[must_use]
    pub fn sprinting(&self) -> bool {
        self.world.sprinting()
    }

    /// Whether an attack on `entity` issued now with [`TickContext::attack`] would slow the bot
    /// (a press's attack runs in the key handling, where 1.9+ has counted one more tick of
    /// attack strength): a hit the client counts as landed (another
    /// player, a boat, a minecart, an end crystal; never a mob, nor an entity it does not
    /// track) with knockback (the held item's Knockback level on 1.8 – 1.16.5, plus one for a
    /// sprint attack, which 1.9+ grants only above 0.9 attack strength). Such a hit multiplies
    /// the velocity x / z by 0.6 and ends the sprint before this tick's movement. This tick's
    /// earlier attacks count: one that already ended the sprint leaves no sprint bonus.
    #[must_use]
    pub fn attack_slows(&self, entity: i32) -> bool {
        use super::items::{attack_hurts, attack_knockback, sprint_bonus};
        use crate::sim::attack_knockback_applies as applies;
        let c = &*self.core;
        if c.game_mode == GameMode::Spectator || !attack_hurts(self.world, entity) {
            return false;
        }
        let knockback = attack_knockback(c);
        let mut sprinting = self.world.sprinting();
        for &(id, ticks) in &c.hands.attacks {
            if attack_hurts(self.world, id) && applies(knockback, sprinting, sprint_bonus(c, ticks))
            {
                sprinting = false;
            }
        }
        applies(
            knockback,
            sprinting,
            sprint_bonus(c, c.hands.ticks_since_swing),
        )
    }

    /// Eye position of `pose` (standing or sneaking eye height of this version).
    #[must_use]
    pub fn eyes(&self, pose: &Pose) -> Vec3 {
        let v = self.core.opts.caps;
        pose.eyes(if pose.sneaking {
            v.sneak_eye_height
        } else {
            v.eye_height
        })
    }

    /// The world (loaded chunk columns and their blocks).
    #[must_use]
    pub fn world(&self) -> &dyn WorldView {
        self.world
    }

    /// The expected flight of `throw` if the player threw or shot it now: launched from the
    /// last sent pose (where the server has the player, see [`TickContext::sent`]) with the
    /// player's motion ([`TickContext::velocity`]; 1.8 adds none) and no random spread, then
    /// ticked as the server ticks it until its first block hit or `max_ticks` ticks — the
    /// version's oracle-proven launch and projectile physics
    /// (`ghast_physics::<version>::{launch, projectile}`). `None` when the version has no such
    /// item (a trident before 1.13, a wind charge or crossbow arrow before 26.x) or a bow was
    /// not drawn long enough. Entities in the way are not seen. See [`crate::throw`].
    ///
    /// ```no_run
    /// use ghast_client::throw::Throw;
    /// # fn f(ctx: &ghast_client::TickContext<'_>) {
    /// if let Some(p) = ctx.predict_throw(Throw::EnderPearl, 200)
    ///     && let Some(hit) = p.hit
    /// {
    ///     println!("lands on {:?} after {} ticks", hit.block, hit.tick);
    /// }
    /// # }
    /// ```
    #[must_use]
    pub fn predict_throw(
        &self,
        throw: crate::throw::Throw,
        max_ticks: u32,
    ) -> Option<crate::throw::ThrowPrediction> {
        let p = &self.core.sent;
        let caps = self.core.opts.caps;
        let shooter = crate::throw::Shooter {
            pos: p.pos,
            eye_height: if p.sneaking {
                caps.sneak_eye_height
            } else {
                caps.eye_height
            },
            yaw: p.yaw,
            pitch: p.pitch,
            motion: self.velocity(),
            on_ground: p.on_ground,
        };
        crate::throw::predict(self.world, caps.version, throw, &shooter, max_ticks)
    }

    /// 26.1: the client player's complete movement state as the physics holds it now (start of
    /// the tick): the attributes the server sent (movement speed, step height, jump strength,
    /// scale, ...), effects, abilities and the level's build height. Clone it to simulate
    /// ahead with `ghast_physics::modern::tick`. `None` on the other versions.
    #[cfg(ghast_modern)]
    #[must_use]
    pub fn modern_player(&self) -> Option<&ghast_physics::modern::PlayerState> {
        self.world.modern_player()
    }

    /// What happened since the previous tick.
    #[must_use]
    pub fn events(&self) -> &TickEvents {
        &self.core.current
    }

    shared_getters!(entity_id);

    /// 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.
    #[must_use]
    pub fn swings(&self) -> u64 {
        self.core.swings + count_swings(&self.core.out)
    }

    shared_getters!(
        health,
        effects,
        spawn_position,
        teams,
        hud,
        last_hurt_tick,
        world_time
    );

    /// The player is dead (waiting for [`TickContext::respawn`]).
    #[must_use]
    pub fn is_dead(&self) -> bool {
        self.core.dead
    }

    shared_getters!(game_mode, item_cooldowns);

    /// Abilities as the server sent them.
    #[must_use]
    pub fn abilities(&self) -> Abilities {
        self.core.abilities
    }

    /// The server allows flight.
    #[must_use]
    pub fn can_fly(&self) -> bool {
        self.core.abilities.may_fly()
    }

    /// The selected hotbar slot (0 … 8).
    #[must_use]
    pub fn held_slot(&self) -> u8 {
        self.core.held_slot
    }

    /// Id of the open container window, if the server opened one.
    #[must_use]
    pub fn open_window(&self) -> Option<i32> {
        (self.core.open_window != 0).then_some(self.core.open_window)
    }

    /// The current dimension (`"0"` / `"-1"` / `"1"` on 1.8, the world name on 1.16).
    #[must_use]
    pub fn dimension(&self) -> &str {
        &self.core.dimension
    }

    /// The movement controls recorded for this tick.
    #[must_use]
    pub fn controls(&self) -> Controls {
        self.core.controls
    }

    /// The rotation target.
    #[must_use]
    pub fn aim(&self) -> (f32, f32) {
        self.core.rotation.target()
    }

    // ---- actions: written now, before this tick's movement packet ----

    /// Sends a chat line or command (truncated to the version's limit, 100 / 256 UTF-16
    /// units, like vanilla).
    pub fn chat(&mut self, text: impl Into<String>) {
        self.core.out.push(Outbound::Chat(text.into()));
    }

    /// Asks the server to complete `text` (`tab_complete` / `command_suggestion`, written now)
    /// and returns the request's number; the answer arrives as a
    /// [`crate::hud::TabCompletion`] with that number in [`TickEvents::tab_completions`] on a
    /// later tick.
    ///
    /// The request is raw: what vanilla would ask for is the caller's business. A 1.13+
    /// client completes most of a command itself from the server's command tree and asks the
    /// server only at argument nodes whose suggestion type is `minecraft:ask_server` in the
    /// server's `declare_commands` tree (the client's command tree, kept for chat signing,
    /// does not model suggestions), sending the whole line with its leading `/`; the
    /// 1.8 – 1.12.2 chat screen sends the line as typed and completes its last word. The
    /// transaction id is the one vanilla would use (`pendingSuggestionsId`: 0 again once the
    /// pending request was answered). Servers refuse texts over 32500 characters (26.x) and
    /// may rate-limit requests.
    pub fn tab_complete(&mut self, text: impl Into<String>) -> u32 {
        self.tab_complete_with(text, false, None)
    }

    /// [`TickContext::tab_complete`] with the 1.8 – 1.12.2 extras: `assume_command` (1.12.2,
    /// completion as a command without the leading `/`, as command blocks ask) and the block
    /// the crosshair is on (the legacy chat screen sends it; servers complete coordinates
    /// with it). Newer versions do not send them.
    pub fn tab_complete_with(
        &mut self,
        text: impl Into<String>,
        assume_command: bool,
        block: Option<ghast_protocol::BlockPos>,
    ) -> u32 {
        let text = text.into();
        let (request, id) = self.core.tabs.request(&text);
        self.core.out.push(Outbound::TabComplete {
            id,
            text,
            assume_command,
            block,
        });
        request
    }

    /// Asks the server to respawn the player. Only sent while dead; returns whether it was.
    pub fn respawn(&mut self) -> bool {
        if self.core.dead {
            self.core.out.push(Outbound::Respawn);
            true
        } else {
            false
        }
    }

    /// Selects a hotbar slot (0 … 8); sends `held_item_slot` when it changes. Out-of-range
    /// slots are ignored. After the server set the held slot (not echoed yet), another slot
    /// sends the echo first and then the new slot, as a hotbar key after vanilla's slot sync
    /// followed by a click does (oracle `slot_server_then_key`).
    pub fn select_slot(&mut self, slot: u8) {
        if slot < 9 {
            // The server changed the slot since the last sync: its echo goes first, as the
            // tick's `syncSelectedSlot` sends it before a hotbar key changes the slot again
            // (without it the server would keep its slot while ours is the old one).
            if self.core.held_slot != slot {
                self.echo_server_slot();
            }
            if self.core.held_slot != slot {
                // 1.8 – 1.16.5: the use ends in the player tick after the key handling
                // (`use_mark`).
                if self.core.opts.caps.use_stop == crate::version::UseStop::AtSelect {
                    self.core.hands.stop_using();
                }
                // 1.12: the cooldown resets in that player tick too (`cooldown_held`).
                if self.core.opts.caps.cooldown_reset == crate::version::CooldownReset::AtSelect {
                    self.core.hands.ticks_since_swing = 0;
                }
            }
            self.core.held_slot = slot;
            self.core.inv.select(slot);
            if self.core.sent_slot != slot {
                self.core.sent_slot = slot;
                self.core.out.push(Outbound::HeldSlot(i16::from(slot)));
            }
        }
    }

    /// Whether the right button's outcome on a mob follows the mob's real state: `true` when
    /// the tracker keeps the entity data ([`Interests::ENTITIES`]). Without it a click on a
    /// mob is judged as on a fresh one (adult, untamed, unsheared, white, unsaddled): a
    /// sheared sheep, a baby, a saddled pig or a tamed wolf can then get packets or a stack
    /// change the real client would not make. Paintings, vehicles, armor stands and other
    /// objects do not depend on it.
    #[must_use]
    pub fn mob_state_known(&self) -> bool {
        self.world.entities().is_some_and(|e| e.config().metadata)
    }

    /// Swings the arm (`arm_animation`; 26.3, which has no serverbound swing: `punch`, the
    /// packet its attack and dig clicks send) and nothing else. Vanilla's left click on air also
    /// starts the 10-tick miss delay outside creative (no click until it ran out or the button
    /// is released; 1.9+ resets the attack cooldown too): the left button of
    /// [`TickContext::set_buttons`] models that, this swing does not.
    pub fn swing(&mut self) {
        let caps = self.core.opts.caps;
        self.core.out.push(attack_swing(caps));
    }

    /// The drop key outside a screen (`MinecraftClient.handleInputEvents`): a `player_action`
    /// that drops one item of the held stack, or the whole stack with `whole_stack` (the key
    /// with control held), written now. It goes out with an empty hand too, like vanilla.
    /// 1.16.5 and 26.x predict it as vanilla does (`ClientPlayerEntity.dropSelectedItem`,
    /// `LocalPlayer.drop`): the item leaves the held slot at once (the server's `set_slot`
    /// then confirms or corrects it) and, when one did, the main arm swings (`arm_animation`
    /// after the drop); a use of the held item ends with its stack. 1.8.9 and 1.12.2 send the
    /// drop alone and wait for the server's slot update. A held slot the server set since the
    /// last sync is echoed first (vanilla syncs the slot before its key handling; 26.3's
    /// `dropItem` syncs it again). Refused (nothing sent, `false`) while a screen is open (a
    /// window, the player inventory, a dialog: vanilla's keys then go to the screen), while
    /// dead, or in spectator mode.
    pub fn drop_held(&mut self, whole_stack: bool) -> bool {
        if !self.keys_reach_player() {
            return false;
        }
        self.echo_server_slot();
        let c = &mut *self.core;
        c.out.push(Outbound::Dig {
            status: if whole_stack {
                crate::common::DigStatus::DropStack
            } else {
                crate::common::DigStatus::DropItem
            },
            pos: ghast_protocol::BlockPos::new(0, 0, 0),
            face: crate::common::Face::Down,
        });
        let before = c.hands.dig_follows_held().then(|| c.inv.held().cloned());
        if c.opts.caps.drop_prediction && c.inv.drop_held(whole_stack) {
            if let Some(before) = before {
                c.hands.held_changed_in_place(before.as_ref(), c.inv.held());
            }
            if c.inv.held().is_none() && c.hands.use_item().is_some_and(|(off, _)| !off) {
                // tickActiveItemStack / updatingUsingItem: the used stack is gone.
                c.hands.stop_using();
            }
            if c.opts.caps.sends_swing {
                c.out.push(Outbound::Swing);
            }
            // A dig or place later in this tick sees the new hand, as in vanilla's key order.
            self.held = held_item(&self.core.inv, self.world);
        }
        true
    }

    /// The swap-hands key outside a screen (1.9+): a `player_action` that swaps the main- and
    /// off-hand stacks, written now. Like vanilla the client predicts nothing: both stacks
    /// come back in the server's slot updates (1.16.5: a use of the main or off hand then ends
    /// unless that hand still holds the used item). Sent while an item is in use too, as
    /// vanilla does. Refused (nothing sent, `false`) on 1.8.9 (no off hand), while a screen is
    /// open, while dead, or in spectator mode.
    pub fn swap_hands(&mut self) -> bool {
        if !self.core.opts.caps.combat_1_9 || !self.keys_reach_player() {
            return false;
        }
        self.echo_server_slot();
        self.core.out.push(Outbound::Dig {
            status: crate::common::DigStatus::SwapHands,
            pos: ghast_protocol::BlockPos::new(0, 0, 0),
            face: crate::common::Face::Down,
        });
        true
    }

    /// A held slot the server set since the last sync goes back first: vanilla's tick syncs
    /// the slot (`ensureHasSentCarriedItem` / `syncSelectedSlot`) before its key handling, so a
    /// key action of the same tick follows the echo.
    pub(super) fn echo_server_slot(&mut self) {
        let c = &mut *self.core;
        if c.slot_from_server {
            c.slot_from_server = false;
            if c.sent_slot != c.held_slot {
                c.sent_slot = c.held_slot;
                c.out.push(Outbound::HeldSlot(i16::from(c.held_slot)));
            }
        }
    }

    /// Vanilla handles the drop and swap keys only without a screen and for a living,
    /// non-spectator player.
    pub(super) fn keys_reach_player(&self) -> bool {
        let c = &*self.core;
        !c.inv.gui_open()
            && c.dialog.is_none()
            && c.sign.is_none()
            && !c.dead
            && c.game_mode != GameMode::Spectator
    }

    /// Escape hatch: queues a serverbound play packet the behaviour encoded itself (`id` and
    /// `body` of this session's protocol version, see [`TickContext::version`]), written as
    /// given in call order with the other actions, before this tick's movement packet.
    /// **You are responsible for protocol correctness**: the client does not look at it, so a
    /// packet that changes state it models (movement, held slot, windows, digging) makes the
    /// client and the server disagree.
    pub fn send_raw(&mut self, id: i32, body: impl Into<bytes::Bytes>) {
        self.core
            .out
            .push(Outbound::Raw(ghast_protocol::RawPacket::new(
                id,
                body.into(),
            )));
    }

    /// [`TickContext::send_raw`] with a generated packet type (e.g. from
    /// `ghast::protocol::v26_2::play::serverbound`); it must belong to this session's version.
    /// Refused (nothing queued) unless it is a serverbound play packet.
    pub fn send_packet<P: ghast_protocol::Packet>(
        &mut self,
        packet: &P,
    ) -> Result<(), ghast_protocol::EncodeError> {
        if P::STATE != ghast_protocol::State::Play
            || P::DIRECTION != ghast_protocol::Direction::Serverbound
        {
            return Err(ghast_protocol::EncodeError::Invalid(
                "not a serverbound play packet",
            ));
        }
        let mut body = bytes::BytesMut::new();
        packet.encode(&mut body)?;
        self.send_raw(P::ID, body.freeze());
        Ok(())
    }

    /// Ends the session after this tick's packets are written.
    pub fn disconnect(&mut self, reason: impl Into<String>) {
        self.core.quit = Some(reason.into());
    }

    // ---- intent for this tick's movement step ----

    /// Rotation target for this tick: the client turns toward it in whole mouse counts, at
    /// most [`TickContext::turn_rate`] degrees per tick (yaw, pitch; set at connect with
    /// [`crate::Client::turn_rate`], default 14° / 10.5°, changed with
    /// [`TickContext::set_turn_rate`]). Call it every tick you want to turn.
    pub fn set_aim(&mut self, yaw: f32, pitch: f32) {
        self.core.rotation.set_target(yaw, pitch);
        self.core.aimed = true;
    }

    /// Changes the aim's cap to at most `yaw` / `pitch` degrees per tick from this tick's turn
    /// on (kept until changed; a new session starts from [`crate::Client::turn_rate`]). Turns
    /// stay whole mouse counts and the mouse budget carried between ticks is kept. A value that
    /// is not finite and positive keeps that axis's cap. Call it before
    /// [`TickContext::planned_look`] or [`TickContext::press_preview`] for them to see it.
    pub fn set_turn_rate(&mut self, yaw: f64, pitch: f64) {
        self.core.rotation.set_turn_rate(yaw, pitch);
    }

    /// The aim's cap per tick: (yaw, pitch) degrees ([`TickContext::set_turn_rate`]).
    #[must_use]
    pub fn turn_rate(&self) -> (f64, f64) {
        self.core.rotation.turn_rate()
    }

    /// Movement keys from now on (kept until changed); the physics turns them into movement
    /// like vanilla's `Input` (sneaking scales walking by 0.3).
    pub fn set_controls(&mut self, controls: Controls) {
        self.core.controls = controls;
    }
}