mirror of
https://github.com/GIKExe/rust_mc_serv.git
synced 2025-06-24 02:12:58 +03:00
beatiful ticks hint
This commit is contained in:
parent
4df4f2ec91
commit
abb0e019af
@ -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::<Vec<TextComponent>>();
|
||||||
|
|
||||||
|
let mut parent = children[0].clone();
|
||||||
|
if children.len() > 1 {
|
||||||
|
parent.extra = Some(children[1..].to_vec());
|
||||||
|
}
|
||||||
|
parent
|
||||||
|
}
|
||||||
|
|
||||||
pub fn rainbow(text: String) -> TextComponent {
|
pub fn rainbow(text: String) -> TextComponent {
|
||||||
if text.is_empty() {
|
if text.is_empty() {
|
||||||
return TextComponent::new(text);
|
return TextComponent::new(text);
|
||||||
|
@ -334,6 +334,7 @@ pub fn handle_play_state(
|
|||||||
}
|
}
|
||||||
send_player(client.clone(), player.clone())?;
|
send_player(client.clone(), player.clone())?;
|
||||||
send_player(player.clone(), client.clone())?;
|
send_player(player.clone(), client.clone())?;
|
||||||
|
send_rainbow_message(&client, format!("{} joined the game", player_name))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
thread::spawn({
|
thread::spawn({
|
||||||
@ -353,11 +354,11 @@ pub fn handle_play_state(
|
|||||||
|
|
||||||
match packet.id() {
|
match packet.id() {
|
||||||
serverbound::play::CLICK_CONTAINER => {
|
serverbound::play::CLICK_CONTAINER => {
|
||||||
let window_id = packet.read_varint()?;
|
let _ = packet.read_varint()?; // window id
|
||||||
let state_id = packet.read_varint()?;
|
let _ = packet.read_varint()?; // state id
|
||||||
let slot = packet.read_short()?;
|
let slot = packet.read_short()?; // slot
|
||||||
let button = packet.read_byte()?;
|
let _ = packet.read_byte()?; // button
|
||||||
let mode = packet.read_varint()?;
|
let _ = packet.read_varint()?; // mode
|
||||||
// i cannot read item slots now
|
// i cannot read item slots now
|
||||||
|
|
||||||
send_rainbow_message(&client, format!("index clicked: {slot}"))?;
|
send_rainbow_message(&client, format!("index clicked: {slot}"))?;
|
||||||
@ -514,15 +515,22 @@ pub fn handle_play_state(
|
|||||||
|
|
||||||
// text animation
|
// text animation
|
||||||
{
|
{
|
||||||
let animation_text = format!("Ticks alive: {} жёпа", ticks_alive);
|
if ticks_alive > 40 {
|
||||||
let animation_index = ((ticks_alive + 40) % 300) as usize;
|
let animation_text = format!(
|
||||||
let animation_end = animation_text.len() + 20;
|
"жёпа .-.-.-.-.-.- Ticks passed during the aliveness of the connection: {} ticks (1/20 of second) -.-.-.-.-.-. жёпа",
|
||||||
|
ticks_alive
|
||||||
|
);
|
||||||
|
|
||||||
if animation_index < animation_end {
|
let now_length = ((ticks_alive - 40 + 1) as usize).min(animation_text.chars().count());
|
||||||
let now_length = (animation_index + 1).min(animation_text.chars().count());
|
|
||||||
let now_text = animation_text.chars().take(now_length).collect();
|
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)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user