diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2023-03-07 22:09:56 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-07 22:09:56 -0600 |
| commit | 5dd35c7ed82c38ef36ca28f630e8d05c5db2cbea (patch) | |
| tree | 72719e46479e7884ea535c768ab7c244ce048063 /azalea/examples/testbot.rs | |
| parent | 719379a8a76ab0685f2bd14bebe2f0cd1e97f06b (diff) | |
| download | azalea-drasl-5dd35c7ed82c38ef36ca28f630e8d05c5db2cbea.tar.xz | |
Add World::find_block (#80)
* start adding World::find_block
* keep working on find_block
* BlockStates
* fix sorting
* update examples that use find_one_block
* azalea_block::properties
* fix tests
* add a gotoblock command to testbot
Diffstat (limited to 'azalea/examples/testbot.rs')
| -rw-r--r-- | azalea/examples/testbot.rs | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/azalea/examples/testbot.rs b/azalea/examples/testbot.rs index 7b7b32b0..a25b28e3 100644 --- a/azalea/examples/testbot.rs +++ b/azalea/examples/testbot.rs @@ -52,17 +52,17 @@ async fn main() -> anyhow::Result<()> { } loop { - // let e = SwarmBuilder::new() - // .add_accounts(accounts.clone()) - // .set_handler(handle) - // .set_swarm_handler(swarm_handle) - // .join_delay(Duration::from_millis(1000)) - // .start("localhost") - // .await; - let e = azalea::ClientBuilder::new() + let e = SwarmBuilder::new() + .add_accounts(accounts.clone()) .set_handler(handle) - .start(Account::offline("bot"), "localhost") + .set_swarm_handler(swarm_handle) + .join_delay(Duration::from_millis(1000)) + .start("localhost") .await; + // let e = azalea::ClientBuilder::new() + // .set_handler(handle) + // .start(Account::offline("bot"), "localhost") + // .await; eprintln!("{e:?}"); } } @@ -140,6 +140,25 @@ async fn handle(mut bot: Client, event: Event, _state: State) -> anyhow::Result< "lag" => { std::thread::sleep(Duration::from_millis(1000)); } + "findblock" => { + let target_pos = bot.world().read().find_block( + bot.component::<Position>(), + &azalea_registry::Block::DiamondBlock.into(), + ); + bot.chat(&format!("target_pos: {target_pos:?}",)); + } + "gotoblock" => { + let target_pos = bot.world().read().find_block( + bot.component::<Position>(), + &azalea_registry::Block::DiamondBlock.into(), + ); + if let Some(target_pos) = target_pos { + // +1 to stand on top of the block + bot.goto(BlockPosGoal::from(target_pos.up(1))); + } else { + bot.chat("no diamond block found"); + } + } _ => {} } } |
