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, 1.16.5
2//! and 26.1).
3//!
4//! [`v1_8::Tracker`] / [`v1_12::Tracker`] / [`v1_16_5::Tracker`] / `v26_1::Tracker` take raw
5//! clientbound play packets
6//! ([`ghast_protocol::RawPacket`]) and keep every entity the server announced, keyed by id:
7//! type, UUID, **server position** (exactly as the vanilla client tracks it from the packets,
8//! with each version's fixed-point rules), rotation, last velocity, on-ground, riding / leash
9//! links, and optionally metadata, equipment, effects and the tab list.
10//!
11//! - **Cheap.** Packets are parsed by hand straight from the packet body; movement, look,
12//!   teleport, velocity, head-rotation and destroy packets do not allocate. Lookups are one hash
13//!   of the id. Parts nobody needs are switched off in [`Config`], and `Tracker::wants(id)` /
14//!   `packet_ids()` tell the client which packets it can drop before decoding.
15//! - **Vanilla semantics.** Spawns replace an existing id, unknown types spawn nothing, moves
16//!   for unknown ids are ignored, `login` and world changes clear everything, pickups remove
17//!   the item (1.16: when its stack runs out), riding follows each version's rules.
18//! - **Never panics on server data**: malformed bodies return a [`ghast_protocol::DecodeError`].
19//!
20//! ```
21//! use ghast_entity::{Config, v1_8::Tracker};
22//! let tracker = Tracker::new(Config::default());
23//! assert!(tracker.get(42).is_none());
24//! ```
25
26#![forbid(unsafe_code)]
27#![warn(missing_docs, unnameable_types)]
28// A build with only some versions leaves helpers of the others unused.
29#![cfg_attr(
30    not(all(
31        feature = "v1_8",
32        feature = "v1_12",
33        feature = "v1_16_5",
34        feature = "v26_1"
35    )),
36    allow(dead_code)
37)]
38// A build with no version at all keeps only the shared store.
39#![cfg_attr(
40    not(any(
41        feature = "v1_8",
42        feature = "v1_12",
43        feature = "v1_16_5",
44        feature = "v26_1"
45    )),
46    allow(unused_imports, unused_variables)
47)]
48
49mod common;
50mod entity;
51mod store;
52#[cfg(feature = "v1_12")]
53pub mod v1_12;
54#[cfg(feature = "v1_16_5")]
55pub mod v1_16_5;
56#[cfg(feature = "v1_8")]
57pub mod v1_8;
58#[cfg(feature = "v26_1")]
59pub mod v26_1;
60
61pub use entity::{
62    EQUIPMENT_SLOTS, Effect, Entity, EntityClass, EntityType, Item, MetaValue, Metadata,
63};
64pub use store::{Config, Entities, Event, PlayerInfo};
65
66/// What applying a packet did.
67#[derive(Clone, Copy, Debug, PartialEq, Eq)]
68pub enum Applied {
69    /// Tracked state changed.
70    Changed,
71    /// Valid, but nothing changed (unknown entity id, unknown type, the bot's own position, ...).
72    Ignored,
73    /// Not a packet this tracker handles (or one its configuration does not want).
74    NotEntityPacket,
75}