diff options
Diffstat (limited to 'azalea/examples')
| -rwxr-xr-x | azalea/examples/craft_dig_straight_down.rs | 6 | ||||
| -rwxr-xr-x | azalea/examples/echo.rs | 2 | ||||
| -rw-r--r-- | azalea/examples/mine_a_chunk.rs | 2 | ||||
| -rwxr-xr-x | azalea/examples/potatobot/autoeat.rs | 3 | ||||
| -rwxr-xr-x | azalea/examples/pvp.rs | 16 |
5 files changed, 17 insertions, 12 deletions
diff --git a/azalea/examples/craft_dig_straight_down.rs b/azalea/examples/craft_dig_straight_down.rs index 864b9809..76979406 100755 --- a/azalea/examples/craft_dig_straight_down.rs +++ b/azalea/examples/craft_dig_straight_down.rs @@ -64,8 +64,12 @@ async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> { crafting_table.close().await; bot.hold(&pickaxe); + loop { - if let Err(e) = bot.dig(bot.entity().feet_pos().down(1)).await { + if let Err(e) = bot + .dig(azalea::entity::feet_pos(bot.entity()).down(1)) + .await + { println!("{:?}", e); break; } diff --git a/azalea/examples/echo.rs b/azalea/examples/echo.rs index 2093ff4e..f9bafebd 100755 --- a/azalea/examples/echo.rs +++ b/azalea/examples/echo.rs @@ -18,7 +18,7 @@ async fn main() { .unwrap(); } -#[derive(Default, Clone)] +#[derive(Default, Clone, Component)] pub struct State {} async fn handle(bot: Client, event: Event, _state: State) -> anyhow::Result<()> { diff --git a/azalea/examples/mine_a_chunk.rs b/azalea/examples/mine_a_chunk.rs index b48fb99c..72d27ff3 100644 --- a/azalea/examples/mine_a_chunk.rs +++ b/azalea/examples/mine_a_chunk.rs @@ -7,7 +7,7 @@ async fn main() { let mut states = Vec::new(); for i in 0..10 { - accounts.push(Account::offline(&format!("bot{}", i))); + accounts.push(Account::offline(&format!("bot{o}"))); states.push(State::default()); } diff --git a/azalea/examples/potatobot/autoeat.rs b/azalea/examples/potatobot/autoeat.rs index 89934fa2..34b418f9 100755 --- a/azalea/examples/potatobot/autoeat.rs +++ b/azalea/examples/potatobot/autoeat.rs @@ -1,6 +1,7 @@ //! Automatically eat when we get hungry. use async_trait::async_trait; +use azalea::prelude::*; use azalea::{Client, Event}; use parking_lot::Mutex; use std::sync::Arc; @@ -10,7 +11,7 @@ pub struct Plugin { pub state: State, } -#[derive(Default, Clone)] +#[derive(Default, Clone, Component)] pub struct State {} #[async_trait] diff --git a/azalea/examples/pvp.rs b/azalea/examples/pvp.rs index 9d2fdc35..28e54f35 100755 --- a/azalea/examples/pvp.rs +++ b/azalea/examples/pvp.rs @@ -7,7 +7,7 @@ async fn main() { let mut states = Vec::new(); for i in 0..10 { - accounts.push(Account::offline(&format!("bot{}", i))); + accounts.push(Account::offline(&format!("bot{i}"))); states.push(State::default()); } @@ -46,16 +46,16 @@ async fn swarm_handle( ) -> anyhow::Result<()> { match event { SwarmEvent::Tick => { - // choose an arbitrary player within render distance to target - if let Some(target) = swarm - .worlds - .read() - .entity_by(|e| e.id == "minecraft:player") + if let Some(target_entity) = + swarm.entity_by::<Player>(|name: &Name| name == "Herobrine") { + let target_bounding_box = + swarm.map_entity(target_entity, |bb: &BoundingBox| bb.clone()); + for (bot, bot_state) in swarm { - bot.tick_goto_goal(pathfinder::Goals::Reach(target.bounding_box)); + bot.tick_goto_goal(pathfinder::Goals::Reach(target_bounding_box)); // if target.bounding_box.distance(bot.eyes) < bot.reach_distance() { - if bot.entity().can_reach(target.bounding_box) { + if azalea::entities::can_reach(bot.entity(), target_bounding_box) { bot.swing(); } if !bot.using_held_item() && bot.hunger() <= 17 { |
