mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 23:44:38 +00:00
Add a new example that uses entities
This commit is contained in:
parent
d8e0457b62
commit
e32b8fabb7
3 changed files with 37 additions and 4 deletions
|
@ -23,7 +23,7 @@ async fn main() {
|
||||||
Event::Chat(p) => {
|
Event::Chat(p) => {
|
||||||
let state = client.state.lock().await;
|
let state = client.state.lock().await;
|
||||||
let world = state.world.as_ref().unwrap();
|
let world = state.world.as_ref().unwrap();
|
||||||
println!("{:?}", state.player.entity());
|
println!("{:?}", state.world.entities.get_player(player));
|
||||||
// world.get_block_state(state.player.entity.pos);
|
// world.get_block_state(state.player.entity.pos);
|
||||||
// println!("{}", p.message.to_ansi(None));
|
// println!("{}", p.message.to_ansi(None));
|
||||||
// if p.message.to_ansi(None) == "<py5> ok" {
|
// if p.message.to_ansi(None) == "<py5> ok" {
|
||||||
|
|
|
@ -8,12 +8,12 @@ bot.join("localhost".try_into().unwrap()).await.unwrap();
|
||||||
loop {
|
loop {
|
||||||
match bot.next().await {
|
match bot.next().await {
|
||||||
Event::Message(m) {
|
Event::Message(m) {
|
||||||
if m.username == bot.username { return };
|
if m.username == bot.player.username { return };
|
||||||
if m.message = "go" {
|
if m.message = "go" {
|
||||||
bot.goto_goal(
|
bot.goto_goal(
|
||||||
pathfinder::Goals::NearXZ(5, azalea::BlockXZ(0, 0))
|
pathfinder::Goals::NearXZ(5, azalea::BlockXZ(0, 0))
|
||||||
).await;
|
).await;
|
||||||
let chest = bot.open_chest(&bot.world.find_one_block(|b| b.id == "minecraft:chest")).await.unwrap();
|
let chest = bot.open_container(&bot.world.find_one_block(|b| b.id == "minecraft:chest")).await.unwrap();
|
||||||
bot.take_amount(&chest, 5, |i| i.id == "#minecraft:planks").await;
|
bot.take_amount(&chest, 5, |i| i.id == "#minecraft:planks").await;
|
||||||
// when rust adds async drop this won't be necessary
|
// when rust adds async drop this won't be necessary
|
||||||
chest.close().await;
|
chest.close().await;
|
||||||
|
@ -25,7 +25,7 @@ loop {
|
||||||
|
|
||||||
bot.hold(&pickaxe);
|
bot.hold(&pickaxe);
|
||||||
loop {
|
loop {
|
||||||
if let Err(e) = bot.dig(bot.feet_coords().down(1)).await {
|
if let Err(e) = bot.dig(bot.entity.feet_pos().down(1)).await {
|
||||||
println!("{:?}", e);
|
println!("{:?}", e);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
33
examples/pvp.rs
Normal file
33
examples/pvp.rs
Normal file
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue