build(deps)!: update azalea and fix ecs changes

This commit is contained in:
2025-04-18 00:20:55 -04:00
parent 3b154c6a35
commit 63cfc7c9c0
24 changed files with 2690 additions and 1881 deletions

View File

@@ -1,16 +1,16 @@
use azalea::{
BlockPos,
blocks::{BlockState, BlockStates},
block::{BlockState, BlockStates},
ecs::query::{With, Without},
entity::{
Dead, EntityKind, EntityUuid, LookDirection, Pose, Position as AzaleaPosition,
Dead, EntityKindComponent, EntityUuid, LookDirection, Pose, Position as AzaleaPosition,
metadata::{CustomName, Owneruuid, Player},
},
world::MinecraftEntityId,
};
use mlua::{Function, Lua, Result, Table, UserDataRef};
use super::{Client, Direction, Vec3};
use crate::lua::client::MinecraftEntityId;
pub fn blocks(
_lua: &Lua,
@@ -28,7 +28,10 @@ pub fn blocks(
nearest_to.z as i32,
),
&BlockStates {
set: block_states.iter().map(|&id| BlockState { id }).collect(),
set: block_states
.into_iter()
.flat_map(BlockState::try_from)
.collect(),
},
)
.map(Vec3::from)

View File

@@ -2,21 +2,24 @@
mod queries;
pub mod find;
use azalea::{BlockPos, auto_tool::AutoToolClientExt, blocks::BlockState, world::InstanceName};
use mlua::{Lua, Result, Table};
use azalea::{BlockPos, block::BlockState, world::WorldName};
use mlua::{Lua, Result, Table, Value};
use super::{Client, Direction, Vec3};
pub fn best_tool_for_block(lua: &Lua, client: &Client, block_state: u16) -> Result<Table> {
let result = client.best_tool_in_hotbar_for_block(BlockState { id: block_state });
pub fn best_tool_for_block(lua: &Lua, client: &Client, block_state: u16) -> Result<Value> {
let Ok(block) = BlockState::try_from(block_state) else {
return Ok(Value::Nil);
};
let result = client.best_tool_in_hotbar_for_block(block);
let table = lua.create_table()?;
table.set("index", result.index)?;
table.set("percentage_per_tick", result.percentage_per_tick)?;
Ok(table)
Ok(Value::Table(table))
}
pub fn dimension(_lua: &Lua, client: &Client) -> Result<String> {
Ok(client.component::<InstanceName>().to_string())
Ok(client.component::<WorldName>().to_string())
}
pub fn get_block_state(_lua: &Lua, client: &Client, position: Vec3) -> Result<Option<u16>> {
@@ -24,17 +27,17 @@ pub fn get_block_state(_lua: &Lua, client: &Client, position: Vec3) -> Result<Op
Ok(client
.world()
.read()
.get_block_state(&BlockPos::new(
.get_block_state(BlockPos::new(
position.x as i32,
position.y as i32,
position.z as i32,
))
.map(|block| block.id))
.map(|block| block.id()))
}
#[allow(clippy::cast_possible_truncation)]
pub fn get_fluid_state(lua: &Lua, client: &Client, position: Vec3) -> Result<Option<Table>> {
let fluid_state = client.world().read().get_fluid_state(&BlockPos::new(
let fluid_state = client.world().read().get_fluid_state(BlockPos::new(
position.x as i32,
position.y as i32,
position.z as i32,

View File

@@ -1,11 +1,11 @@
#[macro_export]
macro_rules! get_entities {
($client:ident) => {{
let mut ecs = $client.ecs.lock();
let mut ecs = $client.ecs.write();
ecs.query::<(
&AzaleaPosition,
&CustomName,
&EntityKind,
&EntityKindComponent,
&EntityUuid,
&LookDirection,
&MinecraftEntityId,
@@ -16,7 +16,7 @@ macro_rules! get_entities {
.map(
|(position, custom_name, kind, uuid, direction, id, owner_uuid, pose)| {
(
Vec3::from(position),
Vec3::from(*position),
custom_name.as_ref().map(ToString::to_string),
kind.to_string(),
uuid.to_string(),
@@ -34,11 +34,11 @@ macro_rules! get_entities {
#[macro_export]
macro_rules! get_players {
($client:ident) => {{
let mut ecs = $client.ecs.lock();
let mut ecs = $client.ecs.write();
ecs.query_filtered::<(
&MinecraftEntityId,
&EntityUuid,
&EntityKind,
&EntityKindComponent,
&AzaleaPosition,
&LookDirection,
&Pose,
@@ -49,7 +49,7 @@ macro_rules! get_players {
id.0,
uuid.to_string(),
kind.to_string(),
Vec3::from(position),
Vec3::from(*position),
Direction::from(direction),
*pose as u8,
)