diff options
| author | mat <github@matdoes.dev> | 2022-06-18 16:33:38 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-06-18 16:33:38 -0500 |
| commit | e32b8fabb78a86e073c7bb3270b1bc89a532350a (patch) | |
| tree | 53f485306cf053db82a94feb655ec1fc49eff918 /examples/pvp.rs | |
| parent | d8e0457b62f5826183671e5b05890b400be35709 (diff) | |
| download | azalea-drasl-e32b8fabb78a86e073c7bb3270b1bc89a532350a.tar.xz | |
Add a new example that uses entities
Diffstat (limited to 'examples/pvp.rs')
| -rw-r--r-- | examples/pvp.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/examples/pvp.rs b/examples/pvp.rs new file mode 100644 index 00000000..61382ecd --- /dev/null +++ b/examples/pvp.rs @@ -0,0 +1,33 @@ +use azalea::{Account, Accounts, Event, pathfinder}; + +#[tokio::main] +async fn main() { + let accounts = Accounts::new(); + for i in 0..10 { + accounts.add(Account::offline(format!("bot{}", i))); + } + + let bots = accounts.join("localhost".try_into().unwrap()).await.unwrap(); + + match bots.next().await { + Event::Tick { + // choose an arbitrary player within render distance to target + if let Some(target) = bots.world.find_one_entity(|e| e.id == "minecraft:player") { + for bot in bots { + 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) { + bot.swing(); + } + if !h.using_held_item() && bot.state.lock().await.hunger <= 17 { + bot.hold(azalea::ItemGroup::Food); + tokio::task::spawn(bot.use_held_item()); + } + } + } + }, + _ => {} + } +} |
