refactor: rename tables to table

This commit is contained in:
2025-02-28 22:04:28 -05:00
parent 6c7156f70d
commit 3e74399e5b
4 changed files with 51 additions and 45 deletions

View File

@@ -117,15 +117,15 @@ pub fn jump(_lua: &Lua, client: &mut Client, _: ()) -> Result<()> {
}
pub fn looking_at(lua: &Lua, client: &Client) -> Result<Option<Table>> {
let r = client.component::<HitResultComponent>();
Ok(if r.miss {
let result = client.component::<HitResultComponent>();
Ok(if result.miss {
None
} else {
let result = lua.create_table()?;
result.set("position", Vec3::from(r.block_pos))?;
result.set("inside", r.inside)?;
result.set("world_border", r.world_border)?;
Some(result)
let table = lua.create_table()?;
table.set("position", Vec3::from(result.block_pos))?;
table.set("inside", result.inside)?;
table.set("world_border", result.world_border)?;
Some(table)
})
}
@@ -149,26 +149,29 @@ pub async fn look_at(_lua: Lua, client: UserDataRef<Client>, position: Vec3) ->
}
pub fn pathfinder(lua: &Lua, client: &Client) -> Result<Table> {
let pathfinder = lua.create_table()?;
pathfinder.set(
let table = lua.create_table()?;
table.set(
"is_calculating",
client.component::<Pathfinder>().is_calculating,
)?;
pathfinder.set(
table.set(
"is_executing",
if let Some(p) = client.get_component::<ExecutingPath>() {
pathfinder.set("last_reached_node", Vec3::from(p.last_reached_node))?;
pathfinder.set(
"last_node_reach_elapsed",
p.last_node_reached_at.elapsed().as_millis(),
if let Some(pathfinder) = client.get_component::<ExecutingPath>() {
table.set(
"last_reached_node",
Vec3::from(pathfinder.last_reached_node),
)?;
pathfinder.set("is_path_partial", p.is_path_partial)?;
table.set(
"last_node_reach_elapsed",
pathfinder.last_node_reached_at.elapsed().as_millis(),
)?;
table.set("is_path_partial", pathfinder.is_path_partial)?;
true
} else {
false
},
)?;
Ok(pathfinder)
Ok(table)
}
pub fn position(_lua: &Lua, client: &Client) -> Result<Vec3> {

View File

@@ -16,12 +16,12 @@ pub fn health(_lua: &Lua, client: &Client) -> Result<f32> {
}
pub fn hunger(lua: &Lua, client: &Client) -> Result<Table> {
let h = client.hunger();
let hunger = client.hunger();
let hunger = lua.create_table()?;
hunger.set("food", h.food)?;
hunger.set("saturation", h.saturation)?;
Ok(hunger)
let table = lua.create_table()?;
table.set("food", hunger.food)?;
table.set("saturation", hunger.saturation)?;
Ok(table)
}
pub fn score(_lua: &Lua, client: &Client) -> Result<i32> {

View File

@@ -13,12 +13,12 @@ use azalea::{
use mlua::{Function, Lua, Result, Table, UserDataRef};
pub fn best_tool_for_block(lua: &Lua, client: &Client, block_state: u16) -> Result<Table> {
let tr = client.best_tool_in_hotbar_for_block(BlockState { id: block_state });
let result = client.best_tool_in_hotbar_for_block(BlockState { id: block_state });
let tool_result = lua.create_table()?;
tool_result.set("index", tr.index)?;
tool_result.set("percentage_per_tick", tr.percentage_per_tick)?;
Ok(tool_result)
let table = lua.create_table()?;
table.set("index", result.index)?;
table.set("percentage_per_tick", result.percentage_per_tick)?;
Ok(table)
}
pub fn dimension(_lua: &Lua, client: &Client) -> Result<String> {
@@ -105,16 +105,16 @@ pub fn get_block_state(_lua: &Lua, client: &Client, position: Vec3) -> Result<Op
pub fn get_fluid_state(lua: &Lua, client: &Client, position: Vec3) -> Result<Option<Table>> {
#[allow(clippy::cast_possible_truncation)]
Ok(
if let Some(fs) = client.world().read().get_fluid_state(&BlockPos::new(
if let Some(state) = client.world().read().get_fluid_state(&BlockPos::new(
position.x as i32,
position.y as i32,
position.z as i32,
)) {
let fluid_state = lua.create_table()?;
fluid_state.set("kind", fs.kind as u8)?;
fluid_state.set("amount", fs.amount)?;
fluid_state.set("falling", fs.falling)?;
Some(fluid_state)
let table = lua.create_table()?;
table.set("kind", state.kind as u8)?;
table.set("amount", state.amount)?;
table.set("falling", state.falling)?;
Some(table)
} else {
None
},