refactor: remove finicky tick broadcasters from some methods
This commit is contained in:
parent
944f595841
commit
14e3781e05
src/lua/client
@ -1,27 +1,14 @@
|
||||
use super::{Client, Vec3};
|
||||
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: i32) -> Result<()> {
|
||||
client.clone().attack(MinecraftEntityId(entity_id));
|
||||
|
||||
while client.get_tick_broadcaster().recv().await.is_ok() {
|
||||
if client
|
||||
.ecs
|
||||
.lock()
|
||||
.get::<AttackEvent>(client.entity)
|
||||
.is_none()
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn attack(_lua: &Lua, client: &mut Client, entity_id: i32) -> Result<()> {
|
||||
client.attack(MinecraftEntityId(entity_id));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -59,13 +59,11 @@ impl UserData for Client {
|
||||
}
|
||||
|
||||
fn add_methods<M: UserDataMethods<Self>>(m: &mut M) {
|
||||
m.add_async_method("attack", interaction::attack);
|
||||
m.add_async_method("find_all_entities", world::find_all_entities);
|
||||
m.add_async_method("find_all_players", world::find_all_players);
|
||||
m.add_async_method("find_entities", world::find_entities);
|
||||
m.add_async_method("find_players", world::find_players);
|
||||
m.add_async_method("go_to", movement::go_to);
|
||||
m.add_async_method("look_at", movement::look_at);
|
||||
m.add_async_method("mine", interaction::mine);
|
||||
m.add_async_method("open_container_at", container::open_container_at);
|
||||
m.add_async_method("set_client_information", state::set_client_information);
|
||||
@ -82,8 +80,10 @@ impl UserData for Client {
|
||||
m.add_method("stop_pathfinding", movement::stop_pathfinding);
|
||||
m.add_method("stop_sleeping", movement::stop_sleeping);
|
||||
m.add_method("use_item", interaction::use_item);
|
||||
m.add_method_mut("attack", interaction::attack);
|
||||
m.add_method_mut("block_interact", interaction::block_interact);
|
||||
m.add_method_mut("jump", movement::jump);
|
||||
m.add_method_mut("look_at", movement::look_at);
|
||||
m.add_method_mut("open_inventory", container::open_inventory);
|
||||
m.add_method_mut("set_direction", movement::set_direction);
|
||||
m.add_method_mut("set_jumping", movement::set_jumping);
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::{Client, Direction, Vec3};
|
||||
use azalea::{
|
||||
BlockPos, BotClientExt, LookAtEvent, SprintDirection, WalkDirection,
|
||||
BlockPos, BotClientExt, SprintDirection, WalkDirection,
|
||||
entity::Position,
|
||||
interact::HitResultComponent,
|
||||
pathfinder::{
|
||||
@ -141,22 +141,8 @@ pub fn looking_at(lua: &Lua, client: &Client) -> Result<Option<Table>> {
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn look_at(_lua: Lua, client: UserDataRef<Client>, position: Vec3) -> Result<()> {
|
||||
client
|
||||
.clone()
|
||||
.look_at(azalea::Vec3::new(position.x, position.y, position.z));
|
||||
|
||||
while client.get_tick_broadcaster().recv().await.is_ok() {
|
||||
if client
|
||||
.ecs
|
||||
.lock()
|
||||
.get::<LookAtEvent>(client.entity)
|
||||
.is_none()
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn look_at(_lua: &Lua, client: &mut Client, position: Vec3) -> Result<()> {
|
||||
client.look_at(azalea::Vec3::new(position.x, position.y, position.z));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user