Add jump and interact commands
This commit is contained in:
parent
3977d83ade
commit
98474c5216
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -667,6 +667,7 @@ dependencies = [
|
|||||||
"anyhow",
|
"anyhow",
|
||||||
"azalea",
|
"azalea",
|
||||||
"azalea-block",
|
"azalea-block",
|
||||||
|
"azalea-core",
|
||||||
"azalea-protocol",
|
"azalea-protocol",
|
||||||
"chrono",
|
"chrono",
|
||||||
"colored",
|
"colored",
|
||||||
|
@ -7,6 +7,7 @@ edition = "2021"
|
|||||||
azalea = "0.5.0"
|
azalea = "0.5.0"
|
||||||
azalea-protocol = "0.5.0"
|
azalea-protocol = "0.5.0"
|
||||||
azalea-block = "0.5.0"
|
azalea-block = "0.5.0"
|
||||||
|
azalea-core = "0.5.0"
|
||||||
toml = "0.5.10"
|
toml = "0.5.10"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
tokio = "1.24.1"
|
tokio = "1.24.1"
|
||||||
|
67
src/bot.rs
67
src/bot.rs
@ -1,5 +1,8 @@
|
|||||||
use crate::{logging::log_error, State};
|
use crate::{logging::log_error, State};
|
||||||
use azalea::{pathfinder::BlockPosGoal, prelude::*, BlockPos, SprintDirection, WalkDirection};
|
use azalea::{
|
||||||
|
pathfinder::BlockPosGoal, prelude::*, BlockPos, SprintDirection, Vec3, WalkDirection,
|
||||||
|
};
|
||||||
|
use azalea_core::Direction;
|
||||||
use azalea_protocol::packets::game::{
|
use azalea_protocol::packets::game::{
|
||||||
self, serverbound_interact_packet::InteractionHand, ServerboundGamePacket,
|
self, serverbound_interact_packet::InteractionHand, ServerboundGamePacket,
|
||||||
};
|
};
|
||||||
@ -26,8 +29,10 @@ pub enum Command {
|
|||||||
Look,
|
Look,
|
||||||
Sneak,
|
Sneak,
|
||||||
Unsneak,
|
Unsneak,
|
||||||
Interact,
|
InteractBlock,
|
||||||
|
InteractEntity,
|
||||||
Attack,
|
Attack,
|
||||||
|
Jump,
|
||||||
Walk,
|
Walk,
|
||||||
Sprint,
|
Sprint,
|
||||||
DropItem,
|
DropItem,
|
||||||
@ -70,8 +75,10 @@ pub async fn process_command(
|
|||||||
"look" => command = Command::Look,
|
"look" => command = Command::Look,
|
||||||
"sneak" => command = Command::Sneak,
|
"sneak" => command = Command::Sneak,
|
||||||
"unsneak" => command = Command::Unsneak,
|
"unsneak" => command = Command::Unsneak,
|
||||||
"interact" => command = Command::Interact,
|
"interact_block" => command = Command::InteractBlock,
|
||||||
|
"interact_entity" => command = Command::InteractEntity,
|
||||||
"attack" => command = Command::Attack,
|
"attack" => command = Command::Attack,
|
||||||
|
"jump" => command = Command::Jump,
|
||||||
"walk" => command = Command::Walk,
|
"walk" => command = Command::Walk,
|
||||||
"sprint" => command = Command::Sprint,
|
"sprint" => command = Command::Sprint,
|
||||||
"drop_item" => command = Command::DropItem,
|
"drop_item" => command = Command::DropItem,
|
||||||
@ -371,7 +378,55 @@ pub async fn process_command(
|
|||||||
);
|
);
|
||||||
return "I am no longer sneaking!".to_string();
|
return "I am no longer sneaking!".to_string();
|
||||||
}
|
}
|
||||||
Command::Interact => {
|
Command::InteractBlock => {
|
||||||
|
if segments.len() < 4 {
|
||||||
|
return "Please give me block coordinates (and block faces) to interact with!"
|
||||||
|
.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut coordinates: Vec<i32> = Vec::new();
|
||||||
|
for segment in &segments[0..3] {
|
||||||
|
coordinates.push(match segment.parse() {
|
||||||
|
Ok(number) => number,
|
||||||
|
Err(error) => return format!("Unable to parse coordinates: {}", error),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
let block_face = match segments[3].to_lowercase().as_str() {
|
||||||
|
"up" | "top" => Direction::Up,
|
||||||
|
"down" | "bottom" => Direction::Down,
|
||||||
|
"north" => Direction::North,
|
||||||
|
"east" => Direction::East,
|
||||||
|
"south" => Direction::South,
|
||||||
|
"west" => Direction::West,
|
||||||
|
_ => return "Please give me a valid block face!".to_string(),
|
||||||
|
};
|
||||||
|
log_error(
|
||||||
|
client
|
||||||
|
.write_packet(ServerboundGamePacket::UseItemOn(
|
||||||
|
game::serverbound_use_item_on_packet::ServerboundUseItemOnPacket {
|
||||||
|
hand: InteractionHand::MainHand,
|
||||||
|
block_hit: game::serverbound_use_item_on_packet::BlockHitResult {
|
||||||
|
block_pos: BlockPos {
|
||||||
|
x: coordinates[0],
|
||||||
|
y: coordinates[1],
|
||||||
|
z: coordinates[2],
|
||||||
|
},
|
||||||
|
direction: block_face,
|
||||||
|
location: Vec3 {
|
||||||
|
x: coordinates[0] as f64,
|
||||||
|
y: coordinates[1] as f64,
|
||||||
|
z: coordinates[2] as f64,
|
||||||
|
},
|
||||||
|
inside: false,
|
||||||
|
},
|
||||||
|
sequence: 0,
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.await,
|
||||||
|
);
|
||||||
|
return "I have successfully interacted with the block!".to_string();
|
||||||
|
}
|
||||||
|
Command::InteractEntity => {
|
||||||
if segments.len() < 1 {
|
if segments.len() < 1 {
|
||||||
return "Please give me IDs to interact with!".to_string();
|
return "Please give me IDs to interact with!".to_string();
|
||||||
}
|
}
|
||||||
@ -481,6 +536,10 @@ pub async fn process_command(
|
|||||||
return "Unable to find entity!".to_string();
|
return "Unable to find entity!".to_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Command::Jump => {
|
||||||
|
client.jump();
|
||||||
|
return "I have successfully jumped!".to_string();
|
||||||
|
}
|
||||||
Command::Walk => {
|
Command::Walk => {
|
||||||
if segments.len() < 2 {
|
if segments.len() < 2 {
|
||||||
return "Please give me a direction (and duration) to walk in!".to_string();
|
return "Please give me a direction (and duration) to walk in!".to_string();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user