diff --git a/src/data/component.rs b/src/data/component.rs index 71ffee9..1eab4d9 100644 --- a/src/data/component.rs +++ b/src/data/component.rs @@ -37,6 +37,35 @@ impl TextComponent { } } + pub fn rainbow_offset(text: String, offset: i64) -> TextComponent { + if text.is_empty() { + return TextComponent::new(text); + } + + let children = text + .char_indices() + .map(|(i, c)| { + let hue = (((i as i64 + offset) % text.chars().count() as i64) as f32) + / (text.chars().count() as f32) + * 360.0; + let hsl = Hsl::new(hue, 1.0, 0.5); + let rgb: Srgb = hsl.into_color(); + let r = (rgb.red * 255.0).round() as u8; + let g = (rgb.green * 255.0).round() as u8; + let b = (rgb.blue * 255.0).round() as u8; + let mut component = TextComponent::new(c.to_string()); + component.color = Some(format!("#{:02X}{:02X}{:02X}", r, g, b)); + component + }) + .collect::>(); + + let mut parent = children[0].clone(); + if children.len() > 1 { + parent.extra = Some(children[1..].to_vec()); + } + parent + } + pub fn rainbow(text: String) -> TextComponent { if text.is_empty() { return TextComponent::new(text); diff --git a/src/play/mod.rs b/src/play/mod.rs index 3f8f023..5121b99 100644 --- a/src/play/mod.rs +++ b/src/play/mod.rs @@ -334,6 +334,7 @@ pub fn handle_play_state( } send_player(client.clone(), player.clone())?; send_player(player.clone(), client.clone())?; + send_rainbow_message(&client, format!("{} joined the game", player_name))?; } thread::spawn({ @@ -353,11 +354,11 @@ pub fn handle_play_state( match packet.id() { serverbound::play::CLICK_CONTAINER => { - let window_id = packet.read_varint()?; - let state_id = packet.read_varint()?; - let slot = packet.read_short()?; - let button = packet.read_byte()?; - let mode = packet.read_varint()?; + let _ = packet.read_varint()?; // window id + let _ = packet.read_varint()?; // state id + let slot = packet.read_short()?; // slot + let _ = packet.read_byte()?; // button + let _ = packet.read_varint()?; // mode // i cannot read item slots now send_rainbow_message(&client, format!("index clicked: {slot}"))?; @@ -514,15 +515,22 @@ pub fn handle_play_state( // 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 ticks_alive > 40 { + let animation_text = format!( + "жёпа .-.-.-.-.-.- Ticks passed during the aliveness of the connection: {} ticks (1/20 of second) -.-.-.-.-.-. жёпа", + ticks_alive + ); - if animation_index < animation_end { - let now_length = (animation_index + 1).min(animation_text.chars().count()); + let now_length = ((ticks_alive - 40 + 1) as usize).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)?; + let mut text = TextComponent::rainbow_offset(now_text, -(ticks_alive as i64)); + + text.bold = Some(true); + text.italic = Some(true); + text.underlined = Some(true); + + send_system_message(client.clone(), text, true)?; } }