ghast_client/version/caps.rs
1//! The cross-layer version row: what a protocol version can do, as facts the version-agnostic
2//! core asks for instead of comparing version numbers.
3//!
4//! One constant row per [`GameVersion`]. Adding a version is adding a row (plus whatever is
5//! really new); the core never names a version. Every field is a plain fact of the vanilla
6//! client of that version.
7
8use super::GameVersion;
9
10/// The physics rule set a version runs on (`ghast-physics` module).
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
12#[non_exhaustive]
13pub enum PhysicsRules {
14 /// `ghast_physics::v1_8` (1.8 – 1.8.9).
15 V1_8,
16 /// `ghast_physics::v1_12` (1.12.1, 1.12.2).
17 V1_12,
18 /// `ghast_physics::v1_16_5` (1.16.2 – 1.16.5).
19 V1_16_5,
20 /// `ghast_physics::modern` with the `V26_1` rules (26.1 – 26.1.2).
21 Modern26_1,
22 /// `ghast_physics::modern` with the `V26_2` rules (26.2: collision restitution).
23 Modern26_2,
24 /// `ghast_physics::modern` with the `V26_3` rules (26.3: movement packets after the
25 /// level's entities and block entities ticked, the teleport answer with the pose).
26 Modern26_3,
27}
28
29/// When a change of the stack in the used hand ends an item use.
30#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
31#[non_exhaustive]
32pub enum UseStop {
33 /// At once when the bot selects another slot (or the server does).
34 AtSelect,
35 /// In the player tick after the key handling, when the hand's stack object was replaced:
36 /// another hotbar slot, or any server write of that slot (`set_slot`, `window_items`), even
37 /// of an equal stack (1.8 `PlayerEntity.tick`, 1.12 `updateActiveHand`: identity).
38 HeldReplaced,
39 /// In the player tick after the key handling, when the hand holds another item (1.16.5
40 /// `tickActiveItemStack`: `ItemStack.areItemsEqual`); a slot change to the same item or a
41 /// resync keeps the use.
42 HeldItemChanged,
43}
44
45/// When a change of the held item resets the 1.9+ attack cooldown.
46#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
47#[non_exhaustive]
48pub enum CooldownReset {
49 /// At once when the bot selects another slot.
50 AtSelect,
51 /// In the player tick after the key handling (`PlayerEntity.tick`, after the cooldown
52 /// count), when the held stack is another item, or the same item without durability with
53 /// another damage value (1.12 `ItemStack.equals`); an attack in the tick of a slot change
54 /// still has the old strength.
55 ItemAndDamage,
56 /// As [`CooldownReset::ItemAndDamage`] comparing the item only.
57 Item,
58}
59
60/// Item cooldowns of a version (`ItemCooldownManager`, 1.9+; see [`crate::cooldown`]).
61#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
62#[non_exhaustive]
63pub enum ItemCooldownRules {
64 /// None (1.8).
65 None,
66 /// Per item (1.9 – 1.21.1): the server's `set_cooldown` names an item; the client starts
67 /// the ender pearl's own 20 ticks.
68 PerItem,
69 /// Per cooldown group (1.21.2+): the server's `set_cooldown` names a group; the client
70 /// starts the `use_cooldown` component's cooldown after a use.
71 Groups,
72}
73
74/// What an invulnerable player (creative, spectator) may eat: `PlayerEntity.canConsume`.
75#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
76#[non_exhaustive]
77pub enum InvulnerableEating {
78 /// Nothing (1.8, 1.12: `!abilities.invulnerable` is part of the test).
79 Never,
80 /// Anything, full or not (1.14+ and 26.x: `abilities.invulnerable || …`).
81 Always,
82 /// As any player (the hunger rule only; no version uses it any more).
83 Hunger,
84}
85
86/// The data tables of a version (`ghast-data` module).
87#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
88#[non_exhaustive]
89pub enum DataSet {
90 /// `ghast_data::v1_8`: numeric block / item ids with metadata.
91 V1_8,
92 /// `ghast_data::v1_12`: numeric block / item ids with metadata.
93 V1_12,
94 /// `ghast_data::v1_16_5`: flattened block states and item ids.
95 V1_16_5,
96 /// `ghast_data::v26_1`: flattened block states and item ids.
97 V26_1,
98 /// `ghast_data::v26_2`: flattened block states and item ids.
99 V26_2,
100 /// `ghast_data::v26_3`: flattened block states and item ids.
101 V26_3,
102}
103
104/// How item stacks carry their extra data on the wire.
105#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
106#[non_exhaustive]
107pub enum ItemModel {
108 /// Numeric id, damage value and an optional NBT compound (1.8 – 1.12).
109 LegacyNbt,
110 /// Flattened id and an optional NBT compound (1.13 – 1.20.4).
111 FlatNbt,
112 /// Flattened id and data components (1.20.5+).
113 Components,
114}
115
116/// What a protocol version can do: the facts the client core asks for.
117///
118/// Read one with [`GameVersion::caps`].
119#[derive(Debug, Clone, Copy, PartialEq)]
120#[non_exhaustive]
121pub struct Capabilities {
122 /// The version this row describes.
123 pub version: GameVersion,
124 /// Protocol number.
125 pub protocol: i32,
126 /// Physics rule set.
127 pub physics: PhysicsRules,
128 /// Data tables.
129 pub data: DataSet,
130 /// How item stacks carry extra data.
131 pub item_model: ItemModel,
132 /// 1.9 combat: attack cooldown, swing sent after the click packet, the off hand.
133 pub combat_1_9: bool,
134 /// The crosshair pick skips entities with the player's root vehicle (1.9+), not only the
135 /// vehicle the player sits on (1.8).
136 pub entity_pick_root_vehicle: bool,
137 /// Eye height above the feet while standing.
138 pub eye_height: f64,
139 /// Eye height while sneaking (1.54 in 1.8 – 1.12, the crouching pose's 1.27 since 1.14).
140 pub sneak_eye_height: f64,
141 /// Longest chat line the server accepts, in UTF-16 units.
142 pub chat_limit: usize,
143 /// Game event 11 ("immediate respawn" game rule) exists (1.15+).
144 pub immediate_respawn_rule: bool,
145 /// The client uses a seed item at once when planting on its soil (the 1.8 `SeedItem.use`
146 /// prediction; later versions wait for the server's slot update).
147 pub seed_planting_prediction: bool,
148 /// Server teleports carry an id the client confirms (1.9+).
149 pub teleport_confirm: bool,
150 /// Window clicks are confirmed with transactions (1.8 – 1.16).
151 pub window_confirm: bool,
152 /// A configuration state sits between login and play (1.20.2+).
153 pub configuration_state: bool,
154 /// Sneaking is sent as `player_input` key state, not as an entity action (1.21.2+).
155 pub sneak_via_player_input: bool,
156 /// The client sends `tick_end` after every tick (1.21.2+).
157 pub sends_tick_end: bool,
158 /// The player does not tick until the client sends `player_loaded` (1.21.4+).
159 pub player_loaded_gate: bool,
160 /// Chunk batches are acknowledged with the desired chunks per tick (1.20.2+).
161 pub chunk_batch_ack: bool,
162 /// Dig / place / use packets carry a sequence number the server acknowledges (1.19+).
163 pub block_sequence: bool,
164 /// Chat packets carry a timestamp, salt and message acknowledgements (1.19.3+).
165 pub chat_acknowledgements: bool,
166 /// The drop key takes the item off the held stack on the client at once and then swings
167 /// the main arm when it took one (1.16.5 `ClientPlayerEntity.dropSelectedItem` and the
168 /// key handler; 26.1 `LocalPlayer.drop`); 1.8.9 / 1.12.2 only send the packet and wait for
169 /// the server's slot update.
170 pub drop_prediction: bool,
171 /// The client itself pushes the player away from other entities in its entity tick
172 /// (26.1+; 1.12.2: `LivingEntity.tickCramming`, other players and boats push the local
173 /// player on the client too; 1.16.5: `LivingEntity.tickCramming`,
174 /// `OtherClientPlayerEntity.tickMovement` and `BoatEntity.tick`, in the client world's entity
175 /// map order; 1.8.9 leaves it to the server). Judging those pushes needs
176 /// each player entity's tab-list name (team collision rules) and game mode (spectators do
177 /// not push), so entity tracking then also keeps a names-only tab list.
178 pub client_entity_push: bool,
179 /// A spectator's right click on a block (the block packet, then the click ends) swings the
180 /// arm: 1.8 – 1.16 `interactBlock` returns true / SUCCESS for spectators; 26.1 / 26.2
181 /// `MultiPlayerGameMode.performUseItemOn` returns CONSUME, which swings nothing.
182 pub spectator_block_click_swings: bool,
183 /// Switching to spectator ends an item use at once: 26.1 / 26.2
184 /// `ServerPlayer.setGameMode(SPECTATOR)` calls `stopUsingItem` and the client's use ends
185 /// with the living flags; 1.8 – 1.16.5 stop nothing (the use runs until release or finish).
186 pub spectator_switch_stops_use: bool,
187 /// The client's attack reads the held item's knockback enchantment level
188 /// (`EnchantmentHelper.getKnockback`, 1.8 – 1.16.5): with knockback the attacker slows down
189 /// on the client too. 26.1 / 26.2 `LivingEntity.getKnockback` runs the data-driven
190 /// enchantment effects only on a `ServerLevel`: the client's knockback is the attribute
191 /// alone (a sprint attack at full strength still slows).
192 pub attack_knockback_enchantment: bool,
193 /// Putting armor on with a right click swings the arm: 1.16.5 `ArmorItem.use` answers
194 /// `success(…, isClient)` (SUCCESS swings) and 26.x `Equippable.swapWithEquipmentSlot`
195 /// SUCCESS (a client swing); 1.12.2 `ArmorItem.use` SUCCESS swings nothing, 1.8
196 /// `interactItem` neither.
197 pub use_equip_swings: bool,
198 /// The player's own inventory screen passes key presses through to the game while it is
199 /// open (1.16.5 `InventoryScreen` / `CreativeInventoryScreen` set `passEvents`: GLFW key
200 /// events the screen does not use reach the key bindings, and `handleInputEvents` runs):
201 /// opening it releases every key (`KeyBinding.unpressAll`), a movement key pressed while
202 /// it is open applies, closing it re-reads the held keys. 1.8.9 / 1.12.2 screens take
203 /// every keyboard event (`handleInput` before `tickKeyboard`), 26.x not verified (off).
204 pub own_inventory_passes_keys: bool,
205 /// When a change of the used hand's stack ends an item use.
206 pub use_stop: UseStop,
207 /// Creative digging as `attackBlock` / `updateBlockBreakingProgress` (26.x
208 /// `startDestroyBlock` / `continueDestroyBlock`) do it: a start packet and the block broken
209 /// at once (not by a sword, 26.x: a tool that cannot destroy blocks in creative), then
210 /// every 5 ticks while the button is held; nothing is aborted (oracle: 26.x
211 /// `held_dig.jsonl.gz`). Off: the survival path.
212 pub creative_instant_dig: bool,
213 /// What an invulnerable (creative) player may eat (`canConsume`).
214 pub invulnerable_eating: InvulnerableEating,
215 /// Our living flags from the server drive the client's item use (1.9+
216 /// `ClientPlayerEntity.onTrackedDataSet(LIVING_FLAGS)`): bit 1 set while not using starts a
217 /// use of the stack in the hand of bit 2, bit 1 clear while using ends it (no packet).
218 pub living_flags_drive_use: bool,
219 /// When a held item change resets the 1.9+ attack cooldown.
220 pub cooldown_reset: CooldownReset,
221 /// Item cooldowns: none, per item or per cooldown group.
222 pub item_cooldowns: ItemCooldownRules,
223 /// The key handling's crosshair pick turns with the player's head yaw (1.8
224 /// `LivingEntity.getRotationVector(1.0F)`: the head yaw the last tick's `tickNewAi` set, so
225 /// the yaw before this tick's turn) and this tick's pitch; the movement packet carries the
226 /// new yaw. 1.9+ picks with this tick's yaw.
227 pub pick_head_yaw: bool,
228 /// The pick block key as 1.8.9 / 1.12.2 / 1.16.5 `MinecraftClient.doPick` ends (1.8
229 /// `PlayerInventory.addPickBlock` of an item and damage, 1.12 `method_13250` / 1.16.5
230 /// `addPickBlock` of a stack) and, in creative mode, a `creative_inventory_action` for the
231 /// selected slot (oracle `clicks_creative`); 1.12.2 / 1.16.5 also load saved toolbars.
232 /// Off: not modelled (refused).
233 pub legacy_pick_block: bool,
234 /// The client sends its arm swings (`swing` / `arm_animation`); 26.3 removed the
235 /// serverbound swing: an attack sends the payload-less `punch` instead and a used item
236 /// only animates the hand (`LocalPlayer.itemUsed`).
237 pub sends_swing: bool,
238 /// 26.3 `ClientPacketListener.handleMovePlayer`: the teleport answer is one
239 /// `accept_teleportation` carrying the resulting position and rotation (no
240 /// position-rotation packet after it), and the teleport aborts a dig in progress
241 /// (`MultiPlayerGameMode.stopDestroyBlock`).
242 pub teleport_confirm_pose: bool,
243 /// 26.3 `MultiPlayerGameMode.continueDestroyBlock`: while the same block is dug, a hit on
244 /// another face sends `CHANGE_DESTROY_DIRECTION` (player action 1) with the new face; the
245 /// later player-action ids are shifted by one.
246 pub dig_change_direction: bool,
247 /// 26.3 `MultiPlayerGameMode.attack`: an attack in creative sets the 5-tick dig delay, so a
248 /// held button that reaches a block right after sends only swings until it ran out
249 /// (oracle: 26.3 `held_dig.jsonl.gz`, `attack_mob_creative`).
250 pub creative_attack_dig_delay: bool,
251 /// The serverbound swing-free `punch` packet goes out where 1.9+ sends the swing after an
252 /// attack or a missed click (26.3 `Minecraft.startAttack` / `LocalPlayer.swing` path).
253 pub sends_punch: bool,
254 /// The server can show boss bars (1.9+ `boss_bar`; [`crate::hud::Hud::boss_bars`]).
255 pub boss_bars: bool,
256 /// How the sign editor opens, closes and sends its lines ([`crate::sign`]).
257 pub sign_editor: crate::sign::SignRules,
258 /// What the book screen sends and changes in the held stack ([`crate::book`]).
259 pub book: crate::book::BookRules,
260 /// 1.13+ `LivingEntity.tick`: a sleeping player's pitch is set to 0 every tick.
261 pub sleep_levels_pitch: bool,
262}
263
264const fn f(v: f32) -> f64 {
265 v as f64
266}
267
268/// 1.12.1 (protocol 338): the 1.12.2 row with its own number (the same jar code apart from
269/// the keep-alive width and GUI details; oracle records identical).
270pub(crate) const V1_12_1: Capabilities = Capabilities {
271 version: GameVersion::V1_12_1,
272 protocol: 338,
273 ..V1_12_2
274};
275
276/// 1.16.2 (protocol 751): the 1.16.5 row with its own number (client movement, block and
277/// network code identical in the jars; oracle records identical).
278pub(crate) const V1_16_2: Capabilities = Capabilities {
279 version: GameVersion::V1_16_2,
280 protocol: 751,
281 ..V1_16_5
282};
283
284/// 1.16.3 (protocol 753): the 1.16.5 row with its own number, like [`V1_16_2`].
285pub(crate) const V1_16_3: Capabilities = Capabilities {
286 version: GameVersion::V1_16_3,
287 protocol: 753,
288 ..V1_16_5
289};
290
291/// 1.8 – 1.8.9 (protocol 47).
292pub(crate) const V1_8_9: Capabilities = Capabilities {
293 version: GameVersion::V1_8_9,
294 protocol: 47,
295 physics: PhysicsRules::V1_8,
296 data: DataSet::V1_8,
297 item_model: ItemModel::LegacyNbt,
298 combat_1_9: false,
299 entity_pick_root_vehicle: false,
300 eye_height: f(1.62),
301 // `1.62F - 0.08F` in float.
302 sneak_eye_height: f(1.62 - 0.08),
303 chat_limit: 100,
304 own_inventory_passes_keys: false,
305 immediate_respawn_rule: false,
306 // the 1.8.9 right-click rules (`Sim::place_rules` / `place_sent`) predict planting now
307 seed_planting_prediction: false,
308 teleport_confirm: false,
309 window_confirm: true,
310 configuration_state: false,
311 sneak_via_player_input: false,
312 sends_tick_end: false,
313 player_loaded_gate: false,
314 chunk_batch_ack: false,
315 block_sequence: false,
316 chat_acknowledgements: false,
317 client_entity_push: false,
318 drop_prediction: false,
319 spectator_block_click_swings: true,
320 spectator_switch_stops_use: false,
321 attack_knockback_enchantment: true,
322 use_equip_swings: false,
323 use_stop: UseStop::HeldReplaced,
324 creative_instant_dig: true,
325 invulnerable_eating: InvulnerableEating::Never,
326 living_flags_drive_use: false,
327 cooldown_reset: CooldownReset::AtSelect,
328 item_cooldowns: ItemCooldownRules::None,
329 pick_head_yaw: true,
330 legacy_pick_block: true,
331 sends_swing: true,
332 teleport_confirm_pose: false,
333 dig_change_direction: false,
334 creative_attack_dig_delay: false,
335 sends_punch: false,
336 boss_bars: false,
337 sign_editor: crate::sign::SignRules::Legacy { json: true },
338 book: crate::book::BookRules::Legacy18,
339 sleep_levels_pitch: false,
340};
341
342/// 1.12.2 (protocol 340).
343pub(crate) const V1_12_2: Capabilities = Capabilities {
344 version: GameVersion::V1_12_2,
345 protocol: 340,
346 physics: PhysicsRules::V1_12,
347 data: DataSet::V1_12,
348 combat_1_9: true,
349 entity_pick_root_vehicle: true,
350 chat_limit: 256,
351 seed_planting_prediction: false,
352 teleport_confirm: true,
353 client_entity_push: true,
354 living_flags_drive_use: true,
355 cooldown_reset: CooldownReset::ItemAndDamage,
356 item_cooldowns: ItemCooldownRules::PerItem,
357 pick_head_yaw: false,
358 boss_bars: true,
359 sign_editor: crate::sign::SignRules::Legacy { json: false },
360 book: crate::book::BookRules::Legacy112,
361 ..V1_8_9
362};
363
364/// 1.16.4 – 1.16.5 (protocol 754).
365pub(crate) const V1_16_5: Capabilities = Capabilities {
366 version: GameVersion::V1_16_5,
367 protocol: 754,
368 own_inventory_passes_keys: true,
369 physics: PhysicsRules::V1_16_5,
370 data: DataSet::V1_16_5,
371 item_model: ItemModel::FlatNbt,
372 sneak_eye_height: f(1.27),
373 immediate_respawn_rule: true,
374 client_entity_push: true,
375 drop_prediction: true,
376 use_equip_swings: true,
377 invulnerable_eating: InvulnerableEating::Always,
378 use_stop: UseStop::HeldItemChanged,
379 cooldown_reset: CooldownReset::Item,
380 pick_head_yaw: false,
381 sign_editor: crate::sign::SignRules::FirstTickCheck,
382 book: crate::book::BookRules::Stack116,
383 sleep_levels_pitch: true,
384 ..V1_12_2
385};
386
387/// 26.1 – 26.1.2 (protocol 775).
388pub(crate) const V26_1: Capabilities = Capabilities {
389 version: GameVersion::V26_1,
390 protocol: 775,
391 own_inventory_passes_keys: false,
392 physics: PhysicsRules::Modern26_1,
393 data: DataSet::V26_1,
394 item_model: ItemModel::Components,
395 window_confirm: false,
396 configuration_state: true,
397 sneak_via_player_input: true,
398 sends_tick_end: true,
399 player_loaded_gate: true,
400 chunk_batch_ack: true,
401 block_sequence: true,
402 chat_acknowledgements: true,
403 client_entity_push: true,
404 spectator_block_click_swings: false,
405 spectator_switch_stops_use: true,
406 attack_knockback_enchantment: false,
407 creative_instant_dig: true,
408 // Player.canEat: abilities.invulnerable || canAlwaysEat || needsFood (26.1 – 26.3).
409 invulnerable_eating: InvulnerableEating::Always,
410 living_flags_drive_use: false,
411 cooldown_reset: CooldownReset::AtSelect,
412 item_cooldowns: ItemCooldownRules::Groups,
413 pick_head_yaw: false,
414 use_stop: UseStop::AtSelect,
415 // 26.x picks with `pick_item_from_block` / `_entity` (not modelled)
416 legacy_pick_block: false,
417 sign_editor: crate::sign::SignRules::Sided,
418 book: crate::book::BookRules::Pages,
419 ..V1_16_5
420};
421
422/// 26.2 (protocol 776): the 26.1 row with its own physics rules and data.
423pub(crate) const V26_2: Capabilities = Capabilities {
424 version: GameVersion::V26_2,
425 protocol: 776,
426 physics: PhysicsRules::Modern26_2,
427 data: DataSet::V26_2,
428 ..V26_1
429};
430
431/// 26.3 (protocol 777): the 26.2 row with its own physics rules and data, no serverbound
432/// swing, the teleport answer with the pose and the dig direction changes.
433pub(crate) const V26_3: Capabilities = Capabilities {
434 version: GameVersion::V26_3,
435 protocol: 777,
436 physics: PhysicsRules::Modern26_3,
437 data: DataSet::V26_3,
438 sends_swing: false,
439 teleport_confirm_pose: true,
440 dig_change_direction: true,
441 creative_attack_dig_delay: true,
442 sends_punch: true,
443 ..V26_2
444};