Skip to main content

ghast_entity/
lib.rs

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