ghast-client 0.5.2

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
//! 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);

    /// 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);
    }
}