refactor: rename tables to table
This commit is contained in:
parent
6c7156f70d
commit
3e74399e5b
@ -9,7 +9,10 @@ pub fn register_functions(lua: &Lua, globals: &Table) -> Result<()> {
|
|||||||
"get_block_from_state",
|
"get_block_from_state",
|
||||||
lua.create_function(get_block_from_state)?,
|
lua.create_function(get_block_from_state)?,
|
||||||
)?;
|
)?;
|
||||||
globals.set("get_block_states", lua.create_async_function(get_block_states)?)?;
|
globals.set(
|
||||||
|
"get_block_states",
|
||||||
|
lua.create_async_function(get_block_states)?,
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -18,20 +21,20 @@ pub fn get_block_from_state(lua: &Lua, state: u32) -> Result<Option<Table>> {
|
|||||||
let Ok(state) = BlockState::try_from(state) else {
|
let Ok(state) = BlockState::try_from(state) else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
let b: Box<dyn AzaleaBlock> = state.into();
|
let block: Box<dyn AzaleaBlock> = state.into();
|
||||||
let bh = b.behavior();
|
let behavior = block.behavior();
|
||||||
|
|
||||||
let block = lua.create_table()?;
|
let table = lua.create_table()?;
|
||||||
block.set("id", b.id())?;
|
table.set("id", block.id())?;
|
||||||
block.set("friction", bh.friction)?;
|
table.set("friction", behavior.friction)?;
|
||||||
block.set("jump_factor", bh.jump_factor)?;
|
table.set("jump_factor", behavior.jump_factor)?;
|
||||||
block.set("destroy_time", bh.destroy_time)?;
|
table.set("destroy_time", behavior.destroy_time)?;
|
||||||
block.set("explosion_resistance", bh.explosion_resistance)?;
|
table.set("explosion_resistance", behavior.explosion_resistance)?;
|
||||||
block.set(
|
table.set(
|
||||||
"requires_correct_tool_for_drops",
|
"requires_correct_tool_for_drops",
|
||||||
bh.requires_correct_tool_for_drops,
|
behavior.requires_correct_tool_for_drops,
|
||||||
)?;
|
)?;
|
||||||
Ok(Some(block))
|
Ok(Some(table))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_block_states(
|
pub async fn get_block_states(
|
||||||
|
@ -117,15 +117,15 @@ pub fn jump(_lua: &Lua, client: &mut Client, _: ()) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn looking_at(lua: &Lua, client: &Client) -> Result<Option<Table>> {
|
pub fn looking_at(lua: &Lua, client: &Client) -> Result<Option<Table>> {
|
||||||
let r = client.component::<HitResultComponent>();
|
let result = client.component::<HitResultComponent>();
|
||||||
Ok(if r.miss {
|
Ok(if result.miss {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let result = lua.create_table()?;
|
let table = lua.create_table()?;
|
||||||
result.set("position", Vec3::from(r.block_pos))?;
|
table.set("position", Vec3::from(result.block_pos))?;
|
||||||
result.set("inside", r.inside)?;
|
table.set("inside", result.inside)?;
|
||||||
result.set("world_border", r.world_border)?;
|
table.set("world_border", result.world_border)?;
|
||||||
Some(result)
|
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> {
|
pub fn pathfinder(lua: &Lua, client: &Client) -> Result<Table> {
|
||||||
let pathfinder = lua.create_table()?;
|
let table = lua.create_table()?;
|
||||||
pathfinder.set(
|
table.set(
|
||||||
"is_calculating",
|
"is_calculating",
|
||||||
client.component::<Pathfinder>().is_calculating,
|
client.component::<Pathfinder>().is_calculating,
|
||||||
)?;
|
)?;
|
||||||
pathfinder.set(
|
table.set(
|
||||||
"is_executing",
|
"is_executing",
|
||||||
if let Some(p) = client.get_component::<ExecutingPath>() {
|
if let Some(pathfinder) = client.get_component::<ExecutingPath>() {
|
||||||
pathfinder.set("last_reached_node", Vec3::from(p.last_reached_node))?;
|
table.set(
|
||||||
pathfinder.set(
|
"last_reached_node",
|
||||||
"last_node_reach_elapsed",
|
Vec3::from(pathfinder.last_reached_node),
|
||||||
p.last_node_reached_at.elapsed().as_millis(),
|
|
||||||
)?;
|
)?;
|
||||||
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
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
Ok(pathfinder)
|
Ok(table)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn position(_lua: &Lua, client: &Client) -> Result<Vec3> {
|
pub fn position(_lua: &Lua, client: &Client) -> Result<Vec3> {
|
||||||
|
@ -16,12 +16,12 @@ pub fn health(_lua: &Lua, client: &Client) -> Result<f32> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn hunger(lua: &Lua, client: &Client) -> Result<Table> {
|
pub fn hunger(lua: &Lua, client: &Client) -> Result<Table> {
|
||||||
let h = client.hunger();
|
let hunger = client.hunger();
|
||||||
|
|
||||||
let hunger = lua.create_table()?;
|
let table = lua.create_table()?;
|
||||||
hunger.set("food", h.food)?;
|
table.set("food", hunger.food)?;
|
||||||
hunger.set("saturation", h.saturation)?;
|
table.set("saturation", hunger.saturation)?;
|
||||||
Ok(hunger)
|
Ok(table)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn score(_lua: &Lua, client: &Client) -> Result<i32> {
|
pub fn score(_lua: &Lua, client: &Client) -> Result<i32> {
|
||||||
|
@ -13,12 +13,12 @@ use azalea::{
|
|||||||
use mlua::{Function, Lua, Result, Table, UserDataRef};
|
use mlua::{Function, Lua, Result, Table, UserDataRef};
|
||||||
|
|
||||||
pub fn best_tool_for_block(lua: &Lua, client: &Client, block_state: u16) -> Result<Table> {
|
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()?;
|
let table = lua.create_table()?;
|
||||||
tool_result.set("index", tr.index)?;
|
table.set("index", result.index)?;
|
||||||
tool_result.set("percentage_per_tick", tr.percentage_per_tick)?;
|
table.set("percentage_per_tick", result.percentage_per_tick)?;
|
||||||
Ok(tool_result)
|
Ok(table)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dimension(_lua: &Lua, client: &Client) -> Result<String> {
|
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>> {
|
pub fn get_fluid_state(lua: &Lua, client: &Client, position: Vec3) -> Result<Option<Table>> {
|
||||||
#[allow(clippy::cast_possible_truncation)]
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
Ok(
|
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.x as i32,
|
||||||
position.y as i32,
|
position.y as i32,
|
||||||
position.z as i32,
|
position.z as i32,
|
||||||
)) {
|
)) {
|
||||||
let fluid_state = lua.create_table()?;
|
let table = lua.create_table()?;
|
||||||
fluid_state.set("kind", fs.kind as u8)?;
|
table.set("kind", state.kind as u8)?;
|
||||||
fluid_state.set("amount", fs.amount)?;
|
table.set("amount", state.amount)?;
|
||||||
fluid_state.set("falling", fs.falling)?;
|
table.set("falling", state.falling)?;
|
||||||
Some(fluid_state)
|
Some(table)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user