mirror of
https://github.com/italicsjenga/valence.git
synced 2024-12-23 22:41:30 +11:00
Added SetExperience and SetHealth packets (#34)
* Added `SetExperience` and `SetHealth` packets Packets were tested * Rename packets in accordance with `packets.json` Renamed `SetExperience` to `ExperienceBarUpdate` and `SetHealth` to `HealthUpdate` * `set_level` and `set_health_and_food` functions
This commit is contained in:
parent
7b3e317c06
commit
a80052097a
|
@ -32,11 +32,11 @@ use crate::protocol::packets::s2c::play::{
|
|||
BiomeRegistry, ChatTypeRegistry, ChunkLoadDistance, ChunkRenderDistanceCenter, ClearTitles,
|
||||
DimensionTypeRegistry, DimensionTypeRegistryEntry, Disconnect, EntitiesDestroy,
|
||||
EntityAnimation, EntityAttributes, EntityAttributesProperty, EntityPosition, EntitySetHeadYaw,
|
||||
EntityStatus, EntityTrackerUpdate, EntityVelocityUpdate, GameJoin, GameMessage,
|
||||
GameStateChange, GameStateChangeReason, KeepAlive, MoveRelative, OverlayMessage, PlaySoundId,
|
||||
PlayerActionResponse, PlayerPositionLook, PlayerPositionLookFlags, PlayerRespawn,
|
||||
PlayerSpawnPosition, RegistryCodec, Rotate, RotateAndMoveRelative, S2cPlayPacket,
|
||||
SoundCategory, UnloadChunk, UpdateSubtitle, UpdateTitle,
|
||||
EntityStatus, EntityTrackerUpdate, EntityVelocityUpdate, ExperienceBarUpdate, GameJoin,
|
||||
GameMessage, GameStateChange, GameStateChangeReason, HealthUpdate, KeepAlive, MoveRelative,
|
||||
OverlayMessage, PlaySoundId, PlayerActionResponse, PlayerPositionLook, PlayerPositionLookFlags,
|
||||
PlayerRespawn, PlayerSpawnPosition, RegistryCodec, Rotate, RotateAndMoveRelative,
|
||||
S2cPlayPacket, SoundCategory, UnloadChunk, UpdateSubtitle, UpdateTitle,
|
||||
};
|
||||
use crate::protocol::{BoundedInt, ByteAngle, NbtBridge, RawBytes, VarInt};
|
||||
use crate::server::{C2sPacketChannels, NewClientData, S2cPlayMessage, SharedServer};
|
||||
|
@ -544,6 +544,35 @@ impl<C: Config> Client<C> {
|
|||
self.send_packet(ClearTitles { reset: true });
|
||||
}
|
||||
|
||||
/// Sets the XP bar visible above hotbar and total experience.
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `bar` - Floating value in the range `0.0..=1.0` indicating progress on the XP bar.
|
||||
/// * `level` - Number above the XP bar.
|
||||
/// * `total_xp` - TODO.
|
||||
pub fn set_level(&mut self, bar: f32, level: i32, total_xp: i32) {
|
||||
self.send_packet(ExperienceBarUpdate {
|
||||
bar,
|
||||
level: level.into(),
|
||||
total_xp: total_xp.into(),
|
||||
})
|
||||
}
|
||||
|
||||
/// Sets the health and food of the player.
|
||||
/// You can read more about hunger and saturation [here](https://minecraft.fandom.com/wiki/Food#Hunger_vs._Saturation).
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `health` - Float in range `0.0..=20.0`. Value `<=0` is legal and will kill the player.
|
||||
/// * `food` - Integer in range `0..=20`.
|
||||
/// * `food_saturation` - Float in range `0.0..=5.0`.
|
||||
pub fn set_health_and_food(&mut self, health: f32, food: i32, food_saturation: f32) {
|
||||
self.send_packet(HealthUpdate {
|
||||
health,
|
||||
food: food.into(),
|
||||
food_saturation,
|
||||
})
|
||||
}
|
||||
|
||||
/// Gets whether or not the client is connected to the server.
|
||||
///
|
||||
/// A disconnected client object will never become reconnected. It is your
|
||||
|
|
|
@ -701,6 +701,22 @@ pub mod play {
|
|||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
ExperienceBarUpdate {
|
||||
bar: f32,
|
||||
level: VarInt,
|
||||
total_xp: VarInt,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
HealthUpdate {
|
||||
health: f32,
|
||||
food: VarInt,
|
||||
food_saturation: f32,
|
||||
}
|
||||
}
|
||||
|
||||
def_struct! {
|
||||
UpdateSubtitle {
|
||||
subtitle_text: Text,
|
||||
|
@ -843,6 +859,8 @@ pub mod play {
|
|||
PlayerSpawnPosition = 77,
|
||||
EntityTrackerUpdate = 80,
|
||||
EntityVelocityUpdate = 82,
|
||||
ExperienceBarUpdate = 84,
|
||||
HealthUpdate = 85,
|
||||
UpdateSubtitle = 91,
|
||||
WorldTimeUpdate = 92,
|
||||
UpdateTitle = 93,
|
||||
|
|
Loading…
Reference in a new issue