diff --git a/examples/conway.rs b/examples/conway.rs index 910d331..08720be 100644 --- a/examples/conway.rs +++ b/examples/conway.rs @@ -200,7 +200,11 @@ impl Config for Game { client.play_sound( ident!("minecraft:block.note_block.banjo"), SoundCategory::Block, - Vec3::::new(normal_position.x.into(), normal_position.y.into(), normal_position.z.into()), + Vec3::::new( + normal_position.x.into(), + normal_position.y.into(), + normal_position.z.into(), + ), 0.5f32, 1f32, ); @@ -232,6 +236,13 @@ impl Config for Game { } } + // Display Playing in green or Paused in red + client.set_action_bar(if server.state.paused { + "Paused".color(Color::RED) + } else { + "Playing".color(Color::GREEN) + }); + true }); diff --git a/src/client.rs b/src/client.rs index e9f1264..cd59302 100644 --- a/src/client.rs +++ b/src/client.rs @@ -33,7 +33,7 @@ use crate::protocol::packets::s2c::play::{ DimensionTypeRegistry, DimensionTypeRegistryEntry, Disconnect, EntitiesDestroy, EntityAnimation, EntityAttributes, EntityAttributesProperty, EntityPosition, EntitySetHeadYaw, EntityStatus, EntityTrackerUpdate, EntityVelocityUpdate, GameJoin, GameMessage, - GameStateChange, GameStateChangeReason, KeepAlive, MoveRelative, PlaySoundId, + GameStateChange, GameStateChangeReason, KeepAlive, MoveRelative, OverlayMessage, PlaySoundId, PlayerActionResponse, PlayerPositionLook, PlayerPositionLookFlags, PlayerRespawn, PlayerSpawnPosition, RegistryCodec, Rotate, RotateAndMoveRelative, S2cPlayPacket, SoundCategory, UnloadChunk, UpdateSubtitle, UpdateTitle, @@ -225,6 +225,7 @@ pub struct Client { dug_blocks: Vec, /// Should be sent after login packet. msgs_to_send: Vec, + bar_to_send: Option, attack_speed: f64, movement_speed: f64, bits: ClientBits, @@ -290,6 +291,7 @@ impl Client { settings: None, dug_blocks: Vec::new(), msgs_to_send: Vec::new(), + bar_to_send: None, attack_speed: 4.0, movement_speed: 0.7, bits: ClientBits::new() @@ -506,6 +508,11 @@ impl Client { } } + /// Sets the action bar for this client. + pub fn set_action_bar(&mut self, text: impl Into) { + self.bar_to_send = Some(text.into()); + } + /// Gets the attack cooldown speed. pub fn attack_speed(&self) -> f64 { self.attack_speed @@ -1219,6 +1226,10 @@ impl Client { ); } + if let Some(bar) = self.bar_to_send.take() { + send_packet(&mut self.send, OverlayMessage { text: bar }); + } + let mut entities_to_unload = Vec::new(); // Update all entities that are visible and unload entities that are no diff --git a/src/protocol/packets/s2c.rs b/src/protocol/packets/s2c.rs index 4a4f2e0..925a44b 100644 --- a/src/protocol/packets/s2c.rs +++ b/src/protocol/packets/s2c.rs @@ -655,6 +655,12 @@ pub mod play { } } + def_struct! { + OverlayMessage { + text: Text + } + } + def_struct! { UpdateSelectedSlot { slot: BoundedInt, @@ -830,6 +836,7 @@ pub mod play { PlayerRespawn = 62, EntitySetHeadYaw = 63, ChunkSectionUpdate = 64, + OverlayMessage = 67, UpdateSelectedSlot = 74, ChunkRenderDistanceCenter = 75, ChunkLoadDistance = 76,