feat(client): bring a few commands from v0.1.0

This commit is contained in:
2025-02-21 23:00:29 -05:00
parent 08b9fbbc1e
commit 70c1a83eb2
3 changed files with 54 additions and 1 deletions

View File

@@ -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(())
}