Skip to main content

steel_core/player/
title.rs

1//! Player helpers for sending client-side title displays.
2
3use steel_protocol::packets::game::{
4    CClearTitles, CSetActionBarText, CSetSubtitleText, CSetTitleText, CSetTitlesAnimation,
5};
6use text_components::TextComponent;
7
8use crate::player::Player;
9
10impl Player {
11    /// Sends title text to the player.
12    pub fn send_title(&self, text: impl Into<TextComponent>) {
13        self.send_packet(CSetTitleText::new(text));
14    }
15
16    /// Sends subtitle text to the player.
17    pub fn send_subtitle(&self, text: impl Into<TextComponent>) {
18        self.send_packet(CSetSubtitleText::new(text));
19    }
20
21    /// Sends action-bar text to the player.
22    pub fn send_action_bar(&self, text: impl Into<TextComponent>) {
23        self.send_packet(CSetActionBarText::new(text));
24    }
25
26    /// Sets title animation durations in client ticks.
27    pub fn send_title_times(&self, fade_in: i32, stay: i32, fade_out: i32) {
28        self.send_packet(CSetTitlesAnimation::new(fade_in, stay, fade_out));
29    }
30
31    /// Clears the player's current title display while preserving its timings.
32    pub fn clear_titles(&self) {
33        self.send_packet(CClearTitles::new(false));
34    }
35
36    /// Clears the player's current title display and resets its timings.
37    pub fn reset_titles(&self) {
38        self.send_packet(CClearTitles::new(true));
39    }
40}