Skip to main content

ghast_entity/
lib.rs

1//! Entity tracking for the ghast Minecraft Java Edition client library (1.8.9 and 1.16.5).
2//!
3//! [`v1_8::Tracker`] / [`v1_16_5::Tracker`] take raw clientbound play packets
4//! ([`ghast_protocol::RawPacket`]) and keep every entity the server announced, keyed by id:
5//! type, UUID, **server position** (exactly as the vanilla client tracks it from the packets,
6//! with each version's fixed-point rules), rotation, last velocity, on-ground, riding / leash
7//! links, and optionally metadata, equipment, effects and the tab list.
8//!
9//! - **Cheap.** Packets are parsed by hand straight from the packet body; movement, look,
10//!   teleport, velocity, head-rotation and destroy packets do not allocate. Lookups are one hash
11//!   of the id. Parts nobody needs are switched off in [`Config`], and `Tracker::wants(id)` /
12//!   `packet_ids()` tell the client which packets it can drop before decoding.
13//! - **Vanilla semantics.** Spawns replace an existing id, unknown types spawn nothing, moves
14//!   for unknown ids are ignored, `login` and world changes clear everything, pickups remove
15//!   the item (1.16: when its stack runs out), riding follows each version's rules.
16//! - **Never panics on server data**: malformed bodies return a [`ghast_protocol::DecodeError`].
17//!
18//! ```
19//! use ghast_entity::{Config, v1_8::Tracker};
20//! let tracker = Tracker::new(Config::default());
21//! assert!(tracker.get(42).is_none());
22//! ```
23
24#![forbid(unsafe_code)]
25#![warn(missing_docs)]
26
27mod common;
28mod entity;
29mod store;
30pub mod v1_16_5;
31pub mod v1_8;
32
33pub use entity::{
34    EQUIPMENT_SLOTS, Effect, Entity, EntityClass, EntityType, Item, MetaValue, Metadata,
35};
36pub use store::{Config, Entities, Event, PlayerInfo};
37
38/// What applying a packet did.
39#[derive(Clone, Copy, Debug, PartialEq, Eq)]
40pub enum Applied {
41    /// Tracked state changed.
42    Changed,
43    /// Valid, but nothing changed (unknown entity id, unknown type, the bot's own position, ...).
44    Ignored,
45    /// Not a packet this tracker handles (or one its configuration does not want).
46    NotEntityPacket,
47}