Compare commits
8 Commits
94d1727d87
...
main
Author | SHA1 | Date | |
---|---|---|---|
2cf4265732
|
|||
ca8c9d4d1c
|
|||
64c96450a4
|
|||
505b1a26af
|
|||
f9495a36f2
|
|||
85e1f082a7
|
|||
33838e5aed
|
|||
7cf7254dce
|
689
Cargo.lock
generated
689
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -61,8 +61,6 @@ function update_listeners()
|
|||||||
message = function()
|
message = function()
|
||||||
info("bot successfully logged in!")
|
info("bot successfully logged in!")
|
||||||
end,
|
end,
|
||||||
},
|
|
||||||
spawn = {
|
|
||||||
eat = function()
|
eat = function()
|
||||||
sleep(5000)
|
sleep(5000)
|
||||||
check_food()
|
check_food()
|
||||||
|
@@ -35,9 +35,6 @@ end
|
|||||||
function steal(item_name)
|
function steal(item_name)
|
||||||
for _, chest_pos in ipairs(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:go_to({ 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
|
|
||||||
sleep(500)
|
|
||||||
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)
|
||||||
|
@@ -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))
|
info(string.format("currently in nether, going to %.2f %.2f", nether_pos.x, nether_pos.z))
|
||||||
client:go_to(nether_pos, { type = XZ_GOAL })
|
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")
|
info("arrived, looking for nearest portal")
|
||||||
local portals_nether = client:find_blocks(client.position, portal_block_states)
|
local portals_nether = client:find_blocks(client.position, portal_block_states)
|
||||||
@@ -144,10 +141,6 @@ function interact_bed()
|
|||||||
end
|
end
|
||||||
|
|
||||||
client:go_to({ position = bed, radius = 2 }, { type = RADIUS_GOAL, options = { without_mining = true } })
|
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:look_at(bed)
|
||||||
client:block_interact(bed)
|
client:block_interact(bed)
|
||||||
end
|
end
|
||||||
|
@@ -1,11 +1,15 @@
|
|||||||
use azalea::{brigadier::prelude::*, chat::ChatPacket, prelude::*};
|
use azalea::{brigadier::prelude::*, chat::ChatPacket, prelude::*};
|
||||||
use futures::lock::Mutex;
|
use futures::lock::Mutex;
|
||||||
use mlua::{Function, Table};
|
use mlua::{Error, Result, Table, UserDataRef};
|
||||||
use ncr::utils::prepend_header;
|
use ncr::{
|
||||||
|
encoding::{Base64Encoding, Base64rEncoding, NewBase64rEncoding},
|
||||||
|
encryption::{CaesarEncryption, Cfb8Encryption, EcbEncryption, Encryption, GcmEncryption},
|
||||||
|
utils::prepend_header,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
State,
|
State, crypt,
|
||||||
lua::{eval, exec, reload},
|
lua::{eval, exec, nochatreports::key::AesKey, reload},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type Ctx = CommandContext<Mutex<CommandSource>>;
|
pub type Ctx = CommandContext<Mutex<CommandSource>>;
|
||||||
@@ -19,21 +23,26 @@ pub struct CommandSource {
|
|||||||
|
|
||||||
impl CommandSource {
|
impl CommandSource {
|
||||||
pub fn reply(&self, message: &str) {
|
pub fn reply(&self, message: &str) {
|
||||||
|
fn encrypt(options: &Table, plaintext: &str) -> Result<String> {
|
||||||
|
Ok(crypt!(encrypt, options, &prepend_header(plaintext)))
|
||||||
|
}
|
||||||
|
|
||||||
for mut chunk in message
|
for mut chunk in message
|
||||||
.chars()
|
.chars()
|
||||||
.collect::<Vec<char>>()
|
.collect::<Vec<char>>()
|
||||||
.chunks(if self.ncr_options.is_some() { 150 } else { 236 })
|
.chunks(if self.ncr_options.is_some() { 150 } else { 236 })
|
||||||
.map(|chars| chars.iter().collect::<String>())
|
.map(|chars| chars.iter().collect::<String>())
|
||||||
{
|
{
|
||||||
if let Some(options) = &self.ncr_options
|
if let Some(ciphertext) = self
|
||||||
&& let Ok(encrypt) = self.state.lua.globals().get::<Function>("ncr_encrypt")
|
.ncr_options
|
||||||
&& let Ok(ciphertext) = encrypt.call::<String>((options, prepend_header(&chunk)))
|
.as_ref()
|
||||||
|
.and_then(|options| encrypt(options, &chunk).ok())
|
||||||
{
|
{
|
||||||
chunk = ciphertext;
|
chunk = ciphertext;
|
||||||
}
|
}
|
||||||
self.client.chat(
|
self.client.chat(
|
||||||
&(if self.message.is_whisper()
|
&(if self.message.is_whisper()
|
||||||
&& let Some(username) = self.message.username()
|
&& let Some(username) = self.message.sender()
|
||||||
{
|
{
|
||||||
format!("/w {username} {chunk}")
|
format!("/w {username} {chunk}")
|
||||||
} else {
|
} else {
|
||||||
@@ -50,7 +59,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
|
|||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let source = source.lock().await;
|
let source = source.lock().await;
|
||||||
source.reply(
|
source.reply(
|
||||||
&reload(&source.state.lua, source.message.username())
|
&reload(&source.state.lua, source.message.sender())
|
||||||
.map_or_else(|error| error.to_string(), |()| String::from("ok")),
|
.map_or_else(|error| error.to_string(), |()| String::from("ok")),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -64,7 +73,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
|
|||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let source = source.lock().await;
|
let source = source.lock().await;
|
||||||
source.reply(
|
source.reply(
|
||||||
&eval(&source.state.lua, &code, source.message.username())
|
&eval(&source.state.lua, &code, source.message.sender())
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(|error| error.to_string()),
|
.unwrap_or_else(|error| error.to_string()),
|
||||||
);
|
);
|
||||||
@@ -80,7 +89,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
|
|||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let source = source.lock().await;
|
let source = source.lock().await;
|
||||||
source.reply(
|
source.reply(
|
||||||
&exec(&source.state.lua, &code, source.message.username())
|
&exec(&source.state.lua, &code, source.message.sender())
|
||||||
.await
|
.await
|
||||||
.map_or_else(|error| error.to_string(), |()| String::from("ok")),
|
.map_or_else(|error| error.to_string(), |()| String::from("ok")),
|
||||||
);
|
);
|
||||||
|
@@ -23,7 +23,7 @@ use crate::{
|
|||||||
replay::recorder::Recorder,
|
replay::recorder::Recorder,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::cognitive_complexity, clippy::too_many_lines)]
|
||||||
pub async fn handle_event(client: Client, event: Event, state: State) -> Result<()> {
|
pub async fn handle_event(client: Client, event: Event, state: State) -> Result<()> {
|
||||||
match event {
|
match event {
|
||||||
Event::AddPlayer(player_info) => {
|
Event::AddPlayer(player_info) => {
|
||||||
@@ -32,7 +32,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
|
|||||||
Event::Chat(message) => {
|
Event::Chat(message) => {
|
||||||
let globals = state.lua.globals();
|
let globals = state.lua.globals();
|
||||||
let (sender, mut content) = message.split_sender_and_content();
|
let (sender, mut content) = message.split_sender_and_content();
|
||||||
let uuid = message.uuid().map(|uuid| uuid.to_string());
|
let uuid = message.sender_uuid().map(|uuid| uuid.to_string());
|
||||||
let is_whisper = message.is_whisper();
|
let is_whisper = message.is_whisper();
|
||||||
let text = message.message();
|
let text = message.message();
|
||||||
let ansi_text = text.to_ansi();
|
let ansi_text = text.to_ansi();
|
||||||
|
@@ -108,7 +108,7 @@ pub async fn open_container_at(
|
|||||||
.map(Container))
|
.map(Container))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn open_inventory(_lua: &Lua, client: &mut Client, _: ()) -> Result<Option<Container>> {
|
pub fn open_inventory(_lua: &Lua, client: &Client, (): ()) -> Result<Option<Container>> {
|
||||||
Ok(client.open_inventory().map(Container))
|
Ok(client.open_inventory().map(Container))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,12 +8,12 @@ use mlua::{Lua, Result, UserDataRef};
|
|||||||
|
|
||||||
use super::{Client, Vec3};
|
use super::{Client, Vec3};
|
||||||
|
|
||||||
pub fn attack(_lua: &Lua, client: &mut Client, entity_id: i32) -> Result<()> {
|
pub fn attack(_lua: &Lua, client: &Client, entity_id: i32) -> Result<()> {
|
||||||
client.attack(MinecraftEntityId(entity_id));
|
client.attack(MinecraftEntityId(entity_id));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn block_interact(_lua: &Lua, client: &mut Client, position: Vec3) -> Result<()> {
|
pub fn block_interact(_lua: &Lua, client: &Client, position: Vec3) -> Result<()> {
|
||||||
#[allow(clippy::cast_possible_truncation)]
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
client.block_interact(BlockPos::new(
|
client.block_interact(BlockPos::new(
|
||||||
position.x as i32,
|
position.x as i32,
|
||||||
@@ -45,7 +45,7 @@ pub fn set_mining(_lua: &Lua, client: &Client, mining: bool) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_mining(_lua: &Lua, client: &mut Client, position: Vec3) -> Result<()> {
|
pub fn start_mining(_lua: &Lua, client: &Client, position: Vec3) -> Result<()> {
|
||||||
#[allow(clippy::cast_possible_truncation)]
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
client.start_mining(BlockPos::new(
|
client.start_mining(BlockPos::new(
|
||||||
position.x as i32,
|
position.x as i32,
|
||||||
|
@@ -41,6 +41,7 @@ impl UserData for Client {
|
|||||||
f.add_field_method_get("dimension", world::dimension);
|
f.add_field_method_get("dimension", world::dimension);
|
||||||
f.add_field_method_get("direction", movement::direction);
|
f.add_field_method_get("direction", movement::direction);
|
||||||
f.add_field_method_get("eye_position", movement::eye_position);
|
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("has_attack_cooldown", interaction::has_attack_cooldown);
|
||||||
f.add_field_method_get("health", state::health);
|
f.add_field_method_get("health", state::health);
|
||||||
f.add_field_method_get("held_item", container::held_item);
|
f.add_field_method_get("held_item", container::held_item);
|
||||||
@@ -63,33 +64,38 @@ impl UserData for Client {
|
|||||||
m.add_async_method("find_entities", world::find::entities);
|
m.add_async_method("find_entities", world::find::entities);
|
||||||
m.add_async_method("find_players", world::find::players);
|
m.add_async_method("find_players", world::find::players);
|
||||||
m.add_async_method("go_to", movement::go_to);
|
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("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);
|
||||||
m.add_async_method("set_client_information", state::set_client_information);
|
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("best_tool_for_block", world::best_tool_for_block);
|
||||||
|
m.add_method("block_interact", interaction::block_interact);
|
||||||
m.add_method("chat", chat);
|
m.add_method("chat", chat);
|
||||||
m.add_method("disconnect", disconnect);
|
m.add_method("disconnect", disconnect);
|
||||||
m.add_method("find_blocks", world::find::blocks);
|
m.add_method("find_blocks", world::find::blocks);
|
||||||
m.add_method("get_block_state", world::get_block_state);
|
m.add_method("get_block_state", world::get_block_state);
|
||||||
m.add_method("get_fluid_state", world::get_fluid_state);
|
m.add_method("get_fluid_state", world::get_fluid_state);
|
||||||
|
m.add_method("jump", movement::jump);
|
||||||
|
m.add_method("look_at", movement::look_at);
|
||||||
|
m.add_method("open_inventory", container::open_inventory);
|
||||||
m.add_method("set_component", state::set_component);
|
m.add_method("set_component", state::set_component);
|
||||||
|
m.add_method("set_direction", movement::set_direction);
|
||||||
m.add_method("set_held_slot", container::set_held_slot);
|
m.add_method("set_held_slot", container::set_held_slot);
|
||||||
|
m.add_method("set_jumping", movement::set_jumping);
|
||||||
m.add_method("set_mining", interaction::set_mining);
|
m.add_method("set_mining", interaction::set_mining);
|
||||||
m.add_method("set_position", movement::set_position);
|
m.add_method("set_position", movement::set_position);
|
||||||
m.add_method("set_sneaking", movement::set_sneaking);
|
m.add_method("set_sneaking", movement::set_sneaking);
|
||||||
|
m.add_method("sprint", movement::sprint);
|
||||||
|
m.add_method("start_mining", interaction::start_mining);
|
||||||
m.add_method("stop_pathfinding", movement::stop_pathfinding);
|
m.add_method("stop_pathfinding", movement::stop_pathfinding);
|
||||||
m.add_method("stop_sleeping", movement::stop_sleeping);
|
m.add_method("stop_sleeping", movement::stop_sleeping);
|
||||||
m.add_method("use_item", interaction::use_item);
|
m.add_method("use_item", interaction::use_item);
|
||||||
m.add_method_mut("attack", interaction::attack);
|
m.add_method("walk", movement::walk);
|
||||||
m.add_method_mut("block_interact", interaction::block_interact);
|
|
||||||
m.add_method_mut("jump", movement::jump);
|
|
||||||
m.add_method_mut("look_at", movement::look_at);
|
|
||||||
m.add_method_mut("open_inventory", container::open_inventory);
|
|
||||||
m.add_method_mut("set_direction", movement::set_direction);
|
|
||||||
m.add_method_mut("set_jumping", movement::set_jumping);
|
|
||||||
m.add_method_mut("sprint", movement::sprint);
|
|
||||||
m.add_method_mut("start_mining", interaction::start_mining);
|
|
||||||
m.add_method_mut("walk", movement::walk);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +104,7 @@ fn chat(_lua: &Lua, client: &Client, message: String) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disconnect(_lua: &Lua, client: &Client, _: ()) -> Result<()> {
|
fn disconnect(_lua: &Lua, client: &Client, (): ()) -> Result<()> {
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@@ -14,6 +14,122 @@ use mlua::{FromLua, Lua, Result, Table, UserDataRef, Value};
|
|||||||
|
|
||||||
use super::{Client, Direction, Vec3};
|
use super::{Client, Direction, Vec3};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct AnyGoal(Box<dyn Goal>);
|
||||||
|
|
||||||
|
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<AnyGoal> {
|
||||||
|
let goal: Box<dyn Goal> = 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<bool> {
|
||||||
|
Ok(client.is_goto_target_reached())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn go_to_wait_until_reached(
|
||||||
|
_lua: Lua,
|
||||||
|
client: UserDataRef<Client>,
|
||||||
|
(): (),
|
||||||
|
) -> Result<()> {
|
||||||
|
client.wait_until_goto_target_reached().await;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn go_to(
|
||||||
|
lua: Lua,
|
||||||
|
client: UserDataRef<Client>,
|
||||||
|
(data, metadata): (Table, Option<Table>),
|
||||||
|
) -> 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<Client>,
|
||||||
|
(data, metadata): (Table, Option<Table>),
|
||||||
|
) -> 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::<GotoEvent>(client.entity).is_none() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn direction(_lua: &Lua, client: &Client) -> Result<Direction> {
|
pub fn direction(_lua: &Lua, client: &Client) -> Result<Direction> {
|
||||||
let direction = client.direction();
|
let direction = client.direction();
|
||||||
Ok(Direction {
|
Ok(Direction {
|
||||||
@@ -26,78 +142,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 go_to(
|
pub fn jump(_lua: &Lua, client: &Client, (): ()) -> Result<()> {
|
||||||
lua: Lua,
|
|
||||||
client: UserDataRef<Client>,
|
|
||||||
(data, metadata): (Table, Option<Table>),
|
|
||||||
) -> Result<()> {
|
|
||||||
fn goto_with_options<G: Goal + Send + Sync + 'static>(
|
|
||||||
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::<GotoEvent>(client.entity).is_none() {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn jump(_lua: &Lua, client: &mut Client, _: ()) -> Result<()> {
|
|
||||||
client.jump();
|
client.jump();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -115,7 +160,7 @@ pub fn looking_at(lua: &Lua, client: &Client) -> Result<Option<Table>> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn look_at(_lua: &Lua, client: &mut Client, position: Vec3) -> Result<()> {
|
pub fn look_at(_lua: &Lua, client: &Client, position: Vec3) -> Result<()> {
|
||||||
client.look_at(azalea::Vec3::new(position.x, position.y, position.z));
|
client.look_at(azalea::Vec3::new(position.x, position.y, position.z));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -150,12 +195,12 @@ pub fn position(_lua: &Lua, client: &Client) -> Result<Vec3> {
|
|||||||
Ok(Vec3::from(&client.component::<Position>()))
|
Ok(Vec3::from(&client.component::<Position>()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_direction(_lua: &Lua, client: &mut Client, direction: Direction) -> Result<()> {
|
pub fn set_direction(_lua: &Lua, client: &Client, direction: Direction) -> Result<()> {
|
||||||
client.set_direction(direction.y, direction.x);
|
client.set_direction(direction.y, direction.x);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_jumping(_lua: &Lua, client: &mut Client, jumping: bool) -> Result<()> {
|
pub fn set_jumping(_lua: &Lua, client: &Client, jumping: bool) -> Result<()> {
|
||||||
client.set_jumping(jumping);
|
client.set_jumping(jumping);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -184,7 +229,7 @@ pub fn set_sneaking(_lua: &Lua, client: &Client, sneaking: bool) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sprint(_lua: &Lua, client: &mut Client, direction: u8) -> Result<()> {
|
pub fn sprint(_lua: &Lua, client: &Client, direction: u8) -> Result<()> {
|
||||||
client.sprint(match direction {
|
client.sprint(match direction {
|
||||||
5 => SprintDirection::ForwardRight,
|
5 => SprintDirection::ForwardRight,
|
||||||
6 => SprintDirection::ForwardLeft,
|
6 => SprintDirection::ForwardLeft,
|
||||||
@@ -193,12 +238,12 @@ pub fn sprint(_lua: &Lua, client: &mut Client, direction: u8) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stop_pathfinding(_lua: &Lua, client: &Client, _: ()) -> Result<()> {
|
pub fn stop_pathfinding(_lua: &Lua, client: &Client, (): ()) -> Result<()> {
|
||||||
client.stop_pathfinding();
|
client.stop_pathfinding();
|
||||||
Ok(())
|
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 {
|
if let Err(error) = client.write_packet(ServerboundPlayerCommand {
|
||||||
id: client.component::<MinecraftEntityId>(),
|
id: client.component::<MinecraftEntityId>(),
|
||||||
action: Action::StopSleeping,
|
action: Action::StopSleeping,
|
||||||
@@ -209,7 +254,7 @@ pub fn stop_sleeping(_lua: &Lua, client: &Client, _: ()) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk(_lua: &Lua, client: &mut Client, direction: u8) -> Result<()> {
|
pub fn walk(_lua: &Lua, client: &Client, direction: u8) -> Result<()> {
|
||||||
client.walk(match direction {
|
client.walk(match direction {
|
||||||
1 => WalkDirection::Forward,
|
1 => WalkDirection::Forward,
|
||||||
2 => WalkDirection::Backward,
|
2 => WalkDirection::Backward,
|
||||||
|
@@ -32,21 +32,20 @@ pub fn get_block_state(_lua: &Lua, client: &Client, position: Vec3) -> Result<Op
|
|||||||
.map(|block| block.id))
|
.map(|block| block.id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
pub fn get_fluid_state(lua: &Lua, client: &Client, position: Vec3) -> Result<Option<Table>> {
|
pub fn get_fluid_state(lua: &Lua, client: &Client, position: Vec3) -> Result<Option<Table>> {
|
||||||
#[allow(clippy::cast_possible_truncation)]
|
let fluid_state = client.world().read().get_fluid_state(&BlockPos::new(
|
||||||
Ok(
|
position.x as i32,
|
||||||
if let Some(state) = client.world().read().get_fluid_state(&BlockPos::new(
|
position.y as i32,
|
||||||
position.x as i32,
|
position.z as i32,
|
||||||
position.y as i32,
|
));
|
||||||
position.z as i32,
|
Ok(if let Some(state) = fluid_state {
|
||||||
)) {
|
let table = lua.create_table()?;
|
||||||
let table = lua.create_table()?;
|
table.set("kind", state.kind as u8)?;
|
||||||
table.set("kind", state.kind as u8)?;
|
table.set("amount", state.amount)?;
|
||||||
table.set("amount", state.amount)?;
|
table.set("falling", state.falling)?;
|
||||||
table.set("falling", state.falling)?;
|
Some(table)
|
||||||
Some(table)
|
} else {
|
||||||
} else {
|
None
|
||||||
None
|
})
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
@@ -71,9 +71,7 @@ impl UserData for ItemStack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn add_methods<M: UserDataMethods<Self>>(m: &mut M) {
|
fn add_methods<M: UserDataMethods<Self>>(m: &mut M) {
|
||||||
m.add_method_mut("split", |_, this, count: u32| {
|
m.add_method_mut("split", |_, this, count: u32| Ok(Self(this.0.split(count))));
|
||||||
Ok(ItemStack(this.0.split(count)))
|
|
||||||
});
|
|
||||||
m.add_method_mut("update_empty", |_, this, (): ()| {
|
m.add_method_mut("update_empty", |_, this, (): ()| {
|
||||||
this.0.update_empty();
|
this.0.update_empty();
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@@ -13,13 +13,15 @@ pub fn register_globals(lua: &Lua, globals: &Table, event_listeners: ListenerMap
|
|||||||
move |_, (event_type, callback, optional_id): (String, Function, Option<String>)| {
|
move |_, (event_type, callback, optional_id): (String, Function, Option<String>)| {
|
||||||
let m = m.clone();
|
let m = m.clone();
|
||||||
let id = optional_id.unwrap_or_else(|| {
|
let id = optional_id.unwrap_or_else(|| {
|
||||||
callback.info().name.unwrap_or(format!(
|
callback.info().name.unwrap_or_else(|| {
|
||||||
"anonymous @ {}",
|
format!(
|
||||||
SystemTime::now()
|
"anonymous @ {}",
|
||||||
.duration_since(UNIX_EPOCH)
|
SystemTime::now()
|
||||||
.unwrap_or_default()
|
.duration_since(UNIX_EPOCH)
|
||||||
.as_millis()
|
.unwrap_or_default()
|
||||||
))
|
.as_millis()
|
||||||
|
)
|
||||||
|
})
|
||||||
});
|
});
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
m.write()
|
m.write()
|
||||||
@@ -40,12 +42,10 @@ pub fn register_globals(lua: &Lua, globals: &Table, event_listeners: ListenerMap
|
|||||||
let m = m.clone();
|
let m = m.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let mut m = m.write().await;
|
let mut m = m.write().await;
|
||||||
let empty = if let Some(listeners) = m.get_mut(&event_type) {
|
let empty = m.get_mut(&event_type).is_some_and(|listeners| {
|
||||||
listeners.retain(|(id, _)| target_id != *id);
|
listeners.retain(|(id, _)| target_id != *id);
|
||||||
listeners.is_empty()
|
listeners.is_empty()
|
||||||
} else {
|
});
|
||||||
false
|
|
||||||
};
|
|
||||||
if empty {
|
if empty {
|
||||||
m.remove(&event_type);
|
m.remove(&event_type);
|
||||||
}
|
}
|
||||||
|
@@ -37,12 +37,7 @@ impl UserData for Room {
|
|||||||
.members(RoomMemberships::all())
|
.members(RoomMemberships::all())
|
||||||
.await
|
.await
|
||||||
.map_err(Error::external)
|
.map_err(Error::external)
|
||||||
.map(|members| {
|
.map(|members| members.into_iter().map(Member).collect::<Vec<_>>())
|
||||||
members
|
|
||||||
.into_iter()
|
|
||||||
.map(|member| Member(member.clone()))
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
m.add_async_method(
|
m.add_async_method(
|
||||||
"kick_user",
|
"kick_user",
|
||||||
|
@@ -38,12 +38,12 @@ impl Display for Error {
|
|||||||
formatter,
|
formatter,
|
||||||
"failed to {}",
|
"failed to {}",
|
||||||
match self {
|
match self {
|
||||||
Error::CreateEnv(error) => format!("create environment: {error}"),
|
Self::CreateEnv(error) => format!("create environment: {error}"),
|
||||||
Error::EvalChunk(error) => format!("evaluate chunk: {error}"),
|
Self::EvalChunk(error) => format!("evaluate chunk: {error}"),
|
||||||
Error::ExecChunk(error) => format!("execute chunk: {error}"),
|
Self::ExecChunk(error) => format!("execute chunk: {error}"),
|
||||||
Error::LoadChunk(error) => format!("load chunk: {error}"),
|
Self::LoadChunk(error) => format!("load chunk: {error}"),
|
||||||
Error::MissingPath(error) => format!("get SCRIPT_PATH global: {error}"),
|
Self::MissingPath(error) => format!("get SCRIPT_PATH global: {error}"),
|
||||||
Error::ReadFile(error) => format!("read script file: {error}"),
|
Self::ReadFile(error) => format!("read script file: {error}"),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@@ -3,9 +3,8 @@ macro_rules! crypt {
|
|||||||
($op:ident, $options:expr, $text:expr) => {{
|
($op:ident, $options:expr, $text:expr) => {{
|
||||||
macro_rules! crypt_with {
|
macro_rules! crypt_with {
|
||||||
($algo:ident) => {{
|
($algo:ident) => {{
|
||||||
let encoding = $options.get("encoding").unwrap_or_default();
|
|
||||||
let key = &$options.get::<UserDataRef<AesKey>>("key")?.0;
|
let key = &$options.get::<UserDataRef<AesKey>>("key")?.0;
|
||||||
match encoding {
|
match $options.get("encoding").unwrap_or_default() {
|
||||||
1 => $algo::<Base64Encoding>::$op($text, &key),
|
1 => $algo::<Base64Encoding>::$op($text, &key),
|
||||||
2 => $algo::<Base64rEncoding>::$op($text, &key),
|
2 => $algo::<Base64rEncoding>::$op($text, &key),
|
||||||
_ => $algo::<NewBase64rEncoding>::$op($text, &key),
|
_ => $algo::<NewBase64rEncoding>::$op($text, &key),
|
||||||
|
@@ -40,7 +40,7 @@ impl From<&Position> for Vec3 {
|
|||||||
|
|
||||||
impl From<BlockPos> for Vec3 {
|
impl From<BlockPos> for Vec3 {
|
||||||
fn from(p: BlockPos) -> Self {
|
fn from(p: BlockPos) -> Self {
|
||||||
Vec3 {
|
Self {
|
||||||
x: f64::from(p.x),
|
x: f64::from(p.x),
|
||||||
y: f64::from(p.y),
|
y: f64::from(p.y),
|
||||||
z: f64::from(p.z),
|
z: f64::from(p.z),
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
#![feature(if_let_guard, let_chains)]
|
#![feature(if_let_guard, let_chains)]
|
||||||
|
#![warn(clippy::pedantic, clippy::nursery)]
|
||||||
|
#![allow(clippy::significant_drop_tightening)]
|
||||||
|
|
||||||
mod arguments;
|
mod arguments;
|
||||||
mod build_info;
|
mod build_info;
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
use azalea::{entity::particle::Particle, registry::ParticleKind};
|
use azalea::{entity::particle::Particle, registry::ParticleKind};
|
||||||
|
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
pub fn to_kind(particle: &Particle) -> ParticleKind {
|
pub const fn to_kind(particle: &Particle) -> ParticleKind {
|
||||||
match particle {
|
match particle {
|
||||||
Particle::AngryVillager => ParticleKind::AngryVillager,
|
Particle::AngryVillager => ParticleKind::AngryVillager,
|
||||||
Particle::Block(_) => ParticleKind::Block,
|
Particle::Block(_) => ParticleKind::Block,
|
||||||
|
@@ -12,7 +12,7 @@ use azalea::{
|
|||||||
protocol::packets::login::ClientboundLoginPacket,
|
protocol::packets::login::ClientboundLoginPacket,
|
||||||
raw_connection::RawConnection,
|
raw_connection::RawConnection,
|
||||||
};
|
};
|
||||||
use bevy_app::{First, Plugin};
|
use bevy_app::{App, First, Plugin};
|
||||||
use bevy_ecs::{schedule::IntoSystemConfigs, system::ResMut};
|
use bevy_ecs::{schedule::IntoSystemConfigs, system::ResMut};
|
||||||
use log::error;
|
use log::error;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
@@ -24,8 +24,9 @@ pub struct RecordPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Plugin for RecordPlugin {
|
impl Plugin for RecordPlugin {
|
||||||
fn build(&self, app: &mut bevy_app::App) {
|
fn build(&self, app: &mut App) {
|
||||||
if let Some(recorder) = self.recorder.lock().take() {
|
let recorder = self.recorder.lock().take();
|
||||||
|
if let Some(recorder) = recorder {
|
||||||
app.insert_resource(recorder)
|
app.insert_resource(recorder)
|
||||||
.add_systems(First, record_login_packets.before(process_packet_events))
|
.add_systems(First, record_login_packets.before(process_packet_events))
|
||||||
.add_systems(First, record_configuration_packets)
|
.add_systems(First, record_configuration_packets)
|
||||||
|
Reference in New Issue
Block a user