mirror of
https://github.com/italicsjenga/valence.git
synced 2025-01-11 07:11:30 +11:00
Get system chat working
This commit is contained in:
parent
0fcedd3656
commit
340318b9b6
|
@ -6,7 +6,7 @@ use log::LevelFilter;
|
||||||
use noise::{NoiseFn, Seedable, SuperSimplex};
|
use noise::{NoiseFn, Seedable, SuperSimplex};
|
||||||
use rayon::iter::ParallelIterator;
|
use rayon::iter::ParallelIterator;
|
||||||
use valence::block::{BlockState, PropName, PropValue};
|
use valence::block::{BlockState, PropName, PropValue};
|
||||||
use valence::client::{GameMode, PlayerChatType};
|
use valence::client::GameMode;
|
||||||
use valence::config::{Config, ServerListPing};
|
use valence::config::{Config, ServerListPing};
|
||||||
use valence::text::Color;
|
use valence::text::Color;
|
||||||
use valence::util::chunks_in_view_distance;
|
use valence::util::chunks_in_view_distance;
|
||||||
|
@ -114,7 +114,7 @@ impl Config for Game {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
client.send_message("welcome!", PlayerChatType::Chat);
|
client.send_message("Welcome to the terrain example!".italic());
|
||||||
}
|
}
|
||||||
|
|
||||||
let dist = client.view_distance();
|
let dist = client.view_distance();
|
||||||
|
|
|
@ -16,16 +16,15 @@ use crate::entity::types::Player;
|
||||||
use crate::entity::{velocity_to_packet_units, EntityType};
|
use crate::entity::{velocity_to_packet_units, EntityType};
|
||||||
use crate::player_textures::SignedPlayerTextures;
|
use crate::player_textures::SignedPlayerTextures;
|
||||||
use crate::protocol::packets::play::c2s::{C2sPlayPacket, DiggingStatus, InteractType};
|
use crate::protocol::packets::play::c2s::{C2sPlayPacket, DiggingStatus, InteractType};
|
||||||
pub use crate::protocol::packets::play::s2c::PlayerChatType;
|
|
||||||
use crate::protocol::packets::play::s2c::{
|
use crate::protocol::packets::play::s2c::{
|
||||||
Biome as BiomeRegistryBiome, BiomeAdditionsSound, BiomeEffects, BiomeMoodSound, BiomeMusic,
|
Biome as BiomeRegistryBiome, BiomeAdditionsSound, BiomeEffects, BiomeMoodSound, BiomeMusic,
|
||||||
BiomeParticle, BiomeParticleOptions, BiomeProperty, BiomeRegistry, BlockChangeAck,
|
BiomeParticle, BiomeParticleOptions, BiomeProperty, BiomeRegistry, BlockChangeAck, ChatType,
|
||||||
ChatTypeRegistry, DimensionType, DimensionTypeRegistry, DimensionTypeRegistryEntry, Disconnect,
|
ChatTypeChat, ChatTypeNarration, ChatTypeRegistry, ChatTypeRegistryEntry, DimensionType,
|
||||||
ForgetLevelChunk, GameEvent, GameEventReason, KeepAlive, Login, MoveEntityPosition,
|
DimensionTypeRegistry, DimensionTypeRegistryEntry, Disconnect, ForgetLevelChunk, GameEvent,
|
||||||
MoveEntityPositionAndRotation, MoveEntityRotation, PlayerPosition, PlayerPositionFlags,
|
GameEventReason, KeepAlive, Login, MoveEntityPosition, MoveEntityPositionAndRotation,
|
||||||
RegistryCodec, RemoveEntities, RotateHead, S2cPlayPacket, SetChunkCacheCenter,
|
MoveEntityRotation, PlayerPosition, PlayerPositionFlags, RegistryCodec, RemoveEntities,
|
||||||
SetChunkCacheRadius, SetEntityMetadata, SetEntityMotion, SpawnPosition, SystemChat,
|
RotateHead, S2cPlayPacket, SetChunkCacheCenter, SetChunkCacheRadius, SetEntityMetadata,
|
||||||
TeleportEntity,
|
SetEntityMotion, SpawnPosition, SystemChat, TeleportEntity,
|
||||||
};
|
};
|
||||||
use crate::protocol::{BoundedInt, ByteAngle, Nbt, RawBytes, VarInt};
|
use crate::protocol::{BoundedInt, ByteAngle, Nbt, RawBytes, VarInt};
|
||||||
use crate::server::C2sPacketChannels;
|
use crate::server::C2sPacketChannels;
|
||||||
|
@ -136,7 +135,7 @@ pub struct Client {
|
||||||
old_game_mode: GameMode,
|
old_game_mode: GameMode,
|
||||||
settings: Option<Settings>,
|
settings: Option<Settings>,
|
||||||
dug_blocks: Vec<i32>,
|
dug_blocks: Vec<i32>,
|
||||||
msgs_to_send: Vec<(Text, PlayerChatType)>,
|
msgs_to_send: Vec<Text>,
|
||||||
/// The metadata for the client's own player entity.
|
/// The metadata for the client's own player entity.
|
||||||
player_meta: Player,
|
player_meta: Player,
|
||||||
}
|
}
|
||||||
|
@ -200,8 +199,9 @@ impl Client {
|
||||||
self.textures.as_ref()
|
self.textures.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_message(&mut self, msg: impl Into<Text>, typ: PlayerChatType) {
|
/// Sends a system message to the player.
|
||||||
self.msgs_to_send.push((msg.into(), typ));
|
pub fn send_message(&mut self, msg: impl Into<Text>) {
|
||||||
|
self.msgs_to_send.push(msg.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn position(&self) -> Vec3<f64> {
|
pub fn position(&self) -> Vec3<f64> {
|
||||||
|
@ -727,9 +727,14 @@ impl Client {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (msg, typ) in self.msgs_to_send.drain(..) {
|
for msg in self.msgs_to_send.drain(..) {
|
||||||
// TODO: wont work without proper chat registry.
|
send_packet(
|
||||||
send_packet(&mut self.send, SystemChat { chat: msg, typ });
|
&mut self.send,
|
||||||
|
SystemChat {
|
||||||
|
chat: msg,
|
||||||
|
typ: VarInt(0),
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut entities_to_unload = Vec::new();
|
let mut entities_to_unload = Vec::new();
|
||||||
|
@ -917,7 +922,7 @@ fn make_dimension_codec(server: &Server) -> RegistryCodec {
|
||||||
assert_eq!(biome.name, ident!("plains"));
|
assert_eq!(biome.name, ident!("plains"));
|
||||||
biomes.push(to_biome_registry_item(&biome, 0));
|
biomes.push(to_biome_registry_item(&biome, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
RegistryCodec {
|
RegistryCodec {
|
||||||
dimension_type_registry: DimensionTypeRegistry {
|
dimension_type_registry: DimensionTypeRegistry {
|
||||||
typ: ident!("dimension_type"),
|
typ: ident!("dimension_type"),
|
||||||
|
@ -929,7 +934,16 @@ fn make_dimension_codec(server: &Server) -> RegistryCodec {
|
||||||
},
|
},
|
||||||
chat_type_registry: ChatTypeRegistry {
|
chat_type_registry: ChatTypeRegistry {
|
||||||
typ: ident!("chat_type"),
|
typ: ident!("chat_type"),
|
||||||
value: Vec::new(),
|
value: vec![ChatTypeRegistryEntry {
|
||||||
|
name: ident!("system"),
|
||||||
|
id: 0,
|
||||||
|
element: ChatType {
|
||||||
|
chat: ChatTypeChat {},
|
||||||
|
narration: ChatTypeNarration {
|
||||||
|
priority: "system".to_string(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -993,7 +993,23 @@ pub mod play {
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct ChatTypeRegistryEntry {
|
pub struct ChatTypeRegistryEntry {
|
||||||
// TODO
|
pub name: Ident,
|
||||||
|
pub id: i32,
|
||||||
|
pub element: ChatType,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub struct ChatType {
|
||||||
|
pub chat: ChatTypeChat,
|
||||||
|
pub narration: ChatTypeNarration,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub struct ChatTypeChat {}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
pub struct ChatTypeNarration {
|
||||||
|
pub priority: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
def_enum! {
|
def_enum! {
|
||||||
|
@ -1037,27 +1053,13 @@ pub mod play {
|
||||||
def_struct! {
|
def_struct! {
|
||||||
PlayerChat 0x30 {
|
PlayerChat 0x30 {
|
||||||
message: Text,
|
message: Text,
|
||||||
typ: PlayerChatType,
|
/// Index into the chat type registry
|
||||||
|
typ: VarInt,
|
||||||
sender: Uuid,
|
sender: Uuid,
|
||||||
// TODO more fields
|
// TODO more fields
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def_enum! {
|
|
||||||
#[derive(Copy, PartialEq, Eq, Default)]
|
|
||||||
PlayerChatType: VarInt {
|
|
||||||
#[default]
|
|
||||||
Chat = 0,
|
|
||||||
SystemMessage = 1,
|
|
||||||
GameInfo = 2,
|
|
||||||
SayCommand = 3,
|
|
||||||
MsgCommand = 4,
|
|
||||||
TeamMsgCommand = 5,
|
|
||||||
EmoteCommand = 6,
|
|
||||||
TellrawCommand = 7,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def_enum! {
|
def_enum! {
|
||||||
PlayerInfo 0x34: VarInt {
|
PlayerInfo 0x34: VarInt {
|
||||||
AddPlayer: Vec<PlayerInfoAddPlayer> = 0,
|
AddPlayer: Vec<PlayerInfoAddPlayer> = 0,
|
||||||
|
@ -1176,7 +1178,8 @@ pub mod play {
|
||||||
def_struct! {
|
def_struct! {
|
||||||
SystemChat 0x5f {
|
SystemChat 0x5f {
|
||||||
chat: Text,
|
chat: Text,
|
||||||
typ: PlayerChatType,
|
/// Index into the chat type registry.
|
||||||
|
typ: VarInt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue