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
//! Which optional packet groups a behaviour wants.
//!
//! The client always receives what its core needs (keep-alive, teleports, health, windows'
//! confirm transactions, chunk headers, …). Everything else is dropped by the frame
//! decoder *before* it is decoded — when compression is on, after inflating only the bytes
//! that hold the packet id. A busy server's tab list, teams, particles, sounds and entity
//! movement therefore cost almost nothing unless a behaviour asks for them.
use std::ops::{BitOr, BitOrAssign};
/// A set of optional packet groups (see the associated constants).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct Interests(u32);
impl Interests {
/// Nothing optional.
pub const NONE: Interests = Interests(0);
/// Chat messages ([`crate::TickEvents::chat`]).
pub const CHAT: Interests = Interests(1 << 0);
/// Entities (spawns, moves, metadata, equipment, effects): [`crate::TickContext::entities`]
/// and the entity crosshair / attack / interact. Can be switched at run time: tracking then
/// starts empty (entities already spawned stay unknown until the server sends them again)
/// and switching off frees the store.
pub const ENTITIES: Interests = Interests(1 << 1);
/// The tab list (player names and UUIDs) on top of [`Interests::ENTITIES`] — the most
/// expensive packet on busy servers. Switching it restarts the tracker empty.
pub const PLAYER_LIST: Interests = Interests(1 << 2);
/// Skin / cape textures (the base64 `"textures"` profile property) of tab-list entries,
/// on top of [`Interests::PLAYER_LIST`] (`PlayerInfo::textures`). Switching it restarts
/// the tracker empty.
pub const PLAYER_SKINS: Interests = Interests(1 << 4);
/// Block changes (1.8 S23/S22, 1.16 block_change / multi_block_change) as
/// [`crate::TickEvents::block_updates`]. The world applies them either way; this only
/// collects them for the behaviour.
pub const BLOCK_UPDATES: Interests = Interests(1 << 3);
/// Lean entity tracking: what [`Interests::ENTITIES`] gives (positions, boxes, the crosshair
/// / attack / interact, entity pushes and collisions) without the generic metadata store,
/// roughly 450 bytes less per tracked entity. Only the generic metadata accessors of
/// [`crate::TickContext::entities`] (`Entity::metadata` and what reads it: health, flags,
/// custom names, raw values) return nothing; item entities keep their stack, and the values
/// physics, pushes and picking read are taken from the packets either way. With
/// [`Interests::ENTITIES`] as well, the metadata is kept.
pub const ENTITY_TRACKING: Interests = Interests(1 << 6);
/// Server dialogs (26.1+ `show_dialog` / `clear_dialog`, see [`crate::dialog`]):
/// [`crate::TickContext::dialog_events`], [`crate::TickContext::dialog`] and the answers, and in the
/// configuration state [`crate::Behavior::configuration_dialog`]. Without it play-state
/// dialogs are dropped undecoded and a configuration-state dialog is only logged.
pub const DIALOGS: Interests = Interests(1 << 5);
/// 1.16.5: the server's recipes and item tags (`declare_recipes`, `tags`), which the
/// inventory's predictions read: crafting remainders, a furnace's shift-click (smelting
/// recipes and fuel tags), the fuel, beacon payment and llama carpet slots, the smithing
/// table and the stonecutter. The server sends them once at join (and on `/reload`), so
/// set it from the start. Without it they are not decoded or kept, and those predictions
/// are refused ([`ghast_inventory::ClickError::Unpredictable`]). Other versions: no
/// effect (1.8 / 1.12 clients have them built in; 26.x reads its own).
pub const RECIPES: Interests = Interests(1 << 7);
/// Entity change events ([`crate::TickEvents::entities`]: spawns, removals, statuses and
/// hurts, velocity, metadata, riding, pickups) on top of [`Interests::ENTITIES`] or
/// [`Interests::ENTITY_TRACKING`]. Switching it restarts the tracker empty.
pub const ENTITY_EVENTS: Interests = Interests(1 << 8);
/// The scoreboard teams ([`crate::TickContext::teams`]: members, prefix / suffix, colour,
/// friendly fire) on every version. Off by default: busy servers send many team packets.
pub const TEAMS: Interests = Interests(1 << 9);
/// The HUD ([`crate::TickContext::hud`], [`crate::TickEvents::hud`]): boss bars (1.9+),
/// the title, subtitle and action bar with the vanilla countdown, the tab list's header and
/// footer. Action bar messages that arrive as chat are decoded for it too (without
/// [`Interests::CHAT`] they are not reported as chat). Off by default.
pub const HUD: Interests = Interests(1 << 10);
/// The client-side physics of the tracked projectiles, item entities, experience orbs,
/// primed TNT and falling blocks, on top of [`Interests::ENTITIES`] or
/// [`Interests::ENTITY_TRACKING`]: each one in a loaded column runs its own tick every client
/// tick with the vanilla client's rules (`ghast_physics::<version>::{projectile, drop}`,
/// oracle-proven), and the server's packets correct it, so [`ghast_entity::Entity`]'s
/// position, velocity, rotation and ground flag are what a vanilla client holds between
/// two server updates. Without it these entities stay where the last packet put them.
/// Off by default; a bot without it pays nothing for it. Every version (1.8.9, 1.12.2,
/// 1.16.5, 26.x). See the crate README for what is not simulated.
pub const ENTITY_PHYSICS: Interests = Interests(1 << 11);
/// Whether every group in `other` is in `self`.
#[must_use]
pub const fn contains(self, other: Interests) -> bool {
self.0 & other.0 == other.0
}
/// The union of two sets.
#[must_use]
pub const fn union(self, other: Interests) -> Interests {
Interests(self.0 | other.0)
}
}
impl BitOr for Interests {
type Output = Interests;
fn bitor(self, rhs: Interests) -> Interests {
self.union(rhs)
}
}
impl BitOrAssign for Interests {
fn bitor_assign(&mut self, rhs: Interests) {
*self = self.union(rhs);
}
}