mirror of
https://github.com/italicsjenga/valence.git
synced 2025-01-11 15:21:31 +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(
|
client.play_sound(
|
||||||
ident!("minecraft:block.note_block.banjo"),
|
ident!("minecraft:block.note_block.banjo"),
|
||||||
SoundCategory::Block,
|
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,
|
0.5f32,
|
||||||
1f32,
|
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
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ use crate::protocol::packets::s2c::play::{
|
||||||
DimensionTypeRegistry, DimensionTypeRegistryEntry, Disconnect, EntitiesDestroy,
|
DimensionTypeRegistry, DimensionTypeRegistryEntry, Disconnect, EntitiesDestroy,
|
||||||
EntityAnimation, EntityAttributes, EntityAttributesProperty, EntityPosition, EntitySetHeadYaw,
|
EntityAnimation, EntityAttributes, EntityAttributesProperty, EntityPosition, EntitySetHeadYaw,
|
||||||
EntityStatus, EntityTrackerUpdate, EntityVelocityUpdate, GameJoin, GameMessage,
|
EntityStatus, EntityTrackerUpdate, EntityVelocityUpdate, GameJoin, GameMessage,
|
||||||
GameStateChange, GameStateChangeReason, KeepAlive, MoveRelative, PlaySoundId,
|
GameStateChange, GameStateChangeReason, KeepAlive, MoveRelative, OverlayMessage, PlaySoundId,
|
||||||
PlayerActionResponse, PlayerPositionLook, PlayerPositionLookFlags, PlayerRespawn,
|
PlayerActionResponse, PlayerPositionLook, PlayerPositionLookFlags, PlayerRespawn,
|
||||||
PlayerSpawnPosition, RegistryCodec, Rotate, RotateAndMoveRelative, S2cPlayPacket,
|
PlayerSpawnPosition, RegistryCodec, Rotate, RotateAndMoveRelative, S2cPlayPacket,
|
||||||
SoundCategory, UnloadChunk, UpdateSubtitle, UpdateTitle,
|
SoundCategory, UnloadChunk, UpdateSubtitle, UpdateTitle,
|
||||||
|
@ -225,6 +225,7 @@ pub struct Client<C: Config> {
|
||||||
dug_blocks: Vec<i32>,
|
dug_blocks: Vec<i32>,
|
||||||
/// Should be sent after login packet.
|
/// Should be sent after login packet.
|
||||||
msgs_to_send: Vec<Text>,
|
msgs_to_send: Vec<Text>,
|
||||||
|
bar_to_send: Option<Text>,
|
||||||
attack_speed: f64,
|
attack_speed: f64,
|
||||||
movement_speed: f64,
|
movement_speed: f64,
|
||||||
bits: ClientBits,
|
bits: ClientBits,
|
||||||
|
@ -290,6 +291,7 @@ impl<C: Config> Client<C> {
|
||||||
settings: None,
|
settings: None,
|
||||||
dug_blocks: Vec::new(),
|
dug_blocks: Vec::new(),
|
||||||
msgs_to_send: Vec::new(),
|
msgs_to_send: Vec::new(),
|
||||||
|
bar_to_send: None,
|
||||||
attack_speed: 4.0,
|
attack_speed: 4.0,
|
||||||
movement_speed: 0.7,
|
movement_speed: 0.7,
|
||||||
bits: ClientBits::new()
|
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.
|
/// Gets the attack cooldown speed.
|
||||||
pub fn attack_speed(&self) -> f64 {
|
pub fn attack_speed(&self) -> f64 {
|
||||||
self.attack_speed
|
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();
|
let mut entities_to_unload = Vec::new();
|
||||||
|
|
||||||
// Update all entities that are visible and unload entities that are no
|
// 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! {
|
def_struct! {
|
||||||
UpdateSelectedSlot {
|
UpdateSelectedSlot {
|
||||||
slot: BoundedInt<u8, 0, 9>,
|
slot: BoundedInt<u8, 0, 9>,
|
||||||
|
@ -830,6 +836,7 @@ pub mod play {
|
||||||
PlayerRespawn = 62,
|
PlayerRespawn = 62,
|
||||||
EntitySetHeadYaw = 63,
|
EntitySetHeadYaw = 63,
|
||||||
ChunkSectionUpdate = 64,
|
ChunkSectionUpdate = 64,
|
||||||
|
OverlayMessage = 67,
|
||||||
UpdateSelectedSlot = 74,
|
UpdateSelectedSlot = 74,
|
||||||
ChunkRenderDistanceCenter = 75,
|
ChunkRenderDistanceCenter = 75,
|
||||||
ChunkLoadDistance = 76,
|
ChunkLoadDistance = 76,
|
||||||
|
|
Loading…
Reference in a new issue