feat: switch to luajit for more features

This commit is contained in:
Ryan 2025-02-23 02:49:35 -05:00
parent b1dbfa6110
commit 168ac1bb46
Signed by: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3
10 changed files with 48 additions and 65 deletions

11
Cargo.lock generated
View File

@ -1825,15 +1825,6 @@ dependencies = [
"linked-hash-map", "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]] [[package]]
name = "matchers" name = "matchers"
version = "0.1.0" version = "0.1.0"
@ -1906,7 +1897,6 @@ dependencies = [
"bstr", "bstr",
"either", "either",
"futures-util", "futures-util",
"libloading",
"mlua-sys", "mlua-sys",
"num-traits", "num-traits",
"parking_lot", "parking_lot",
@ -1921,7 +1911,6 @@ checksum = "1901c1a635a22fe9250ffcc4fcc937c16b47c2e9e71adba8784af8bca1f69594"
dependencies = [ dependencies = [
"cc", "cc",
"cfg-if", "cfg-if",
"luau0-src",
"pkg-config", "pkg-config",
] ]

View File

@ -25,5 +25,5 @@ http-body-util = "0"
hyper = { version = "1", features = ["server"] } hyper = { version = "1", features = ["server"] }
hyper-util = "0" hyper-util = "0"
log = { version = "0" } log = { version = "0" }
mlua = { version = "0", features = ["async", "luau-jit", "send"] } mlua = { version = "0", features = ["async", "luajit", "send"] }
tokio = { version = "1", features = ["macros"] } tokio = { version = "1", features = ["macros"] }

View File

@ -2,15 +2,13 @@ Server = "localhost"
Username = "ErrorNoWatcher" Username = "ErrorNoWatcher"
Owners = { "ErrorNoInternet" } Owners = { "ErrorNoInternet" }
for _, module in for _, module in ipairs({
{
"enum", "enum",
"events", "events",
"inventory", "inventory",
"movement", "movement",
"utils", "utils",
} }) do
do
module = "lib/" .. module module = "lib/" .. module
package.loaded[module] = nil package.loaded[module] = nil
require(module) require(module)

View File

@ -9,7 +9,7 @@ function log_player_positions()
and e.position.z > center.z - radius and e.position.z > center.z - radius
and e.position.z < center.z + radius and e.position.z < center.z + radius
end) 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)) 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
end end

View File

@ -1,17 +1,17 @@
function steal(item_name) function steal(item_name)
for _, chest_pos in client:find_blocks(client.position, get_block_states({ "chest" })) do for _, chest_pos in ipairs(client:find_blocks(client.position, get_block_states({ "chest" }))) do
client:chat(dump(chest_pos)) client:chat(dump(chest_pos))
client:goto({ position = chest_pos, radius = 3 }, { type = RADIUS_GOAL }) client:go_to({ position = chest_pos, radius = 3 }, { type = RADIUS_GOAL })
while client.pathfinder.is_calculating or client.pathfinder.is_executing do while client.pathfinder.is_calculating or client.pathfinder.is_executing do
sleep(50) sleep(50)
end end
client:look_at(chest_pos) client:look_at(chest_pos)
local container = client:open_container_at(chest_pos) local container = client:open_container_at(chest_pos)
for index, item in container.contents do for index, item in ipairs(container.contents) do
if item.kind == item_name then if item.kind == item_name then
container:click({slot = index - 1}, THROW_ALL) container:click({ slot = index - 1 }, THROW_ALL)
sleep(50) sleep(50)
end end
end end
@ -26,13 +26,13 @@ end
function drop_all_hotbar() function drop_all_hotbar()
local inventory = client:open_inventory() local inventory = client:open_inventory()
for i = 0, 9 do for i = 0, 9 do
inventory:click({slot = 36 + i}, THROW_ALL) inventory:click({ slot = 36 + i }, THROW_ALL)
end end
end end
function drop_all_inventory() function drop_all_inventory()
local inventory = client:open_inventory() local inventory = client:open_inventory()
for i = 0, 45 do for i = 0, 45 do
inventory:click({slot = i}, THROW_ALL) inventory:click({ slot = i }, THROW_ALL)
end end
end end

View File

@ -8,10 +8,10 @@ function look_at_player(name)
end end
end end
function goto_player(name, opts) function go_to_player(name, opts)
local player = get_player(name) local player = get_player(name)
if player then if player then
client:goto(player.position, opts) client:go_to(player.position, opts)
else else
client:chat(string.format("/w %s player not found!", sender)) client:chat(string.format("/w %s player not found!", sender))
end end

View File

@ -1,6 +1,6 @@
function get_player(name) function get_player(name)
local target_uuid = nil local target_uuid = nil
for _, player in client.tab_list do for _, player in ipairs(client.tab_list) do
if player.name == name then if player.name == name then
target_uuid = player.uuid target_uuid = player.uuid
break break

View File

@ -58,7 +58,7 @@ impl UserData for Client {
fn add_methods<M: UserDataMethods<Self>>(m: &mut M) { fn add_methods<M: UserDataMethods<Self>>(m: &mut M) {
m.add_async_method("attack", interaction::attack); 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("look_at", movement::look_at);
m.add_async_method("mine", interaction::mine); m.add_async_method("mine", interaction::mine);
m.add_async_method("open_container_at", container::open_container_at); m.add_async_method("open_container_at", container::open_container_at);

View File

@ -22,7 +22,7 @@ pub fn eye_position(_lua: &Lua, client: &Client) -> Result<Vec3> {
Ok(Vec3::from(client.eye_position())) Ok(Vec3::from(client.eye_position()))
} }
pub async fn goto( pub async fn go_to(
lua: Lua, lua: Lua,
client: UserDataRef<Client>, client: UserDataRef<Client>,
(data, metadata): (Value, Option<Table>), (data, metadata): (Value, Option<Table>),
@ -89,7 +89,7 @@ pub async fn goto(
&client, &client,
without_mining, without_mining,
YGoal { YGoal {
y: data.as_integer().ok_or(error)?, y: data.as_table().ok_or(error)?.get("y")?,
}, },
), ),
_ => { _ => {

View File

@ -50,8 +50,8 @@ impl From<BlockPos> for Vec3 {
impl FromLua for Vec3 { impl FromLua for Vec3 {
fn from_lua(value: Value, _lua: &Lua) -> Result<Self> { fn from_lua(value: Value, _lua: &Lua) -> Result<Self> {
match value { if let Value::Table(table) = value {
Value::Table(table) => Ok( Ok(
if let (Ok(x), Ok(y), Ok(z)) = (table.get(1), table.get(2), table.get(3)) { if let (Ok(x), Ok(y), Ok(z)) = (table.get(1), table.get(2), table.get(3)) {
Self { x, y, z } Self { x, y, z }
} else { } else {
@ -61,17 +61,13 @@ impl FromLua for Vec3 {
z: table.get("z")?, z: table.get("z")?,
} }
}, },
), )
Value::Vector(vector) => Ok(Self { } else {
x: vector.x().into(), Err(mlua::Error::FromLuaConversionError {
y: vector.y().into(),
z: vector.z().into(),
}),
_ => Err(mlua::Error::FromLuaConversionError {
from: value.type_name(), from: value.type_name(),
to: "Vec3".to_string(), to: "Vec3".to_string(),
message: None, message: None,
}), })
} }
} }
} }