Skip to main content

basalt_api/
lib.rs

1//! Basalt public plugin API.
2//!
3//! This crate is the **single dependency** for all Basalt plugins.
4//! Types are organized into focused modules:
5//!
6//! - [`prelude`] — essentials for every plugin (glob import this)
7//! - [`components`] — ECS component types (Position, Velocity, etc.)
8//! - [`system`] — system registration (SystemContext, Phase, etc.)
9//! - [`command`] — command argument types (Arg, CommandArgs, etc.)
10//! - [`types`] — primitive Minecraft types (Uuid, Slot, TextComponent, etc.)
11//! - [`world`] — block states, collision, block entities
12
13pub mod broadcast;
14pub mod budget;
15pub mod components;
16pub mod container;
17pub mod context;
18pub mod events;
19pub mod gamemode;
20pub mod logger;
21pub mod player;
22pub mod plugin;
23pub mod recipes;
24pub mod system;
25#[cfg(any(feature = "testing", test))]
26pub mod testing;
27
28/// Command argument types, parsing, validation, and dispatch.
29pub mod command;
30
31/// Primitive Minecraft types.
32pub mod types {
33    pub use basalt_types::{NamedColor, Slot, TextColor, TextComponent, Uuid};
34}
35
36/// World access: block states, collision, block entities, chunk storage.
37pub mod world;
38
39/// Wire-level protocol packet definitions, exposed for plugins that
40/// need raw packet inspection (anti-cheat, telemetry, packet logging).
41///
42/// Most plugins should listen to domain events
43/// ([`events::BlockBrokenEvent`], [`events::PlayerMovedEvent`], …)
44/// rather than reaching into packet structs directly. The packets
45/// module is here for the cases where the wire-level shape matters —
46/// e.g. inspecting [`events::RawPacketEvent::packet`].
47///
48/// Available only when the `raw-packets` feature is enabled.
49#[cfg(feature = "raw-packets")]
50pub use basalt_mc_protocol::packets;
51
52// Top-level re-exports for non-prelude usage.
53pub use context::Response;
54pub use events::{Event, EventBus, Stage};
55pub use plugin::{CommandEntry, Plugin, PluginMetadata, PluginRegistrar};
56
57/// Prelude module — import this in every plugin.
58///
59/// Contains only what 90%+ of plugins need: registration types,
60/// context traits, events, and stage. Specialized types live in
61/// their respective modules.
62///
63/// ```ignore
64/// use basalt_api::prelude::*;
65/// ```
66pub mod prelude {
67    // Plugin registration
68    pub use crate::context::Response;
69    pub use crate::plugin::{Plugin, PluginMetadata, PluginRegistrar};
70
71    // Context traits
72    pub use crate::broadcast::BroadcastMessage;
73    pub use crate::context::{
74        ChatContext, ContainerContext, Context, EntityContext, PlayerContext, RecipeContext,
75        UnlockReason, WorldContext,
76    };
77    pub use crate::gamemode::Gamemode;
78
79    // Event system
80    pub use crate::events::{Event, Stage};
81
82    // Container types
83    pub use crate::container::{Container, ContainerBacking, ContainerBuilder, InventoryType};
84
85    // All event types
86    pub use crate::events::{
87        BlockBrokenEvent, BlockEntityCreatedEvent, BlockEntityDestroyedEvent, BlockEntityKind,
88        BlockEntityModifiedEvent, BlockPlacedEvent, ChatMessageEvent, CloseReason, CommandEvent,
89        ContainerClickEvent, ContainerClickType, ContainerClosedEvent, ContainerDragEvent,
90        ContainerOpenRequestEvent, ContainerOpenedEvent, ContainerSlotChangedEvent,
91        CraftingCraftedEvent, CraftingGridChangedEvent, CraftingPreCraftEvent,
92        CraftingRecipeClearedEvent, CraftingRecipeMatchedEvent, CraftingShiftClickBatchEvent,
93        DragType, PlayerInteractEvent, PlayerJoinedEvent, PlayerLeftEvent, PlayerMovedEvent,
94        RecipeBookFillRequestEvent, RecipeBookFilledEvent, RecipeLockedEvent, RecipeRegisterEvent,
95        RecipeRegisteredEvent, RecipeUnlockedEvent, RecipeUnregisteredEvent, WindowSlotKind,
96    };
97
98    // Recipe types referenced by registry-lifecycle events.
99    pub use crate::recipes::{OwnedShapedRecipe, OwnedShapelessRecipe, Recipe, RecipeId};
100}