diff --git a/Cargo.lock b/Cargo.lock index 8d6493c..c52085d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1825,15 +1825,6 @@ dependencies = [ "linked-hash-map", ] -[[package]] -name = "luau0-src" -version = "0.12.2+luau660" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d62e6fe44400150a045b8f2a6721a268437d45dc67600f8ca716e2fa3a3cc2fe" -dependencies = [ - "cc", -] - [[package]] name = "matchers" version = "0.1.0" @@ -1906,7 +1897,6 @@ dependencies = [ "bstr", "either", "futures-util", - "libloading", "mlua-sys", "num-traits", "parking_lot", @@ -1921,7 +1911,6 @@ checksum = "1901c1a635a22fe9250ffcc4fcc937c16b47c2e9e71adba8784af8bca1f69594" dependencies = [ "cc", "cfg-if", - "luau0-src", "pkg-config", ] diff --git a/Cargo.toml b/Cargo.toml index 55eb68d..3d9f48a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,5 +25,5 @@ http-body-util = "0" hyper = { version = "1", features = ["server"] } hyper-util = "0" log = { version = "0" } -mlua = { version = "0", features = ["async", "luau-jit", "send"] } +mlua = { version = "0", features = ["async", "luajit", "send"] } tokio = { version = "1", features = ["macros"] } diff --git a/errornowatcher.lua b/errornowatcher.lua index fda0b68..2b78133 100644 --- a/errornowatcher.lua +++ b/errornowatcher.lua @@ -2,15 +2,13 @@ Server = "localhost" Username = "ErrorNoWatcher" Owners = { "ErrorNoInternet" } -for _, module in - { - "enum", - "events", - "inventory", - "movement", - "utils", - } -do +for _, module in ipairs({ + "enum", + "events", + "inventory", + "movement", + "utils", +}) do module = "lib/" .. module package.loaded[module] = nil require(module) diff --git a/lib/events.lua b/lib/events.lua index 9f11a8e..25cc95b 100644 --- a/lib/events.lua +++ b/lib/events.lua @@ -9,7 +9,7 @@ function log_player_positions() and e.position.z > center.z - radius and e.position.z < center.z + radius end) - for _, e in entities do + for _, e in ipairs(entities) do client:chat(string.format("%s (%s) at %.1f %.1f %.1f", e.kind, e.id, e.position.x, e.position.y, e.position.z)) end end diff --git a/lib/inventory.lua b/lib/inventory.lua index d99e618..2099511 100644 --- a/lib/inventory.lua +++ b/lib/inventory.lua @@ -1,38 +1,38 @@ function steal(item_name) - for _, chest_pos in client:find_blocks(client.position, get_block_states({ "chest" })) do - client:chat(dump(chest_pos)) + for _, chest_pos in ipairs(client:find_blocks(client.position, get_block_states({ "chest" }))) do + client:chat(dump(chest_pos)) - client:goto({ position = chest_pos, radius = 3 }, { type = RADIUS_GOAL }) - while client.pathfinder.is_calculating or client.pathfinder.is_executing do - sleep(50) - end - client:look_at(chest_pos) + client:go_to({ position = chest_pos, radius = 3 }, { type = RADIUS_GOAL }) + while client.pathfinder.is_calculating or client.pathfinder.is_executing do + sleep(50) + end + client:look_at(chest_pos) - local container = client:open_container_at(chest_pos) - for index, item in container.contents do - if item.kind == item_name then - container:click({slot = index - 1}, THROW_ALL) - sleep(50) - end - end + local container = client:open_container_at(chest_pos) + for index, item in ipairs(container.contents) do + if item.kind == item_name then + container:click({ slot = index - 1 }, THROW_ALL) + sleep(50) + end + end - container = nil - while client.open_container do - sleep(50) - end - end + container = nil + while client.open_container do + sleep(50) + end + end end function drop_all_hotbar() - local inventory = client:open_inventory() - for i = 0, 9 do - inventory:click({slot = 36 + i}, THROW_ALL) - end + local inventory = client:open_inventory() + for i = 0, 9 do + inventory:click({ slot = 36 + i }, THROW_ALL) + end end function drop_all_inventory() - local inventory = client:open_inventory() - for i = 0, 45 do - inventory:click({slot = i}, THROW_ALL) - end + local inventory = client:open_inventory() + for i = 0, 45 do + inventory:click({ slot = i }, THROW_ALL) + end end diff --git a/lib/movement.lua b/lib/movement.lua index 1de35d5..f04436c 100644 --- a/lib/movement.lua +++ b/lib/movement.lua @@ -8,10 +8,10 @@ function look_at_player(name) end end -function goto_player(name, opts) +function go_to_player(name, opts) local player = get_player(name) if player then - client:goto(player.position, opts) + client:go_to(player.position, opts) else client:chat(string.format("/w %s player not found!", sender)) end diff --git a/lib/utils.lua b/lib/utils.lua index c0afebd..26758d3 100644 --- a/lib/utils.lua +++ b/lib/utils.lua @@ -1,6 +1,6 @@ function get_player(name) local target_uuid = nil - for _, player in client.tab_list do + for _, player in ipairs(client.tab_list) do if player.name == name then target_uuid = player.uuid break diff --git a/src/lua/client/mod.rs b/src/lua/client/mod.rs index 4b6224e..c86442b 100644 --- a/src/lua/client/mod.rs +++ b/src/lua/client/mod.rs @@ -58,7 +58,7 @@ impl UserData for Client { fn add_methods>(m: &mut M) { m.add_async_method("attack", interaction::attack); - m.add_async_method("goto", movement::goto); + 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); diff --git a/src/lua/client/movement.rs b/src/lua/client/movement.rs index e7028cc..aef4de4 100644 --- a/src/lua/client/movement.rs +++ b/src/lua/client/movement.rs @@ -22,7 +22,7 @@ pub fn eye_position(_lua: &Lua, client: &Client) -> Result { Ok(Vec3::from(client.eye_position())) } -pub async fn goto( +pub async fn go_to( lua: Lua, client: UserDataRef, (data, metadata): (Value, Option), @@ -89,7 +89,7 @@ pub async fn goto( &client, without_mining, YGoal { - y: data.as_integer().ok_or(error)?, + y: data.as_table().ok_or(error)?.get("y")?, }, ), _ => { diff --git a/src/lua/vec3.rs b/src/lua/vec3.rs index e8f0e97..d62c7d7 100644 --- a/src/lua/vec3.rs +++ b/src/lua/vec3.rs @@ -50,8 +50,8 @@ impl From for Vec3 { impl FromLua for Vec3 { fn from_lua(value: Value, _lua: &Lua) -> Result { - match value { - Value::Table(table) => Ok( + if let Value::Table(table) = value { + Ok( if let (Ok(x), Ok(y), Ok(z)) = (table.get(1), table.get(2), table.get(3)) { Self { x, y, z } } else { @@ -61,17 +61,13 @@ impl FromLua for Vec3 { z: table.get("z")?, } }, - ), - Value::Vector(vector) => Ok(Self { - x: vector.x().into(), - y: vector.y().into(), - z: vector.z().into(), - }), - _ => Err(mlua::Error::FromLuaConversionError { + ) + } else { + Err(mlua::Error::FromLuaConversionError { from: value.type_name(), to: "Vec3".to_string(), message: None, - }), + }) } } }