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
574
575
576
577
578
579
580
581
582
583
584
585
586
//! [`TickContext`]'s actions in the world: the mouse buttons, the crosshair as the server
//! judges it and the press preview, attacks, digs and places, item facts and dig speeds,
//! riding and gliding, flight, the planned look and the status line.
use super::*;
impl TickContext<'_> {
/// 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).
/// A left press on air (or on nothing in reach) starts vanilla's 10-tick miss delay
/// outside creative: no attack or dig until it ran out, and releasing the button ends it.
/// A new right press needs a released tick before it; held, right re-uses every 4 ticks.
/// On 1.8 / 1.12 a use the held button restarts in the tick of a finish is ended by the
/// server's stack update a tick later, as in the real client, while the server keeps
/// using ([`crate::common::UseEvent::Interrupted`]): release the button for one tick on
/// [`crate::common::UseEvent::Finished`] when that matters.
///
/// A right click on a mob follows the mob's state only with the entity data tracked
/// ([`TickContext::mob_state_known`]); otherwise it is judged as on a fresh mob.
///
/// **Entities are invisible without entity tracking** ([`Interests::ENTITIES`] or
/// [`Interests::ENTITY_TRACKING`]): the crosshair then sees blocks only (a player or mob in
/// front of the block does not stop the dig and cannot be attacked) and nothing pushes the
/// bot. Ask for one of the interests when other entities matter.
pub fn set_buttons(&mut self, buttons: Buttons) {
self.core.buttons = buttons;
}
/// Queues one press of `button` for this tick's key handling, as a mouse click between
/// two ticks queues one in vanilla (1.8 – 1.16.5 `while (attackKey.wasPressed())`, 26.x
/// `consumeClick`): N calls are N clicks in this tick. Returns whether the press was
/// queued: only [`hands::Button::Left`] is (the right button's repeated presses in one
/// tick are not modelled; a right press is a [`TickContext::set_buttons`] edge).
///
/// Each click is the left button's own click, vanilla-exact: the turn toward
/// [`TickContext::set_aim`] comes first (as on every tick), then the whole key handling
/// picks once (from the client's current position with this tick's look, on 1.8 with the
/// head yaw; entities at their drawn position: [`TickContext::press_preview`] gives the
/// result) and every click of the tick acts on that pick in order: an entity is attacked
/// with the arm swing in the version's order (1.8: swing first; 1.9+: after) and its
/// attack slow-down, 1.9+ resets the attack cooldown on every click; a block starts its
/// dig; a miss (air, nothing in reach) swings and starts the 10-tick miss delay outside
/// creative, which holds back the rest of this tick's clicks and ends when the button is
/// up at the end of the key handling ([`Buttons`] left released). The movement packet that
/// follows carries the look of the pick, so no turn is held. A held left button's press
/// edge is one more click; a use in progress, an open screen or death drops the presses.
///
/// Several clicks in a tick land on one entity (the pick's), so they never attack two
/// entities in one tick; [`TickContext::attack`] calls on different entities in one tick
/// do (an anticheat may flag that).
pub fn press(&mut self, button: hands::Button) -> bool {
match button {
hands::Button::Left => {
self.core.clicks = self.core.clicks.saturating_add(1);
true
}
_ => false,
}
}
/// **Not vanilla when off**: whether other entities push the player from now on (default
/// on, see [`crate::Client::entity_push`]). Takes effect on this tick's entity ticks; a
/// no-op without entity tracking ([`Interests::ENTITIES`] or
/// [`Interests::ENTITY_TRACKING`]: no entities are known, so nothing pushes) and on 1.8.9,
/// whose client never pushes the player.
pub fn set_entity_push(&mut self, on: bool) {
self.core.entity_push = on;
}
/// Whether other entities push the player ([`TickContext::set_entity_push`]).
#[must_use]
pub fn entity_push(&self) -> bool {
self.core.entity_push
}
/// The buttons held.
#[must_use]
pub fn buttons(&self) -> Buttons {
self.core.buttons
}
/// The crosshair as the server judges it: vanilla's pick (block at the game mode's reach,
/// then the entity ray) along the **sent** look from the sent eyes.
fn sent_crosshair(&self) -> (Option<BlockHit>, Option<hands::EntityHit>) {
*self.crosshair.get_or_init(|| self.pick_sent())
}
fn pick_sent(&self) -> (Option<BlockHit>, Option<hands::EntityHit>) {
let s = &self.core.sent;
let v = self.core.opts.caps;
let eye = pick_eye_height(self.world, v, s.sneaking);
let eyes = Vec3::new(s.pos.x, s.pos.y + eye, s.pos.z);
let mut list = PickList::default();
list.fill(self.world, v, eyes);
let t = self.world.crosshair_target(&PickQuery {
eyes,
rotation: (s.yaw, s.pitch),
look: hands::look_vector(s.yaw, s.pitch),
held: None,
now: false,
creative: self.core.game_mode == GameMode::Creative,
player_bb: pick_box(s.pos),
entities: &list.entities,
});
list.split(t, eyes)
}
/// The block the crosshair is on as the server judges it (from the sent pose): `None` when
/// nothing is in reach or an entity is in front of it.
///
/// **Entities count only with [`Interests::ENTITIES`]:** without entity tracking this is a
/// block pick that looks through players and mobs (and nothing pushes the bot).
#[must_use]
pub fn target(&self) -> Option<BlockHit> {
self.sent_crosshair().0
}
/// The tracked entities (behaviours that ask for [`Interests::ENTITIES`]).
#[must_use]
pub fn entities(&self) -> Option<&ghast_entity::Entities> {
self.world.entities()
}
/// The bot's own fishing bobber, while one is out (needs entity tracking:
/// [`Interests::ENTITIES`] or [`Interests::ENTITY_TRACKING`]; see [`crate::fishing`]).
/// Cast and reel in with a right click ([`TickContext::set_buttons`]) while holding a
/// fishing rod; the changes arrive as [`crate::TickEvents::fishing`].
#[must_use]
pub fn fishing(&self) -> Option<&crate::fishing::Bobber> {
self.world.fishing()
}
/// The entity the crosshair is on as the server judges it (from the sent pose; vanilla's
/// pick: within 3 blocks outside creative, nearer than the block hit, boxes grown by the
/// type's targeting margin, each entity's box at its drawn position,
/// [`ghast_entity::Entity::drawn_bounding_box`], as the vanilla client interpolates it).
/// [`TickContext::attack`] checks this pick; a tick with an attack or interact keeps its
/// look (the movement packet after it carries the pick's look). The buttons pick from the
/// client's current position with this tick's look (after this tick's turn):
/// [`TickContext::press_preview`] gives their exact result.
#[must_use]
pub fn target_entity(&self) -> Option<hands::EntityHit> {
self.sent_crosshair().1
}
/// What a press of `button` would act on in this tick's key handling, computed exactly
/// as that key handling will (it runs after the behaviour's tick and the turn, before the
/// movement step): vanilla's crosshair pick from the client's current position — the
/// position of the last movement step, not [`TickContext::sent`] — with this tick's look
/// ([`TickContext::planned_look`]: call [`TickContext::set_aim`] first; on 1.8 with the
/// yaw before the turn, the head yaw vanilla's pick reads), the held item
/// and each entity at its drawn position, then the button's rules (an entity wins over a
/// block; a block hit on a block broken earlier in this tick or on air counts as none).
/// It says what a press acts on, not whether the key handling presses at all this tick
/// (the miss delay, a block being broken, a use in progress, a 4-tick right-click delay,
/// an open screen or death hold it back). Actions later in this tick that change the
/// world, the held slot or the entities can change the result.
///
/// [`TickContext::target_entity`] is the server's view of the same pick (from the sent
/// pose, without the held item): it equals this pick when the last movement packet
/// carried the current position and look and nothing moved since. Use this one to decide
/// on a right press that must not interact with an entity.
#[must_use]
pub fn press_preview(&self, button: hands::Button) -> hands::PressOutcome {
use hands::PressOutcome;
let c = &*self.core;
let caps = c.opts.caps;
let eye = pick_eye_height(self.world, caps, c.pose.sneaking);
let eyes = Vec3::new(c.pose.pos.x, c.pose.pos.y + eye, c.pose.pos.z);
let mut list = PickList::default();
list.fill(self.world, caps, eyes);
let (mut yaw, pitch) = self.planned_look();
if c.opts.caps.pick_head_yaw
&& let Some(y) = c.head_yaw
{
yaw = y;
}
let t = self.world.crosshair_target(&PickQuery {
eyes,
rotation: (yaw, pitch),
look: hands::look_vector(yaw, pitch),
held: c.inv.held().and_then(|s| u16::try_from(s.id()).ok()),
now: true,
creative: c.game_mode == GameMode::Creative,
player_bb: pick_box(c.pose.pos),
entities: &list.entities,
});
match list.split(t, eyes) {
(_, Some(e)) => return PressOutcome::Entity(e),
(Some(hit), None)
if !c.broken_now.contains(&hit.pos)
&& self
.world
.block_query(hit.pos.x, hit.pos.y, hit.pos.z)
.is_some_and(|b| !b.air) =>
{
return PressOutcome::Block(hit);
}
_ => {}
}
let has_item = c.inv.held().is_some() || (caps.combat_1_9 && c.inv.offhand().is_some());
match button {
hands::Button::Right if has_item && c.game_mode != GameMode::Spectator => {
PressOutcome::Item
}
_ => PressOutcome::Nothing,
}
}
/// Attacks `entity` now (`use_entity` attack and the arm swing in the version's order,
/// written before this tick's key handling; 1.9+ resets the attack cooldown). Refused
/// (`false`, nothing sent) while dead and unless [`TickContext::target_entity`] is that
/// entity: the pick from the **sent** position with the **sent** look (the last movement
/// packet's), not this tick's turn. A tick with an attack holds the turn by default
/// ([`crate::Client::hold_turn_on_action`]), so the movement packet after it carries the
/// look it was checked with. It checks no miss delay, attack cooldown or click rate and
/// may run several times per tick. For vanilla's clicks (the pick with this tick's look,
/// the miss delay, more than one click per tick) use [`TickContext::press`].
///
/// Like vanilla's `PlayerEntity.attack` (the left button's attacks too), a hit the client
/// counts as landed — another player, a boat, a minecart, an end crystal (never a mob) —
/// with knockback slows the bot before this tick's movement: velocity x / z × 0.6 and the
/// sprint ends (it starts again in the same step while the sprint key is held, without a
/// packet). Knockback is the held item's Knockback level (1.8 – 1.16.5; the 26.x client
/// has none) plus one for a sprint attack, which 1.9+ grants only at an attack strength
/// above 0.9. Grim predicts the same slow-down.
pub fn attack(&mut self, entity: i32) -> bool {
if self.core.dead || self.target_entity().is_none_or(|e| e.id != entity) {
return false;
}
let modern = self.core.opts.caps.combat_1_9;
self.with_hands(None, DigFactors::default(), |hands, io| {
if !modern {
io.out.push(Outbound::Swing);
}
hands.attack(entity, io);
});
if modern {
let c = &mut *self.core;
c.out.push(attack_swing(c.opts.caps));
}
true
}
/// Runs `run` on the hands with the I/O of a behaviour's world action ([`Self::attack`],
/// [`Self::dig`], [`Self::place`]): the block lookup, the version's right-click rules and
/// the player's state, without a crosshair, an entity or the off hand.
fn with_hands<R>(
&mut self,
held_stack: Option<ghast_inventory::Stack>,
factors: DigFactors,
run: impl FnOnce(&mut Hands, &mut HandsIo<'_>) -> R,
) -> R {
let world = self.world;
let blocks = |x: i32, y: i32, z: i32| world.block_query(x, y, z);
let blocked = |p: ghast_protocol::BlockPos, f: crate::common::Face, id: u16| {
world.place_suppressed(p, f, id)
};
let c = &mut *self.core;
let mut placed = false;
let cooling = if c.cooldowns.is_empty() {
[false; 2]
} else {
cooling_hands(c)
};
// right clicks on blocks: the version's oracle-proven rules (`Sim::place_rules`)
let rules = ClickRules {
sim: world,
inv: &c.inv,
sneaking: c.pose.sneaking,
game_mode: c.game_mode,
yaw: c.pose.yaw,
pitch: c.pose.pitch,
eyes: Vec3::new(0.0, 0.0, 0.0),
food: use_food_level(c),
creative: c.abilities.creative_mode(),
cooling,
};
let mut io = HandsIo {
blocks: &blocks,
target: None,
held: self.held,
held_stack,
inv_version: c.inv.version(),
food: use_food_level(c),
off_held: None,
off_stack: None,
entity: None,
factors,
sneaking: c.pose.sneaking,
out: &mut c.out,
broken: &mut c.broken_now,
placed: &mut placed,
spectator: c.game_mode == GameMode::Spectator,
caps: c.opts.caps,
creative: c.game_mode == GameMode::Creative,
creative_dig: c.game_mode == GameMode::Creative && c.opts.caps.creative_instant_dig,
place_blocked: &blocked,
rules: &rules,
};
let r = run(&mut c.hands, &mut io);
// (the key handling's own `cooled` bits are what the engine reads)
c.hands.cooled = 0;
r
}
/// 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).
#[must_use]
pub fn attack_strength(&self, attack_speed: f64) -> f32 {
if self.core.opts.caps.combat_1_9 {
self.core.hands.attack_strength(attack_speed)
} else {
1.0
}
}
/// The block being broken with the left button and its progress 0 … 1.
#[must_use]
pub fn mining(&self) -> Option<(ghast_protocol::BlockPos, f32)> {
self.core.hands.mining()
}
/// Blocks broken so far (finish sent).
#[must_use]
pub fn broken(&self) -> u64 {
self.core.hands.broken
}
/// Using the held item (eating, blocking, drawing a bow): movement input is slowed.
#[must_use]
pub fn using_item(&self) -> bool {
self.core.hands.using_item()
}
/// 1.19+ (26.1 – 26.3): the block-prediction sequence number of the last predicting packet
/// written so far (`block_dig` start / finish, `block_place`, `use_item` each take the
/// next one; it restarts at 0 in a new level), the number the server's
/// `block_changed_ack` answers with (the client then restores the blocks it broke in those
/// predictions to the server's state). `None` on 1.8.9 – 1.16.5. The packets this tick
/// writes are not counted yet ([`TickView::outbound`] lists them).
#[must_use]
pub fn prediction_sequence(&self) -> Option<i32> {
self.core.sequence
}
/// The vehicle the player rides (26.1 boats and rafts; 1.16.5, 1.12.2 and 1.8.9 boats with
/// entity tracking: boarded when the server's `set_passengers` (1.8.9: `attach_entity`)
/// names the player, e.g. after a right click on the boat with the crosshair on it; the
/// client then moves the boat with the movement keys). Leave it with the sneak key (on
/// 1.12.2 and 1.8.9 the server takes the player off). `None` when not riding.
///
/// Living mounts (horse family, pig, strider, camel, happy ghast, nautilus, llama) and
/// minecarts are reported the same way, with [`crate::common::Vehicle::controlled`] telling
/// whether the client moves it from the keys. Everything riding needs is the normal
/// controls: board with a right click on the entity ([`TickContext::set_buttons`] with the
/// crosshair on it, [`TickContext::target_entity`]); steer with the movement keys and the
/// look; sprint with the sprint key (a camel); the jump key held and released charges and
/// releases the jump bar (horse family jump, camel / nautilus dash: one tenth per held
/// tick after the press, full after 10; the client sends the riding jump on the release);
/// the right button with a carrot / warped fungus on a stick is the boost (an item use);
/// sneak gets off (1.8.9, 1.12.2, 26.x: the sneak reaches the server in the steer / input
/// packet and the server takes the player off; 1.16.5: the client also gets off by itself
/// a tick later). The vehicle's type and the player's seat are in the tracker
/// ([`TickContext::entities`]: the entity's type, its `passengers()` list, index 0
/// steers). ghast-ext wraps these as `Bot::mount`, `Bot::dismount`, `Bot::ride_jump` and
/// `Bot::boost`.
#[must_use]
pub fn vehicle(&self) -> Option<crate::common::Vehicle> {
self.world.vehicle()
}
/// Riding a vehicle ([`TickContext::vehicle`]).
#[must_use]
pub fn is_riding(&self) -> bool {
self.world.vehicle().is_some()
}
/// Gliding with an elytra (1.12.2, 1.16.5, 26.x; shared flag 7: set by the client when a
/// glide starts (on 1.12.2 by the server, after the client asked), cleared by the server on
/// landing, in water or when the elytra breaks).
#[must_use]
pub fn is_gliding(&self) -> bool {
self.world.gliding()
}
/// Starts gliding the way a player does (1.12.2, 1.16.5, 26.x): presses jump for this tick
/// (the controls' `jump`, as [`TickContext::set_controls`] would; release it on the next
/// tick). The client starts a glide on a fresh jump press in the air with an elytra
/// equipped (not on the ground, not flying, not in water, not on a climbable): jump must
/// have been released on the tick before (a held key is not a press). Nothing happens when
/// those conditions do not hold. 1.12.2 only asks (`start_fall_flying`, while falling); the
/// server starts the glide. On 1.12.2 / 1.16.5 the server's glide flag and the rockets it
/// attaches are read from the first such press with an elytra on.
pub fn start_gliding(&mut self) {
self.core.controls.jump = true;
}
/// The version facts of an item stack (tool speeds, block item, food, usable), as the
/// hands use them for the held stack. `None` for ids outside the item id range.
///
/// ```no_run
/// # fn f(ctx: &ghast_client::TickContext<'_>) {
/// if let Some(s) = ctx.inventory().hotbar(0) {
/// let food = ctx.item_facts(s).is_some_and(|f| f.food);
/// }
/// # }
/// ```
#[must_use]
pub fn item_facts(&self, stack: &ghast_inventory::Stack) -> Option<hands::HeldItem> {
let id = u16::try_from(stack.id()).ok()?;
let count = u8::try_from(stack.count().clamp(0, 255)).unwrap_or(0);
Some(crate::sim::held_item_facts(
self.core.opts.caps.data,
id,
count,
efficiency(stack),
))
}
/// Break progress per tick (vanilla `calcBlockBreakingData`) of the block at `pos` dug
/// with `stack` (`None` = empty hand), with the factors the left button uses now: on
/// ground, eyes in water, aqua affinity, haste / mining fatigue. The block breaks once the
/// progress sums to 1, so it takes about `ceil(1 / speed)` ticks; 0 = unbreakable.
/// Creative mode breaks every block at once and is not reflected here. `None` when the
/// column is not loaded.
///
/// ```no_run
/// # fn f(ctx: &ghast_client::TickContext<'_>, pos: ghast_client::BlockPos) {
/// // The hotbar slot that digs `pos` fastest.
/// let best = (0..9u8).max_by(|a, b| {
/// let s = |k: u8| ctx.dig_speed(pos, ctx.inventory().hotbar(k.into())).unwrap_or(0.0);
/// s(*a).total_cmp(&s(*b))
/// });
/// # }
/// ```
#[must_use]
pub fn dig_speed(
&self,
pos: ghast_protocol::BlockPos,
stack: Option<&ghast_inventory::Stack>,
) -> Option<f32> {
let b = self.world.block_query(pos.x, pos.y, pos.z)?;
if b.air {
return Some(0.0);
}
let c = &*self.core;
let eyes = self.eyes(&c.pose);
let in_water = self
.world
.block_query(
eyes.x.floor() as i32,
eyes.y.floor() as i32,
eyes.z.floor() as i32,
)
.is_some_and(|b| b.water);
let held = stack.and_then(|s| self.item_facts(s));
let factors = dig_factors(c, in_water);
Some(hands::relative_hardness(&b, held.as_ref(), factors))
}
/// 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, and while the player is dead.
pub fn dig(&mut self, pos: ghast_protocol::BlockPos, face: crate::common::Face) -> bool {
if self.core.dead
|| !self
.target()
.is_some_and(|t| t.pos == pos && t.face == face)
{
return false;
}
let c = &*self.core;
let held_stack = c.inv.held().cloned();
let factors = dig_factors(c, false);
self.with_hands(held_stack, factors, |hands, io| {
hands.click_block(pos, face, io);
});
let c = &mut *self.core;
c.out.push(attack_swing(c.opts.caps));
true
}
/// 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`)
/// while the player is dead (until the respawn the server would drop it without an answer,
/// and vanilla's death screen takes the input), unless the crosshair from the sent pose is
/// on exactly that block face, and on 1.8.9 /
/// 1.12.2 when the vanilla client would write no packet because the held block cannot go
/// there (the spot next to the face is not replaceable, or the block would overlap the
/// player).
pub fn place(
&mut self,
support: ghast_protocol::BlockPos,
face: crate::common::Face,
hit: Vec3,
) -> bool {
if self.core.dead {
return false;
}
let Some(t) = self.target().filter(|t| t.pos == support && t.face == face) else {
return false;
};
let world = self.world;
let Some(b) = world.block_query(support.x, support.y, support.z) else {
return false;
};
let first = self.core.out.len();
let held_stack = self.core.inv.held().cloned();
self.with_hands(held_stack, DigFactors::default(), |hands, io| {
hands.right_click_block(BlockHit { hit, ..t }, &b, io);
});
let c = &mut *self.core;
if c.out.len() == first {
// 1.8.9 / 1.12.2: the vanilla client would write no block packet (the block item
// cannot go there): nothing is sent.
return false;
}
predict_planting(c, world, first);
if c.opts.caps.sends_swing {
c.out.push(Outbound::Swing);
}
true
}
/// When the last inbound bytes arrived (a gap before a setback means lag).
#[must_use]
pub fn last_inbound(&self) -> Option<Instant> {
self.core.last_inbound
}
/// The yaw / pitch this tick's movement step will use, from this tick's
/// [`TickContext::set_aim`] and the digs / places / attacks written so far (incl. the turn
/// held by [`crate::Client::hold_turn_on_action`]); also the look this tick's key handling
/// picks with (the turn runs after the behaviour, before the buttons and queued presses).
/// Computed on a copy: the rotation's carried budget does not change. Without an aim this
/// tick: the current look.
#[must_use]
pub fn planned_look(&self) -> (f32, f32) {
let c = &*self.core;
let now = (c.pose.yaw, c.pose.pitch);
#[cfg(test)]
if let Some(l) = c.forced_look
&& !c.forced_aim
{
return l;
}
if !c.aimed {
return now;
}
let mut r = c.rotation;
let (yaw, pitch) = r.step(c.pose.yaw, c.pose.pitch);
if c.opts.hold_turn_on_action && !post_look_ok(c, self.world, yaw, pitch) {
now
} else {
(yaw, pitch)
}
}
/// 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.
pub fn set_flying(&mut self, flying: bool) {
self.core.want_flying = Some(flying);
}
/// 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`]).
#[must_use]
pub fn held_turns(&self) -> u64 {
self.core.held_turns
}
/// Behaviour status line (logged when it changes).
pub fn status(&mut self, text: &str) {
if self.core.status != text {
text.clone_into(&mut self.core.status);
log::info!(
"[{}] t{} status: {text}",
self.core.opts.name,
self.core.tick
);
}
}
}