mirror of
https://github.com/italicsjenga/valence.git
synced 2025-01-11 07:11:30 +11:00
Add action bar support (#15)
* Action bar + conway * Docs for action bar * Apply suggestions * fmt
This commit is contained in:
parent
42dfcef57d
commit
10a8de3bbd
|
@ -200,7 +200,11 @@ impl Config for Game {
|
|||
client.play_sound(
|
||||
ident!("minecraft:block.note_block.banjo"),
|
||||
SoundCategory::Block,
|
||||
Vec3::<f64>::new(normal_position.x.into(), normal_position.y.into(), normal_position.z.into()),
|
||||
Vec3::<f64>::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
|
||||
});
|
||||
|
||||
|
|
|
@ -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<C: Config> {
|
|||
dug_blocks: Vec<i32>,
|
||||
/// Should be sent after login packet.
|
||||
msgs_to_send: Vec<Text>,
|
||||
bar_to_send: Option<Text>,
|
||||
attack_speed: f64,
|
||||
movement_speed: f64,
|
||||
bits: ClientBits,
|
||||
|
@ -290,6 +291,7 @@ impl<C: Config> Client<C> {
|
|||
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<C: Config> Client<C> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Sets the action bar for this client.
|
||||
pub fn set_action_bar(&mut self, text: impl Into<Text>) {
|
||||
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<C: Config> Client<C> {
|
|||
);
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -655,6 +655,12 @@ pub mod play {
|
|||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
OverlayMessage {
|
||||
text: Text
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
UpdateSelectedSlot {
|
||||
slot: BoundedInt<u8, 0, 9>,
|
||||
|
@ -830,6 +836,7 @@ pub mod play {
|
|||
PlayerRespawn = 62,
|
||||
EntitySetHeadYaw = 63,
|
||||
ChunkSectionUpdate = 64,
|
||||
OverlayMessage = 67,
|
||||
UpdateSelectedSlot = 74,
|
||||
ChunkRenderDistanceCenter = 75,
|
||||
ChunkLoadDistance = 76,
|
||||
|
|
Loading…
Reference in a new issue