refactor: minor changes

This commit is contained in:
Ryan 2025-03-13 21:34:24 -04:00
parent 3400541a79
commit a76265b2a7
Signed by: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3
5 changed files with 13 additions and 11 deletions

View File

@ -6,7 +6,7 @@ use azalea::{
protocol::packets::game::ServerboundSetCarriedItem,
};
use log::error;
use mlua::{Lua, Result, Table, UserDataRef};
use mlua::{Lua, Result, UserDataRef, Value};
pub fn container(_lua: &Lua, client: &Client) -> Result<Option<ContainerRef>> {
Ok(client.get_open_container().map(ContainerRef))
@ -21,7 +21,7 @@ pub fn held_slot(_lua: &Lua, client: &Client) -> Result<u8> {
}
#[allow(clippy::too_many_lines)]
pub fn menu(lua: &Lua, client: &Client) -> Result<Table> {
pub fn menu(lua: &Lua, client: &Client) -> Result<Value> {
fn from_slot_list<const N: usize>(s: SlotList<N>) -> Vec<ItemStack> {
s.iter()
.map(|i| ItemStack(i.to_owned()))
@ -84,9 +84,9 @@ pub fn menu(lua: &Lua, client: &Client) -> Result<Table> {
table.set("contents", from_slot_list(contents))?;
table.set("player", from_slot_list(player))?;
}
_ => (),
_ => return Ok(Value::Nil),
}
Ok(table)
Ok(Value::Table(table))
}
pub async fn open_container_at(

View File

@ -55,15 +55,15 @@ pub fn start_mining(_lua: &Lua, client: &mut Client, position: Vec3) -> Result<(
}
pub fn use_item(_lua: &Lua, client: &Client, hand: Option<u8>) -> Result<()> {
let d = client.direction();
let direction = 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,
yaw: direction.0,
pitch: direction.1,
}) {
error!("failed to send UseItem packet: {error:?}");
}

View File

@ -14,8 +14,11 @@ use log::error;
use mlua::{FromLua, Lua, Result, Table, UserDataRef, Value};
pub fn direction(_lua: &Lua, client: &Client) -> Result<Direction> {
let d = client.direction();
Ok(Direction { y: d.0, x: d.1 })
let direction = client.direction();
Ok(Direction {
y: direction.0,
x: direction.1,
})
}
pub fn eye_position(_lua: &Lua, client: &Client) -> Result<Vec3> {

View File

@ -19,7 +19,6 @@ pub fn health(_lua: &Lua, client: &Client) -> Result<f32> {
pub fn hunger(lua: &Lua, client: &Client) -> Result<Table> {
let hunger = client.hunger();
let table = lua.create_table()?;
table.set("food", hunger.food)?;
table.set("saturation", hunger.saturation)?;

View File

@ -114,9 +114,9 @@ async fn main() -> anyhow::Result<()> {
)),
};
let Err(error) = ClientBuilder::new_without_plugins()
.add_plugins(DefaultBotPlugins)
.add_plugins(default_plugins)
.add_plugins(record_plugin)
.add_plugins(DefaultBotPlugins)
.set_handler(events::handle_event)
.set_state(State {
lua: Arc::new(lua),