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",
]
[[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",
]

View File

@ -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"] }

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -58,7 +58,7 @@ impl UserData for Client {
fn add_methods<M: UserDataMethods<Self>>(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);

View File

@ -22,7 +22,7 @@ pub fn eye_position(_lua: &Lua, client: &Client) -> Result<Vec3> {
Ok(Vec3::from(client.eye_position()))
}
pub async fn goto(
pub async fn go_to(
lua: Lua,
client: UserDataRef<Client>,
(data, metadata): (Value, Option<Table>),
@ -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")?,
},
),
_ => {

View File

@ -50,8 +50,8 @@ impl From<BlockPos> for Vec3 {
impl FromLua for Vec3 {
fn from_lua(value: Value, _lua: &Lua) -> Result<Self> {
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,
}),
})
}
}
}