feat(bedrock) add & send title packet
This commit is contained in:
parent
5616f02751
commit
bb0941bfeb
@ -20,6 +20,7 @@ pub mod set_actor_data;
|
|||||||
pub mod set_actor_motion;
|
pub mod set_actor_motion;
|
||||||
pub mod set_player_gamemode;
|
pub mod set_player_gamemode;
|
||||||
pub mod set_time;
|
pub mod set_time;
|
||||||
|
pub mod set_title;
|
||||||
pub mod start_game;
|
pub mod start_game;
|
||||||
pub mod update_abilities;
|
pub mod update_abilities;
|
||||||
pub mod update_artributes;
|
pub mod update_artributes;
|
||||||
|
|||||||
37
pumpkin-protocol/src/bedrock/client/set_title.rs
Normal file
37
pumpkin-protocol/src/bedrock/client/set_title.rs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
use crate::{codec::var_int::VarInt, serial::PacketWrite};
|
||||||
|
use pumpkin_macros::packet;
|
||||||
|
|
||||||
|
#[derive(PacketWrite)]
|
||||||
|
#[packet(88)]
|
||||||
|
pub struct CSetTitle {
|
||||||
|
pub action_type: VarInt,
|
||||||
|
pub text: String,
|
||||||
|
pub fade_in_duration: VarInt,
|
||||||
|
pub remain_duration: VarInt,
|
||||||
|
pub fade_out_duration: VarInt,
|
||||||
|
pub xuid: String,
|
||||||
|
pub platform_online_id: String,
|
||||||
|
pub filtered_message: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CSetTitle {
|
||||||
|
#[must_use]
|
||||||
|
pub fn new(
|
||||||
|
action_type: i32,
|
||||||
|
text: String,
|
||||||
|
fade_in_duration: i32,
|
||||||
|
remain_duration: i32,
|
||||||
|
fade_out_duration: i32,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
action_type: VarInt(action_type),
|
||||||
|
text,
|
||||||
|
fade_in_duration: VarInt(fade_in_duration),
|
||||||
|
remain_duration: VarInt(remain_duration),
|
||||||
|
fade_out_duration: VarInt(fade_out_duration),
|
||||||
|
xuid: String::new(),
|
||||||
|
platform_online_id: String::new(),
|
||||||
|
filtered_message: String::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1542,17 +1542,54 @@ impl Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn show_title(&self, text: &TextComponent, mode: &TitleMode) {
|
pub async fn show_title(&self, text: &TextComponent, mode: &TitleMode) {
|
||||||
match mode {
|
match &self.client {
|
||||||
TitleMode::Title => self.client.enqueue_packet(&CTitleText::new(text)).await,
|
ClientPlatform::Java(client) => match mode {
|
||||||
TitleMode::SubTitle => self.client.enqueue_packet(&CSubtitle::new(text)).await,
|
TitleMode::Title => client.enqueue_packet(&CTitleText::new(text)).await,
|
||||||
TitleMode::ActionBar => self.client.enqueue_packet(&CActionBar::new(text)).await,
|
TitleMode::SubTitle => client.enqueue_packet(&CSubtitle::new(text)).await,
|
||||||
|
TitleMode::ActionBar => client.enqueue_packet(&CActionBar::new(text)).await,
|
||||||
|
},
|
||||||
|
ClientPlatform::Bedrock(client) => {
|
||||||
|
let action_type = match mode {
|
||||||
|
TitleMode::Title => 2,
|
||||||
|
TitleMode::SubTitle => 3,
|
||||||
|
TitleMode::ActionBar => 4,
|
||||||
|
};
|
||||||
|
client
|
||||||
|
.send_game_packet(
|
||||||
|
&pumpkin_protocol::bedrock::client::set_title::CSetTitle::new(
|
||||||
|
action_type,
|
||||||
|
text.clone().get_text(),
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_title_animation(&self, fade_in: i32, stay: i32, fade_out: i32) {
|
pub async fn send_title_animation(&self, fade_in: i32, stay: i32, fade_out: i32) {
|
||||||
self.client
|
match &self.client {
|
||||||
.enqueue_packet(&CTitleAnimation::new(fade_in, stay, fade_out))
|
ClientPlatform::Java(client) => {
|
||||||
.await;
|
client
|
||||||
|
.enqueue_packet(&CTitleAnimation::new(fade_in, stay, fade_out))
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
ClientPlatform::Bedrock(client) => {
|
||||||
|
client
|
||||||
|
.send_game_packet(
|
||||||
|
&pumpkin_protocol::bedrock::client::set_title::CSetTitle::new(
|
||||||
|
5,
|
||||||
|
String::new(),
|
||||||
|
fade_in,
|
||||||
|
stay,
|
||||||
|
fade_out,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn spawn_particle(
|
pub async fn spawn_particle(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user