refactor: a few small efficiency improvements
This commit is contained in:
parent
aa27d9fd36
commit
c2da997b71
@ -9,7 +9,7 @@ use azalea::{
|
||||
use bevy_ecs::{entity::Entity, query::With};
|
||||
use futures::lock::Mutex;
|
||||
|
||||
pub type Ctx<'a> = CommandContext<Mutex<CommandSource>>;
|
||||
pub type Ctx = CommandContext<Mutex<CommandSource>>;
|
||||
|
||||
pub struct CommandSource {
|
||||
pub client: Client,
|
||||
|
@ -1,6 +1,7 @@
|
||||
use super::{Client, Direction, Vec3};
|
||||
use azalea::{
|
||||
BlockPos, BotClientExt, LookAtEvent, SprintDirection, WalkDirection,
|
||||
entity::Position,
|
||||
interact::HitResultComponent,
|
||||
pathfinder::{
|
||||
ExecutingPath, GotoEvent, Pathfinder, PathfinderClientExt,
|
||||
@ -187,7 +188,7 @@ pub fn pathfinder(lua: &Lua, client: &Client) -> Result<Table> {
|
||||
}
|
||||
|
||||
pub fn position(_lua: &Lua, client: &Client) -> Result<Vec3> {
|
||||
let p = client.position();
|
||||
let p = client.component::<Position>();
|
||||
Ok(Vec3 {
|
||||
x: p.x,
|
||||
y: p.y,
|
||||
|
18
src/main.rs
18
src/main.rs
@ -14,6 +14,8 @@ use futures::lock::Mutex;
|
||||
use mlua::Lua;
|
||||
use std::{net::SocketAddr, path::PathBuf, sync::Arc};
|
||||
|
||||
const DEFAULT_SCRIPT_PATH: &str = "errornowatcher.lua";
|
||||
|
||||
#[derive(Default, Clone, Component)]
|
||||
pub struct State {
|
||||
lua: Lua,
|
||||
@ -24,14 +26,22 @@ pub struct State {
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let args = arguments::Arguments::parse();
|
||||
let script_path = args.script.unwrap_or(PathBuf::from("errornowatcher.lua"));
|
||||
let script_path = args.script.unwrap_or(PathBuf::from(DEFAULT_SCRIPT_PATH));
|
||||
|
||||
let lua = Lua::new();
|
||||
lua.load(std::fs::read_to_string(&script_path)?).exec()?;
|
||||
lua.load(
|
||||
std::fs::read_to_string(&script_path)
|
||||
.expect(&(DEFAULT_SCRIPT_PATH.to_owned() + " should be in current directory")),
|
||||
)
|
||||
.exec()?;
|
||||
|
||||
let globals = lua.globals();
|
||||
let server = globals.get::<String>("SERVER")?;
|
||||
let username = globals.get::<String>("USERNAME")?;
|
||||
let server = globals
|
||||
.get::<String>("SERVER")
|
||||
.expect("SERVER should be in lua globals");
|
||||
let username = globals
|
||||
.get::<String>("USERNAME")
|
||||
.expect("USERNAME should be in lua globals");
|
||||
|
||||
globals.set("script_path", script_path)?;
|
||||
lua::register_functions(&lua, &globals)?;
|
||||
|
Loading…
x
Reference in New Issue
Block a user