Add Message types

aka chat types
This commit is contained in:
Alexander Medvedev 2025-01-23 18:35:00 +01:00
parent 57e54284c5
commit 7ec4cc7c2e
6 changed files with 57 additions and 2 deletions

View File

@ -1 +1 @@
{"chat":{"chat":{"translation_key":"chat.type.text","parameters":["sender","content"]},"narration":{"translation_key":"chat.type.text.narrate","parameters":["sender","content"]}},"emote_command":{"chat":{"translation_key":"chat.type.emote","parameters":["sender","content"]},"narration":{"translation_key":"chat.type.emote","parameters":["sender","content"]}},"msg_command_incoming":{"chat":{"translation_key":"commands.message.display.incoming","parameters":["sender","content"],"style":{"italic":true,"color":"gray"}},"narration":{"translation_key":"chat.type.text.narrate","parameters":["sender","content"]}},"msg_command_outgoing":{"chat":{"translation_key":"commands.message.display.outgoing","parameters":["target","content"],"style":{"italic":true,"color":"gray"}},"narration":{"translation_key":"chat.type.text.narrate","parameters":["sender","content"]}},"say_command":{"chat":{"translation_key":"chat.type.announcement","parameters":["sender","content"]},"narration":{"translation_key":"chat.type.text.narrate","parameters":["sender","content"]}},"team_msg_command_incoming":{"chat":{"translation_key":"chat.type.team.text","parameters":["target","sender","content"]},"narration":{"translation_key":"chat.type.text.narrate","parameters":["sender","content"]}},"team_msg_command_outgoing":{"chat":{"translation_key":"chat.type.team.sent","parameters":["target","sender","content"]},"narration":{"translation_key":"chat.type.text.narrate","parameters":["sender","content"]}}}
{"chat":{"id":0,"components":{"chat":{"translation_key":"chat.type.text","parameters":["sender","content"]},"narration":{"translation_key":"chat.type.text.narrate","parameters":["sender","content"]}}},"emote_command":{"id":1,"components":{"chat":{"translation_key":"chat.type.emote","parameters":["sender","content"]},"narration":{"translation_key":"chat.type.emote","parameters":["sender","content"]}}},"msg_command_incoming":{"id":2,"components":{"chat":{"translation_key":"commands.message.display.incoming","parameters":["sender","content"],"style":{"italic":true,"color":"gray"}},"narration":{"translation_key":"chat.type.text.narrate","parameters":["sender","content"]}}},"msg_command_outgoing":{"id":3,"components":{"chat":{"translation_key":"commands.message.display.outgoing","parameters":["target","content"],"style":{"italic":true,"color":"gray"}},"narration":{"translation_key":"chat.type.text.narrate","parameters":["sender","content"]}}},"say_command":{"id":4,"components":{"chat":{"translation_key":"chat.type.announcement","parameters":["sender","content"]},"narration":{"translation_key":"chat.type.text.narrate","parameters":["sender","content"]}}},"team_msg_command_incoming":{"id":5,"components":{"chat":{"translation_key":"chat.type.team.text","parameters":["target","sender","content"]},"narration":{"translation_key":"chat.type.text.narrate","parameters":["sender","content"]}}},"team_msg_command_outgoing":{"id":6,"components":{"chat":{"translation_key":"chat.type.team.sent","parameters":["target","sender","content"]},"narration":{"translation_key":"chat.type.text.narrate","parameters":["sender","content"]}}}}

View File

@ -8,6 +8,8 @@ build = "build/build.rs"
serde.workspace = true
[build-dependencies]
pumpkin-util = { path = "../pumpkin-util" }
serde.workspace = true
serde_json.workspace = true

View File

@ -10,6 +10,7 @@ mod chunk_status;
mod entity_pose;
mod entity_type;
mod game_event;
mod message_type;
mod noise_parmeter;
mod packet;
mod particle;
@ -33,6 +34,7 @@ pub fn main() {
write_generated_file(entity_type::build(), "entity_type.rs");
write_generated_file(noise_parmeter::build(), "noise_parmeter.rs");
write_generated_file(biome::build(), "biome.rs");
write_generated_file(message_type::build(), "message_type.rs");
}
pub fn array_to_tokenstream(array: Vec<String>) -> TokenStream {

View File

@ -0,0 +1,49 @@
use std::collections::HashMap;
use proc_macro2::TokenStream;
use pumpkin_util::text::style::Style;
use quote::quote;
use serde::{Deserialize, Serialize};
use crate::ident;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RawChatType {
id: u32,
components: ChatType,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChatType {
chat: Decoration,
narration: Decoration,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Decoration {
translation_key: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
style: Option<Style>,
parameters: Vec<String>,
}
pub(crate) fn build() -> TokenStream {
println!("cargo:rerun-if-changed=../assets/message_type.json");
let json: HashMap<String, RawChatType> =
serde_json::from_str(include_str!("../../assets/message_type.json"))
.expect("Failed to parse message_type.json");
let mut variants = TokenStream::new();
for (name, paremter) in json.iter() {
let i = paremter.id;
let name = ident(name.to_uppercase());
variants.extend([quote! {
pub const #name: u32 = #i;
}]);
}
quote! {
#variants
}
}

View File

@ -32,6 +32,7 @@ pub mod entity {
pub mod world {
include!(concat!(env!("OUT_DIR"), "/world_event.rs"));
include!(concat!(env!("OUT_DIR"), "/message_type.rs"));
}
pub mod scoreboard {

View File

@ -13,6 +13,7 @@ use crate::{
};
use pumpkin_config::ADVANCED_CONFIG;
use pumpkin_data::entity::EntityType;
use pumpkin_data::world::CHAT;
use pumpkin_inventory::player::PlayerInventory;
use pumpkin_inventory::InventoryError;
use pumpkin_protocol::client::play::{CSetContainerSlot, CSetHeldItem, CSpawnEntity};
@ -560,7 +561,7 @@ impl Player {
&[],
Some(TextComponent::text(message.clone())),
FilterType::PassThrough,
1.into(),
CHAT.into(),
TextComponent::text(gameprofile.name.clone()),
None,
))