From 4036be8cc131515480a6503fa473e798da780913 Mon Sep 17 00:00:00 2001 From: MeexReay Date: Wed, 7 May 2025 14:22:43 +0300 Subject: [PATCH] fancy animation --- src/data/text_component.rs | 4 +++- src/play/mod.rs | 29 ++++++++++++++++------------- src/play/planner.rs | 1 + 3 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 src/play/planner.rs diff --git a/src/data/text_component.rs b/src/data/text_component.rs index d08264b..71ffee9 100644 --- a/src/data/text_component.rs +++ b/src/data/text_component.rs @@ -58,7 +58,9 @@ impl TextComponent { .collect::>(); let mut parent = children[0].clone(); - parent.extra = Some(children[1..].to_vec()); + if children.len() > 1 { + parent.extra = Some(children[1..].to_vec()); + } parent } diff --git a/src/play/mod.rs b/src/play/mod.rs index 597c21e..6f65792 100644 --- a/src/play/mod.rs +++ b/src/play/mod.rs @@ -16,6 +16,7 @@ use crate::protocol::{ConnectionState, packet_id::*}; pub mod config; pub mod helper; +pub mod planner; pub struct PlayHandler; @@ -194,13 +195,13 @@ pub fn handle_play_state( }); send_login(client.clone())?; - sync_player_pos(client.clone(), 8.0, 3.0, 8.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0)?; // idk why, but now you need to set y to 3 here + sync_player_pos(client.clone(), 8.0, 0.0, 8.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0)?; // idk why, but now you need to set y to 3 here send_game_event(client.clone(), 13, 0.0)?; // 13 - Start waiting for level chunks set_center_chunk(client.clone(), 0, 0)?; let mut chunks = Vec::new(); - let view_distance = client.client_info().unwrap().view_distance as i32; + let view_distance = client.client_info().unwrap().view_distance as i32 / 2; send_example_chunks_in_distance(client.clone(), &mut chunks, view_distance, (0, 0))?; @@ -272,19 +273,21 @@ pub fn handle_play_state( view_distance, (chunk_x, chunk_z), )?; - - // send_system_message( - // client.clone(), - // TextComponent::rainbow(format!("Pos: {} {} {}", x as i64, y as i64, z as i64)), - // false, - // )?; } - send_system_message( - client.clone(), - TextComponent::rainbow(format!("Ticks alive: {}", ticks_alive)), - true, - )?; + // text animation + { + let animation_text = format!("Ticks alive: {} жёпа", ticks_alive); + let animation_index = ((ticks_alive + 40) % 300) as usize; + let animation_end = animation_text.len() + 20; + + if animation_index < animation_end { + let now_length = (animation_index + 1).min(animation_text.chars().count()); + let now_text = animation_text.chars().take(now_length).collect(); + + send_system_message(client.clone(), TextComponent::rainbow(now_text), true)?; + } + } thread::sleep(Duration::from_millis(50)); // 1 tick ticks_alive += 1; diff --git a/src/play/planner.rs b/src/play/planner.rs new file mode 100644 index 0000000..f8d4701 --- /dev/null +++ b/src/play/planner.rs @@ -0,0 +1 @@ +// TODO: thread-safe planner like BukkitScheduler