feat(client): bring a few commands from v0.1.0
This commit is contained in:
parent
08b9fbbc1e
commit
70c1a83eb2
@ -1,5 +1,11 @@
|
||||
use super::{Client, Vec3};
|
||||
use azalea::{BlockPos, BotClientExt, attack::AttackEvent, world::MinecraftEntityId};
|
||||
use azalea::{
|
||||
BlockPos, BotClientExt,
|
||||
attack::AttackEvent,
|
||||
protocol::packets::game::{ServerboundUseItem, s_interact::InteractionHand},
|
||||
world::MinecraftEntityId,
|
||||
};
|
||||
use log::error;
|
||||
use mlua::{Lua, Result, UserDataRef};
|
||||
|
||||
pub async fn attack(_lua: Lua, client: UserDataRef<Client>, entity_id: u32) -> Result<()> {
|
||||
@ -60,3 +66,19 @@ pub fn start_mining(_lua: &Lua, client: &mut Client, position: Vec3) -> Result<(
|
||||
));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn use_item(_lua: &Lua, client: &Client, hand: Option<u8>) -> Result<()> {
|
||||
let d = client.direction();
|
||||
if let Err(error) = client.write_packet(ServerboundUseItem {
|
||||
hand: match hand {
|
||||
Some(1) => InteractionHand::OffHand,
|
||||
_ => InteractionHand::MainHand,
|
||||
},
|
||||
sequence: 0,
|
||||
yaw: d.0,
|
||||
pitch: d.1,
|
||||
}) {
|
||||
error!("failed to send UseItem packet: {error:?}");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -72,7 +72,10 @@ impl UserData for Client {
|
||||
m.add_method("get_fluid_state", world::get_fluid_state);
|
||||
m.add_method("set_held_slot", container::set_held_slot);
|
||||
m.add_method("set_mining", interaction::set_mining);
|
||||
m.add_method("set_sneaking", movement::set_sneaking);
|
||||
m.add_method("stop_pathfinding", movement::stop_pathfinding);
|
||||
m.add_method("stop_sleeping", movement::stop_sleeping);
|
||||
m.add_method("use_item", interaction::use_item);
|
||||
m.add_method_mut("block_interact", interaction::block_interact);
|
||||
m.add_method_mut("jump", movement::jump);
|
||||
m.add_method_mut("open_inventory", container::open_inventory);
|
||||
|
@ -7,7 +7,9 @@ use azalea::{
|
||||
ExecutingPath, GotoEvent, Pathfinder, PathfinderClientExt,
|
||||
goals::{BlockPosGoal, Goal, RadiusGoal, ReachBlockPosGoal, XZGoal, YGoal},
|
||||
},
|
||||
protocol::packets::game::{ServerboundPlayerCommand, s_player_command::Action},
|
||||
};
|
||||
use log::error;
|
||||
use mlua::{FromLua, Lua, Result, Table, UserDataRef, Value};
|
||||
|
||||
pub fn direction(_lua: &Lua, client: &Client) -> Result<Direction> {
|
||||
@ -182,6 +184,21 @@ pub fn set_jumping(_lua: &Lua, client: &mut Client, jumping: bool) -> Result<()>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_sneaking(_lua: &Lua, client: &Client, sneaking: bool) -> Result<()> {
|
||||
if let Err(error) = client.write_packet(ServerboundPlayerCommand {
|
||||
id: client.entity.index(),
|
||||
action: if sneaking {
|
||||
Action::PressShiftKey
|
||||
} else {
|
||||
Action::ReleaseShiftKey
|
||||
},
|
||||
data: 0,
|
||||
}) {
|
||||
error!("failed to send PlayerCommand packet: {error:?}");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn sprint(_lua: &Lua, client: &mut Client, direction: u8) -> Result<()> {
|
||||
client.sprint(match direction {
|
||||
5 => SprintDirection::ForwardRight,
|
||||
@ -196,6 +213,17 @@ pub fn stop_pathfinding(_lua: &Lua, client: &Client, _: ()) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn stop_sleeping(_lua: &Lua, client: &Client, _: ()) -> Result<()> {
|
||||
if let Err(error) = client.write_packet(ServerboundPlayerCommand {
|
||||
id: client.entity.index(),
|
||||
action: Action::StopSleeping,
|
||||
data: 0,
|
||||
}) {
|
||||
error!("failed to send PlayerCommand packet: {error:?}");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn walk(_lua: &Lua, client: &mut Client, direction: u8) -> Result<()> {
|
||||
client.walk(match direction {
|
||||
1 => WalkDirection::Forward,
|
||||
|
Loading…
x
Reference in New Issue
Block a user