Crate azalea

source ·
Expand description

Azalea is a framework for creating Minecraft bots.

Internally, it’s just a wrapper over azalea_client, adding useful functions for making bots. Because of this, lots of the documentation will refer to azalea_client. You can just replace these with azalea in your code, since everything from azalea_client is re-exported in azalea.

Installation

First, install Rust nightly with rustup install nightly and rustup default nightly.

Then, add one of the following lines to your Cargo.toml:

Latest bleeding-edge version: azalea = { git="https://github.com/mat-1/Cargo.toml" }
Latest “stable” release: azalea = "0.5.0"

Optimization

For faster compile times, make a .cargo/config.toml file in your project and copy this file into it.

For faster performance in debug mode, add

[profile.dev]
opt-level = 1
[profile.dev.package."*"]
opt-level = 3

to your Cargo.toml. You may have to install the LLD linker.

Examples

//! A bot that logs chat messages sent in the server to the console.

use azalea::prelude::*;
use parking_lot::Mutex;
use std::sync::Arc;

#[tokio::main]
async fn main() {
    let account = Account::offline("bot");
    // or Account::microsoft("example@example.com").await.unwrap();

    azalea::start(azalea::Options {
        account,
        address: "localhost",
        state: State::default(),
        plugins: plugins![],
        handle,
    })
    .await
    .unwrap();
}

#[derive(Default, Clone)]
pub struct State {}

async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> {
    match event {
        Event::Chat(m) => {
            println!("{}", m.message().to_ansi());
        }
        _ => {}
    }

    Ok(())
}

Modules

Ping Minecraft servers.
The Azalea prelude. Things that are necessary for a bare-bones bot are re-exported here.

Macros

A helper macro that generates a Plugins struct from a list of objects that implement Plugin.
A helper macro that generates a SwarmPlugins struct from a list of objects that implement SwarmPlugin.

Structs

Something that can join Minecraft servers.
A player that you control that is currently in a Minecraft server.
The options that are passed to azalea::start.
A player in the tab list.
A map of PluginState TypeIds to AnyPlugin objects. This can then be built into a PluginStates object to get a fresh new state based on this plugin.
A swarm is a way to conveniently control many bots at once, while also being able to control bots at an individual level when desired.
The options that are passed to azalea::start_swarm.
A map of plugin ids to SwarmPlugin trait objects. The client stores this so we can keep the state for our Swarm plugins.

Enums

A chat packet, either a system message or a chat message.
Something that happened in-game, such as a tick passing or chat message being sent.
An error that happened while joining the server.
The directions that we can sprint in. It’s a subset of WalkDirection.
An event about something that doesn’t have to do with a single bot.

Traits

Plugins can keep their own personal state, listen to Events, and add new functions to Client.
A PluginState keeps the current state of a plugin for a client. All the fields must be atomic. Unique PluginStates are built from Plugins.
Swarm plugins can keep their own personal state (SwarmPluginState), listen to SwarmEvents, and add new functions to Swarm.
A SwarmPluginState keeps the current state of a plugin for a client. All the fields must be atomic. Unique SwarmPluginStates are built from SwarmPlugins.

Functions

Join a server and start handling events. This function will run forever until it gets disconnected from the server.
Make a bot Swarm.

Type Definitions