From 505b1a26afa737e9289db5e75c951bf0f2dec78d Mon Sep 17 00:00:00 2001 From: ErrorNoInternet Date: Wed, 16 Apr 2025 01:02:55 -0400 Subject: [PATCH] build(deps)!: update azalea and refactor go_to --- Cargo.lock | 286 ++++++++++++++++++++++++++---------- lib/inventory.lua | 3 - lib/utils.lua | 7 - src/lua/client/container.rs | 2 +- src/lua/client/mod.rs | 8 +- src/lua/client/movement.rs | 193 ++++++++++++++---------- 6 files changed, 337 insertions(+), 162 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d8ac379..005157a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -166,9 +166,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.97" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f" +checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" [[package]] name = "anymap2" @@ -398,8 +398,8 @@ dependencies = [ [[package]] name = "azalea" -version = "0.11.0+mc1.21.5" -source = "git+https://github.com/azalea-rs/azalea#913d6ac8c52aa41305749e0a526f77079c84ecea" +version = "0.12.0+mc1.21.5" +source = "git+https://github.com/azalea-rs/azalea#6a83a6fa387170ae71fbe06791cf3afa20aac1df" dependencies = [ "azalea-auth", "azalea-block", @@ -436,8 +436,8 @@ dependencies = [ [[package]] name = "azalea-auth" -version = "0.11.0+mc1.21.5" -source = "git+https://github.com/azalea-rs/azalea#913d6ac8c52aa41305749e0a526f77079c84ecea" +version = "0.12.0+mc1.21.5" +source = "git+https://github.com/azalea-rs/azalea#6a83a6fa387170ae71fbe06791cf3afa20aac1df" dependencies = [ "azalea-buf", "azalea-crypto", @@ -456,8 +456,8 @@ dependencies = [ [[package]] name = "azalea-block" -version = "0.11.0+mc1.21.5" -source = "git+https://github.com/azalea-rs/azalea#913d6ac8c52aa41305749e0a526f77079c84ecea" +version = "0.12.0+mc1.21.5" +source = "git+https://github.com/azalea-rs/azalea#6a83a6fa387170ae71fbe06791cf3afa20aac1df" dependencies = [ "azalea-block-macros", "azalea-buf", @@ -466,8 +466,8 @@ dependencies = [ [[package]] name = "azalea-block-macros" -version = "0.11.0+mc1.21.5" -source = "git+https://github.com/azalea-rs/azalea#913d6ac8c52aa41305749e0a526f77079c84ecea" +version = "0.12.0+mc1.21.5" +source = "git+https://github.com/azalea-rs/azalea#6a83a6fa387170ae71fbe06791cf3afa20aac1df" dependencies = [ "proc-macro2", "quote", @@ -476,8 +476,8 @@ dependencies = [ [[package]] name = "azalea-brigadier" -version = "0.11.0+mc1.21.5" -source = "git+https://github.com/azalea-rs/azalea#913d6ac8c52aa41305749e0a526f77079c84ecea" +version = "0.12.0+mc1.21.5" +source = "git+https://github.com/azalea-rs/azalea#6a83a6fa387170ae71fbe06791cf3afa20aac1df" dependencies = [ "azalea-buf", "azalea-chat", @@ -486,8 +486,8 @@ dependencies = [ [[package]] name = "azalea-buf" -version = "0.11.0+mc1.21.5" -source = "git+https://github.com/azalea-rs/azalea#913d6ac8c52aa41305749e0a526f77079c84ecea" +version = "0.12.0+mc1.21.5" +source = "git+https://github.com/azalea-rs/azalea#6a83a6fa387170ae71fbe06791cf3afa20aac1df" dependencies = [ "azalea-buf-macros", "byteorder", @@ -500,8 +500,8 @@ dependencies = [ [[package]] name = "azalea-buf-macros" -version = "0.11.0+mc1.21.5" -source = "git+https://github.com/azalea-rs/azalea#913d6ac8c52aa41305749e0a526f77079c84ecea" +version = "0.12.0+mc1.21.5" +source = "git+https://github.com/azalea-rs/azalea#6a83a6fa387170ae71fbe06791cf3afa20aac1df" dependencies = [ "proc-macro2", "quote", @@ -510,8 +510,8 @@ dependencies = [ [[package]] name = "azalea-chat" -version = "0.11.0+mc1.21.5" -source = "git+https://github.com/azalea-rs/azalea#913d6ac8c52aa41305749e0a526f77079c84ecea" +version = "0.12.0+mc1.21.5" +source = "git+https://github.com/azalea-rs/azalea#6a83a6fa387170ae71fbe06791cf3afa20aac1df" dependencies = [ "azalea-buf", "azalea-language", @@ -524,8 +524,8 @@ dependencies = [ [[package]] name = "azalea-client" -version = "0.11.0+mc1.21.5" -source = "git+https://github.com/azalea-rs/azalea#913d6ac8c52aa41305749e0a526f77079c84ecea" +version = "0.12.0+mc1.21.5" +source = "git+https://github.com/azalea-rs/azalea#6a83a6fa387170ae71fbe06791cf3afa20aac1df" dependencies = [ "azalea-auth", "azalea-block", @@ -559,8 +559,8 @@ dependencies = [ [[package]] name = "azalea-core" -version = "0.11.0+mc1.21.5" -source = "git+https://github.com/azalea-rs/azalea#913d6ac8c52aa41305749e0a526f77079c84ecea" +version = "0.12.0+mc1.21.5" +source = "git+https://github.com/azalea-rs/azalea#6a83a6fa387170ae71fbe06791cf3afa20aac1df" dependencies = [ "azalea-buf", "azalea-chat", @@ -576,8 +576,8 @@ dependencies = [ [[package]] name = "azalea-crypto" -version = "0.11.0+mc1.21.5" -source = "git+https://github.com/azalea-rs/azalea#913d6ac8c52aa41305749e0a526f77079c84ecea" +version = "0.12.0+mc1.21.5" +source = "git+https://github.com/azalea-rs/azalea#6a83a6fa387170ae71fbe06791cf3afa20aac1df" dependencies = [ "aes", "azalea-buf", @@ -593,8 +593,8 @@ dependencies = [ [[package]] name = "azalea-entity" -version = "0.11.0+mc1.21.5" -source = "git+https://github.com/azalea-rs/azalea#913d6ac8c52aa41305749e0a526f77079c84ecea" +version = "0.12.0+mc1.21.5" +source = "git+https://github.com/azalea-rs/azalea#6a83a6fa387170ae71fbe06791cf3afa20aac1df" dependencies = [ "azalea-block", "azalea-buf", @@ -617,8 +617,8 @@ dependencies = [ [[package]] name = "azalea-inventory" -version = "0.11.0+mc1.21.5" -source = "git+https://github.com/azalea-rs/azalea#913d6ac8c52aa41305749e0a526f77079c84ecea" +version = "0.12.0+mc1.21.5" +source = "git+https://github.com/azalea-rs/azalea#6a83a6fa387170ae71fbe06791cf3afa20aac1df" dependencies = [ "azalea-buf", "azalea-chat", @@ -633,8 +633,8 @@ dependencies = [ [[package]] name = "azalea-inventory-macros" -version = "0.11.0+mc1.21.5" -source = "git+https://github.com/azalea-rs/azalea#913d6ac8c52aa41305749e0a526f77079c84ecea" +version = "0.12.0+mc1.21.5" +source = "git+https://github.com/azalea-rs/azalea#6a83a6fa387170ae71fbe06791cf3afa20aac1df" dependencies = [ "proc-macro2", "quote", @@ -643,8 +643,8 @@ dependencies = [ [[package]] name = "azalea-language" -version = "0.11.0+mc1.21.5" -source = "git+https://github.com/azalea-rs/azalea#913d6ac8c52aa41305749e0a526f77079c84ecea" +version = "0.12.0+mc1.21.5" +source = "git+https://github.com/azalea-rs/azalea#6a83a6fa387170ae71fbe06791cf3afa20aac1df" dependencies = [ "compact_str", "serde", @@ -653,8 +653,8 @@ dependencies = [ [[package]] name = "azalea-physics" -version = "0.11.0+mc1.21.5" -source = "git+https://github.com/azalea-rs/azalea#913d6ac8c52aa41305749e0a526f77079c84ecea" +version = "0.12.0+mc1.21.5" +source = "git+https://github.com/azalea-rs/azalea#6a83a6fa387170ae71fbe06791cf3afa20aac1df" dependencies = [ "azalea-block", "azalea-core", @@ -670,8 +670,8 @@ dependencies = [ [[package]] name = "azalea-protocol" -version = "0.11.0+mc1.21.5" -source = "git+https://github.com/azalea-rs/azalea#913d6ac8c52aa41305749e0a526f77079c84ecea" +version = "0.12.0+mc1.21.5" +source = "git+https://github.com/azalea-rs/azalea#6a83a6fa387170ae71fbe06791cf3afa20aac1df" dependencies = [ "async-recursion", "azalea-auth", @@ -705,8 +705,8 @@ dependencies = [ [[package]] name = "azalea-protocol-macros" -version = "0.11.0+mc1.21.5" -source = "git+https://github.com/azalea-rs/azalea#913d6ac8c52aa41305749e0a526f77079c84ecea" +version = "0.12.0+mc1.21.5" +source = "git+https://github.com/azalea-rs/azalea#6a83a6fa387170ae71fbe06791cf3afa20aac1df" dependencies = [ "proc-macro2", "quote", @@ -715,8 +715,8 @@ dependencies = [ [[package]] name = "azalea-registry" -version = "0.11.0+mc1.21.5" -source = "git+https://github.com/azalea-rs/azalea#913d6ac8c52aa41305749e0a526f77079c84ecea" +version = "0.12.0+mc1.21.5" +source = "git+https://github.com/azalea-rs/azalea#6a83a6fa387170ae71fbe06791cf3afa20aac1df" dependencies = [ "azalea-buf", "azalea-registry-macros", @@ -726,8 +726,8 @@ dependencies = [ [[package]] name = "azalea-registry-macros" -version = "0.11.0+mc1.21.5" -source = "git+https://github.com/azalea-rs/azalea#913d6ac8c52aa41305749e0a526f77079c84ecea" +version = "0.12.0+mc1.21.5" +source = "git+https://github.com/azalea-rs/azalea#6a83a6fa387170ae71fbe06791cf3afa20aac1df" dependencies = [ "quote", "syn", @@ -735,8 +735,8 @@ dependencies = [ [[package]] name = "azalea-world" -version = "0.11.0+mc1.21.5" -source = "git+https://github.com/azalea-rs/azalea#913d6ac8c52aa41305749e0a526f77079c84ecea" +version = "0.12.0+mc1.21.5" +source = "git+https://github.com/azalea-rs/azalea#6a83a6fa387170ae71fbe06791cf3afa20aac1df" dependencies = [ "azalea-block", "azalea-buf", @@ -1265,9 +1265,9 @@ checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" [[package]] name = "compact_str" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b79c4069c6cad78e2e0cdfcbd26275770669fb39fd308a752dc110e83b9af32" +checksum = "3fdb1325a1cece981e8a296ab8f0f9b63ae357bd0784a9faaf548cc7b480707a" dependencies = [ "castaway", "cfg-if", @@ -1408,6 +1408,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "critical-section" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" + [[package]] name = "crossbeam-channel" version = "0.5.15" @@ -1417,6 +1423,15 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.21" @@ -2046,6 +2061,19 @@ dependencies = [ "slab", ] +[[package]] +name = "generator" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc6bd114ceda131d3b1d665eba35788690ad37f5916457286b32ab6fd3c438dd" +dependencies = [ + "cfg-if", + "libc", + "log", + "rustversion", + "windows", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -2157,9 +2185,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5017294ff4bb30944501348f6f8e42e6ad28f42c8bbef7a74029aff064a4e3c2" +checksum = "75249d144030531f8dee69fe9cea04d3edf809a017ae445e2abdff6629e86633" dependencies = [ "atomic-waker", "bytes", @@ -2236,12 +2264,14 @@ checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "hickory-proto" -version = "0.24.4" +version = "0.25.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92652067c9ce6f66ce53cc38d1169daa36e6e7eb7dd3b63b5103bd9d97117248" +checksum = "6d844af74f7b799e41c78221be863bade11c430d46042c3b49ca8ae0c6d27287" dependencies = [ + "async-recursion", "async-trait", "cfg-if", + "critical-section", "data-encoding", "enum-as-inner", "futures-channel", @@ -2250,8 +2280,9 @@ dependencies = [ "idna", "ipnet", "once_cell", - "rand 0.8.5", - "thiserror 1.0.69", + "rand 0.9.0", + "ring", + "thiserror 2.0.12", "tinyvec", "tokio", "tracing", @@ -2260,19 +2291,19 @@ dependencies = [ [[package]] name = "hickory-resolver" -version = "0.24.4" +version = "0.25.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbb117a1ca520e111743ab2f6688eddee69db4e0ea242545a604dce8a66fd22e" +checksum = "a128410b38d6f931fcc6ca5c107a3b02cabd6c05967841269a4ad65d23c44331" dependencies = [ "cfg-if", "futures-util", "hickory-proto", - "lru-cache", + "moka", "once_cell", "parking_lot", - "rand 0.8.5", + "rand 0.9.0", "smallvec", - "thiserror 1.0.69", + "thiserror 2.0.12", "tokio", "tracing", ] @@ -2447,7 +2478,7 @@ dependencies = [ "js-sys", "log", "wasm-bindgen", - "windows-core", + "windows-core 0.61.0", ] [[package]] @@ -2809,9 +2840,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.171" +version = "0.2.172" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" +checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" [[package]] name = "libgit2-sys" @@ -2892,12 +2923,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "linked-hash-map" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" - [[package]] name = "linux-raw-sys" version = "0.9.4" @@ -2927,12 +2952,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" [[package]] -name = "lru-cache" -version = "0.1.2" +name = "loom" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c" +checksum = "419e0dc8046cb947daa77eb95ae174acfbddb7673b4151f56d1eed8e93fbfaca" dependencies = [ - "linked-hash-map", + "cfg-if", + "generator", + "scoped-tls", + "tracing", + "tracing-subscriber", ] [[package]] @@ -3343,6 +3372,25 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "moka" +version = "0.12.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9321642ca94a4282428e6ea4af8cc2ca4eac48ac7a6a4ea8f33f76d0ce70926" +dependencies = [ + "crossbeam-channel", + "crossbeam-epoch", + "crossbeam-utils", + "loom", + "parking_lot", + "portable-atomic", + "rustc_version", + "smallvec", + "tagptr", + "thiserror 1.0.69", + "uuid", +] + [[package]] name = "native-tls" version = "0.2.14" @@ -3573,6 +3621,10 @@ name = "once_cell" version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +dependencies = [ + "critical-section", + "portable-atomic", +] [[package]] name = "opaque-debug" @@ -3806,6 +3858,12 @@ dependencies = [ "universal-hash", ] +[[package]] +name = "portable-atomic" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e" + [[package]] name = "powerfmt" version = "0.2.0" @@ -3863,9 +3921,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.94" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" dependencies = [ "unicode-ident", ] @@ -4493,6 +4551,12 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + [[package]] name = "scopeguard" version = "1.2.0" @@ -4869,6 +4933,12 @@ dependencies = [ "syn", ] +[[package]] +name = "tagptr" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417" + [[package]] name = "tempfile" version = "3.19.1" @@ -5611,19 +5681,53 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" +dependencies = [ + "windows-core 0.58.0", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-core" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" +dependencies = [ + "windows-implement 0.58.0", + "windows-interface 0.58.0", + "windows-result 0.2.0", + "windows-strings 0.1.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows-core" version = "0.61.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4763c1de310c86d75a878046489e2e5ba02c649d185f21c67d4cf8a56d098980" dependencies = [ - "windows-implement", - "windows-interface", + "windows-implement 0.60.0", + "windows-interface 0.59.1", "windows-link", - "windows-result", + "windows-result 0.3.2", "windows-strings 0.4.0", ] +[[package]] +name = "windows-implement" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "windows-implement" version = "0.60.0" @@ -5635,6 +5739,17 @@ dependencies = [ "syn", ] +[[package]] +name = "windows-interface" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "windows-interface" version = "0.59.1" @@ -5658,11 +5773,20 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4286ad90ddb45071efd1a66dfa43eb02dd0dfbae1545ad6cc3c51cf34d7e8ba3" dependencies = [ - "windows-result", + "windows-result 0.3.2", "windows-strings 0.3.1", "windows-targets 0.53.0", ] +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-result" version = "0.3.2" @@ -5672,6 +5796,16 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result 0.2.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows-strings" version = "0.3.1" diff --git a/lib/inventory.lua b/lib/inventory.lua index bfa6ff8..8ac6989 100644 --- a/lib/inventory.lua +++ b/lib/inventory.lua @@ -35,9 +35,6 @@ end function steal(item_name) for _, chest_pos in ipairs(client:find_blocks(client.position, get_block_states({ "chest" }))) do client:go_to({ position = chest_pos, radius = 3 }, { type = RADIUS_GOAL }) - while client.pathfinder.is_calculating or client.pathfinder.is_executing do - sleep(500) - end client:look_at(chest_pos) local container = client:open_container_at(chest_pos) diff --git a/lib/utils.lua b/lib/utils.lua index 3d16f46..c091f76 100644 --- a/lib/utils.lua +++ b/lib/utils.lua @@ -93,9 +93,6 @@ function nether_travel(pos, go_to_opts) info(string.format("currently in nether, going to %.2f %.2f", nether_pos.x, nether_pos.z)) client:go_to(nether_pos, { type = XZ_GOAL }) - while client.pathfinder.is_calculating or client.pathfinder.is_executing do - sleep(1000) - end info("arrived, looking for nearest portal") local portals_nether = client:find_blocks(client.position, portal_block_states) @@ -144,10 +141,6 @@ function interact_bed() end client:go_to({ position = bed, radius = 2 }, { type = RADIUS_GOAL, options = { without_mining = true } }) - while client.pathfinder.is_calculating or client.pathfinder.is_executing do - sleep(500) - end - client:look_at(bed) client:block_interact(bed) end diff --git a/src/lua/client/container.rs b/src/lua/client/container.rs index fb1953e..6b1e64e 100644 --- a/src/lua/client/container.rs +++ b/src/lua/client/container.rs @@ -108,7 +108,7 @@ pub async fn open_container_at( .map(Container)) } -pub fn open_inventory(_lua: &Lua, client: &Client, _: ()) -> Result> { +pub fn open_inventory(_lua: &Lua, client: &Client, (): ()) -> Result> { Ok(client.open_inventory().map(Container)) } diff --git a/src/lua/client/mod.rs b/src/lua/client/mod.rs index 285724a..8ef6f27 100644 --- a/src/lua/client/mod.rs +++ b/src/lua/client/mod.rs @@ -41,6 +41,7 @@ impl UserData for Client { f.add_field_method_get("dimension", world::dimension); f.add_field_method_get("direction", movement::direction); f.add_field_method_get("eye_position", movement::eye_position); + f.add_field_method_get("go_to_reached", movement::go_to_reached); f.add_field_method_get("has_attack_cooldown", interaction::has_attack_cooldown); f.add_field_method_get("health", state::health); f.add_field_method_get("held_item", container::held_item); @@ -63,9 +64,14 @@ impl UserData for Client { 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( + "go_to_wait_until_reached", + movement::go_to_wait_until_reached, + ); 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); + m.add_async_method("start_go_to", movement::start_go_to); m.add_method("attack", interaction::attack); m.add_method("best_tool_for_block", world::best_tool_for_block); m.add_method("block_interact", interaction::block_interact); @@ -98,7 +104,7 @@ fn chat(_lua: &Lua, client: &Client, message: String) -> Result<()> { Ok(()) } -fn disconnect(_lua: &Lua, client: &Client, _: ()) -> Result<()> { +fn disconnect(_lua: &Lua, client: &Client, (): ()) -> Result<()> { client.disconnect(); Ok(()) } diff --git a/src/lua/client/movement.rs b/src/lua/client/movement.rs index 7340b8a..ded0b62 100644 --- a/src/lua/client/movement.rs +++ b/src/lua/client/movement.rs @@ -14,6 +14,122 @@ use mlua::{FromLua, Lua, Result, Table, UserDataRef, Value}; use super::{Client, Direction, Vec3}; +#[derive(Debug)] +struct AnyGoal(Box); + +impl Goal for AnyGoal { + fn success(&self, n: BlockPos) -> bool { + self.0.success(n) + } + + fn heuristic(&self, n: BlockPos) -> f32 { + self.0.heuristic(n) + } +} + +#[allow(clippy::cast_possible_truncation)] +fn to_goal(lua: &Lua, client: &Client, data: Table, options: &Table, kind: u8) -> Result { + let goal: Box = match kind { + 1 => { + let pos = Vec3::from_lua(data.get("position")?, lua)?; + Box::new(RadiusGoal { + pos: azalea::Vec3::new(pos.x, pos.y, pos.z), + radius: data.get("radius")?, + }) + } + 2 => { + let pos = Vec3::from_lua(Value::Table(data), lua)?; + Box::new(ReachBlockPosGoal { + pos: BlockPos::new(pos.x as i32, pos.y as i32, pos.z as i32), + chunk_storage: client.world().read().chunks.clone(), + }) + } + 3 => Box::new(XZGoal { + x: data.get("x")?, + z: data.get("z")?, + }), + 4 => Box::new(YGoal { y: data.get("y")? }), + _ => { + let pos = Vec3::from_lua(Value::Table(data), lua)?; + Box::new(BlockPosGoal(BlockPos::new( + pos.x as i32, + pos.y as i32, + pos.z as i32, + ))) + } + }; + + Ok(AnyGoal(if options.get("inverse").unwrap_or_default() { + Box::new(InverseGoal(AnyGoal(goal))) + } else { + goal + })) +} + +pub fn go_to_reached(_lua: &Lua, client: &Client) -> Result { + Ok(client.is_goto_target_reached()) +} + +pub async fn go_to_wait_until_reached( + _lua: Lua, + client: UserDataRef, + (): (), +) -> Result<()> { + client.wait_until_goto_target_reached().await; + Ok(()) +} + +pub async fn go_to( + lua: Lua, + client: UserDataRef, + (data, metadata): (Table, Option), +) -> Result<()> { + let metadata = metadata.unwrap_or(lua.create_table()?); + let options = metadata.get("options").unwrap_or(lua.create_table()?); + let goal = to_goal( + &lua, + &client, + data, + &options, + metadata.get("type").unwrap_or_default(), + )?; + if options.get("without_mining").unwrap_or_default() { + client.start_goto_without_mining(goal); + client.wait_until_goto_target_reached().await; + } else { + client.goto(goal).await; + } + Ok(()) +} + +pub async fn start_go_to( + lua: Lua, + client: UserDataRef, + (data, metadata): (Table, Option
), +) -> Result<()> { + let metadata = metadata.unwrap_or(lua.create_table()?); + let options = metadata.get("options").unwrap_or(lua.create_table()?); + let goal = to_goal( + &lua, + &client, + data, + &options, + metadata.get("type").unwrap_or_default(), + )?; + if options.get("without_mining").unwrap_or_default() { + client.start_goto_without_mining(goal); + } else { + client.start_goto(goal); + } + while client.get_tick_broadcaster().recv().await.is_ok() { + if client.ecs.lock().get::(client.entity).is_none() { + break; + } + } + + Ok(()) +} + pub fn direction(_lua: &Lua, client: &Client) -> Result { let direction = client.direction(); Ok(Direction { @@ -26,78 +142,7 @@ pub fn eye_position(_lua: &Lua, client: &Client) -> Result { Ok(Vec3::from(client.eye_position())) } -pub async fn go_to( - lua: Lua, - client: UserDataRef, - (data, metadata): (Table, Option
), -) -> Result<()> { - fn goto_with_options( - client: &Client, - options: &Table, - goal: G, - ) { - if options.get("without_mining").unwrap_or_default() { - client.goto_without_mining(goal); - } else { - client.goto(goal); - } - } - - let table = metadata.unwrap_or(lua.create_table()?); - let goal_type = table.get("type").unwrap_or_default(); - let options = table.get("options").unwrap_or(lua.create_table()?); - - macro_rules! goto { - ($goal:expr) => { - if options.get("inverse").unwrap_or_default() { - goto_with_options(&client, &options, InverseGoal($goal)); - } else { - goto_with_options(&client, &options, $goal); - } - }; - } - - #[allow(clippy::cast_possible_truncation)] - match goal_type { - 1 => { - let p = Vec3::from_lua(data.get("position")?, &lua)?; - goto!(RadiusGoal { - pos: azalea::Vec3::new(p.x, p.y, p.z), - radius: data.get("radius")?, - }); - } - 2 => { - let p = Vec3::from_lua(Value::Table(data), &lua)?; - goto!(ReachBlockPosGoal { - pos: BlockPos::new(p.x as i32, p.y as i32, p.z as i32), - chunk_storage: client.world().read().chunks.clone(), - }); - } - 3 => { - goto!(XZGoal { - x: data.get("x")?, - z: data.get("z")?, - }); - } - 4 => goto!(YGoal { y: data.get("y")? }), - _ => { - let p = Vec3::from_lua(Value::Table(data), &lua)?; - goto!(BlockPosGoal(BlockPos::new( - p.x as i32, p.y as i32, p.z as i32 - ))); - } - } - - while client.get_tick_broadcaster().recv().await.is_ok() { - if client.ecs.lock().get::(client.entity).is_none() { - break; - } - } - - Ok(()) -} - -pub fn jump(_lua: &Lua, client: &Client, _: ()) -> Result<()> { +pub fn jump(_lua: &Lua, client: &Client, (): ()) -> Result<()> { client.jump(); Ok(()) } @@ -193,12 +238,12 @@ pub fn sprint(_lua: &Lua, client: &Client, direction: u8) -> Result<()> { Ok(()) } -pub fn stop_pathfinding(_lua: &Lua, client: &Client, _: ()) -> Result<()> { +pub fn stop_pathfinding(_lua: &Lua, client: &Client, (): ()) -> Result<()> { client.stop_pathfinding(); Ok(()) } -pub fn stop_sleeping(_lua: &Lua, client: &Client, _: ()) -> Result<()> { +pub fn stop_sleeping(_lua: &Lua, client: &Client, (): ()) -> Result<()> { if let Err(error) = client.write_packet(ServerboundPlayerCommand { id: client.component::(), action: Action::StopSleeping,