Skip to main content

azalea/
lib.rs

1#![doc = include_str!("../README.md")]
2#![feature(type_changing_struct_update)]
3
4#[cfg(doc)]
5pub mod _docs;
6pub mod accept_resource_packs;
7pub mod auto_reconnect;
8pub mod auto_respawn;
9pub mod auto_tool;
10pub mod bot;
11mod builder;
12mod client_impl;
13pub mod container;
14mod entity_ref;
15pub mod events;
16mod join_opts;
17pub mod nearest_entity;
18pub mod pathfinder;
19pub mod prelude;
20pub mod swarm;
21pub mod tick_broadcast;
22
23use std::ops::Deref;
24
25pub use azalea_auth as auth;
26pub use azalea_block as block;
27#[doc(hidden)]
28#[deprecated = "moved to `azalea::block`"]
29pub mod blocks {
30    pub type BlockStates = azalea_block::BlockStates;
31    pub type BlockState = azalea_block::BlockState;
32    pub trait BlockTrait: azalea_block::BlockTrait {}
33    // azalea_block has more items but rust doesn't mark them deprecated if we
34    // `use azalea_block::*`, so hopefully the three types above are enough for
35    // most users :(
36}
37
38pub use azalea_brigadier as brigadier;
39pub use azalea_buf as buf;
40pub use azalea_chat::FormattedText;
41pub use azalea_client::*;
42pub use azalea_core as core;
43// these are re-exported on this level because they're very common
44pub use azalea_core::position::{BlockPos, Vec3};
45pub use azalea_entity as entity;
46pub use azalea_physics as physics;
47pub use azalea_protocol as protocol;
48pub use azalea_registry as registry;
49#[doc(hidden)]
50#[deprecated(note = "renamed to `Identifier`.")]
51pub type ResourceLocation = azalea_registry::identifier::Identifier;
52
53// TODO: replace this mod with the commented line below
54// pub use azalea_chat as chat;
55pub mod chat {
56    pub use azalea_chat::*;
57    #[deprecated = "moved to `azalea::client_chat`."]
58    pub type ChatPacket = azalea_client::client_chat::ChatPacket;
59}
60
61pub use azalea_registry::identifier::Identifier;
62pub use azalea_world as world;
63pub use bevy_app as app;
64pub use bevy_ecs as ecs;
65use bevy_ecs::{component::Component, resource::Resource};
66pub use builder::ClientBuilder;
67use futures::future::BoxFuture;
68pub use join_opts::JoinOpts;
69
70pub use crate::{
71    client_impl::{Client, StartClientOpts, error},
72    entity_ref::EntityRef,
73    events::Event,
74};
75
76// for convenience, adds the alias `azalea::Result` instead of
77// `azalea::error::AzaleaResult`. the user should probably be using anyhow/eyre,
78// but in some cases they may prefer to have the errors more strictly defined.
79pub type Result<T> = error::AzaleaResult<T>;
80
81pub type BoxHandleFn<S, R> = Box<dyn Fn(Client, Event, S) -> BoxFuture<'static, R> + Send>;
82pub type HandleFn<S, Fut> = fn(Client, Event, S) -> Fut;
83
84/// A marker that can be used in place of a State in [`ClientBuilder`] or
85/// [`SwarmBuilder`].
86///
87/// You probably don't need to use this manually since the compiler will infer
88/// it for you.
89///
90/// [`SwarmBuilder`]: swarm::SwarmBuilder
91#[derive(Clone, Component, Default)]
92pub struct NoState;
93
94/// A reference to a `tokio::runtime::Handle`, allowing you to spawn Tokio tasks
95/// inside of ECS systems.
96///
97/// There are times in which you may want to use something like `tokio::spawn`
98/// inside of an ECS system, but you don't want to bother with message passing
99/// or Bevy's `AsyncComputeTaskPool`. Bevy doesn't run systems inside of a Tokio
100/// runtime, which results in an error if you try to use `tokio::spawn` or
101/// `tokio::task::spawn_local`. However, if you have a reference to a `Handle`,
102/// then Tokio will let you use it to spawn new tasks. This `Resource` exists
103/// for that -- it simply gives you a handle to a Tokio runtime to do whatever
104/// you want with.
105///
106/// ```
107/// # use azalea::ecs::prelude::*;
108/// fn example(rt: Res<azalea::TokioRuntimeHandle>) {
109///     rt.spawn(async {
110///         // ...
111///     });
112/// }
113/// ```
114#[derive(Resource)]
115pub struct TokioRuntimeHandle(pub tokio::runtime::Handle);
116impl Deref for TokioRuntimeHandle {
117    type Target = tokio::runtime::Handle;
118    fn deref(&self) -> &Self::Target {
119        &self.0
120    }
121}