mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
fix some doc tests
This commit is contained in:
parent
f8c143725e
commit
12c1558c17
4 changed files with 29 additions and 33 deletions
|
@ -107,10 +107,11 @@ pub type ClientInformation = ServerboundClientInformationPacket;
|
|||
/// tab list.
|
||||
///
|
||||
/// ```
|
||||
/// # use azalea_client::TabList;
|
||||
/// # fn example(client: &azalea_client::Client) {
|
||||
/// let tab_list = client.component::<TabList>();
|
||||
/// println!("Online players:");
|
||||
/// for (uuid, player_info) in tab_list {
|
||||
/// for (uuid, player_info) in tab_list.iter() {
|
||||
/// println!("- {} ({}ms)", player_info.profile.name, player_info.latency);
|
||||
/// }
|
||||
/// # }
|
||||
|
@ -636,7 +637,9 @@ pub async fn tick_run_schedule_loop(run_schedule_sender: mpsc::UnboundedSender<(
|
|||
///
|
||||
/// This is useful for running code every schedule from async user code.
|
||||
///
|
||||
/// ```no_run
|
||||
/// ```
|
||||
/// use azalea_client::TickBroadcast;
|
||||
/// # async fn example(client: azalea_client::Client) {
|
||||
/// let mut receiver = {
|
||||
/// let ecs = client.ecs.lock();
|
||||
/// let tick_broadcast = ecs.resource::<TickBroadcast>();
|
||||
|
@ -645,6 +648,7 @@ pub async fn tick_run_schedule_loop(run_schedule_sender: mpsc::UnboundedSender<(
|
|||
/// while receiver.recv().await.is_ok() {
|
||||
/// // do something
|
||||
/// }
|
||||
/// # }
|
||||
/// ```
|
||||
#[derive(Resource, Deref)]
|
||||
pub struct TickBroadcast(broadcast::Sender<()>);
|
||||
|
|
|
@ -38,6 +38,21 @@ impl Plugin for InventoryPlugin {
|
|||
pub struct WaitingForInventoryOpen;
|
||||
|
||||
impl Client {
|
||||
/// Open a container in the world, like a chest.
|
||||
///
|
||||
/// ```
|
||||
/// # async fn example(mut bot: azalea_client::Client) {
|
||||
/// let target_pos = bot
|
||||
/// .world()
|
||||
/// .read()
|
||||
/// .find_block(bot.position(), &azalea_registry::Block::Chest.into());
|
||||
/// let Some(target_pos) = target_pos else {
|
||||
/// bot.chat("no chest found");
|
||||
/// return;
|
||||
/// };
|
||||
/// let container = bot.open_container(target_pos).await;
|
||||
/// # }
|
||||
/// ```
|
||||
pub async fn open_container(&mut self, pos: BlockPos) -> Option<ContainerHandle> {
|
||||
self.ecs
|
||||
.lock()
|
||||
|
|
|
@ -30,6 +30,7 @@ pub mod task_pool;
|
|||
pub use account::Account;
|
||||
pub use client::{
|
||||
init_ecs_app, start_ecs, Client, ClientInformation, JoinError, JoinedClientBundle, TabList,
|
||||
TickBroadcast,
|
||||
};
|
||||
pub use events::Event;
|
||||
pub use local_player::{GameProfileComponent, LocalPlayer};
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//! Take wool from a chest and put one random piece of wool in every inventory
|
||||
//! slot
|
||||
//! Take the items in a container and put one of each in a checkerboard pattern
|
||||
|
||||
use azalea::{entity::Position, prelude::*};
|
||||
use azalea::{pathfinder::BlockPosGoal, prelude::*};
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -22,10 +21,10 @@ struct State {
|
|||
pub started: Arc<Mutex<bool>>,
|
||||
}
|
||||
|
||||
async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> {
|
||||
async fn handle(mut bot: Client, event: Event, state: State) -> anyhow::Result<()> {
|
||||
match event {
|
||||
Event::Chat(m) => {
|
||||
if m.username() == Some(bot.profile.name) {
|
||||
if m.username() == Some(bot.profile.name.clone()) {
|
||||
return Ok(());
|
||||
};
|
||||
if m.content() != "go" {
|
||||
|
@ -47,36 +46,13 @@ async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> {
|
|||
bot.chat("No chest found");
|
||||
return Ok(());
|
||||
};
|
||||
bot.goto(chest_block.into());
|
||||
let Some(chest) = bot.open_container(&chest_block).await else {
|
||||
bot.goto(BlockPosGoal::from(chest_block));
|
||||
let Some(chest) = bot.open_container(chest_block).await else {
|
||||
println!("Couldn't open chest");
|
||||
return Ok(());
|
||||
};
|
||||
bot.take_amount_from_container(&chest, 5, |i| i.id == "#minecraft:planks")
|
||||
.await;
|
||||
chest.close().await;
|
||||
|
||||
let crafting_table = bot
|
||||
.open_crafting_table(
|
||||
&bot.world
|
||||
.find_one_block(|b| b.id == "minecraft:crafting_table"),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
bot.craft(&crafting_table, &bot.recipe_for("minecraft:sticks"))
|
||||
.await?;
|
||||
let pickaxe = bot
|
||||
.craft(&crafting_table, &bot.recipe_for("minecraft:wooden_pickaxe"))
|
||||
.await?;
|
||||
crafting_table.close().await;
|
||||
|
||||
bot.hold(&pickaxe);
|
||||
loop {
|
||||
if let Err(e) = bot.dig(bot.position().down(1.).into()).await {
|
||||
println!("{:?}", e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// move everything into our inventory first
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue