Add Clientbound Set Health
This commit is contained in:
parent
b5452245d8
commit
4076cda942
22
pumpkin-protocol/src/client/play/c_set_health.rs
Normal file
22
pumpkin-protocol/src/client/play/c_set_health.rs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
use pumpkin_macros::packet;
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use crate::VarInt;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
#[packet(0x5D)]
|
||||||
|
pub struct CSetHealth {
|
||||||
|
health: f32,
|
||||||
|
food: VarInt,
|
||||||
|
food_saturation: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CSetHealth {
|
||||||
|
pub fn new(health: f32, food: VarInt, food_saturation: f32) -> Self {
|
||||||
|
Self {
|
||||||
|
health,
|
||||||
|
food,
|
||||||
|
food_saturation,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -28,6 +28,7 @@ mod c_remove_entities;
|
|||||||
mod c_set_container_content;
|
mod c_set_container_content;
|
||||||
mod c_set_container_property;
|
mod c_set_container_property;
|
||||||
mod c_set_container_slot;
|
mod c_set_container_slot;
|
||||||
|
mod c_set_health;
|
||||||
mod c_set_held_item;
|
mod c_set_held_item;
|
||||||
mod c_set_title;
|
mod c_set_title;
|
||||||
mod c_spawn_player;
|
mod c_spawn_player;
|
||||||
@ -72,6 +73,7 @@ pub use c_remove_entities::*;
|
|||||||
pub use c_set_container_content::*;
|
pub use c_set_container_content::*;
|
||||||
pub use c_set_container_property::*;
|
pub use c_set_container_property::*;
|
||||||
pub use c_set_container_slot::*;
|
pub use c_set_container_slot::*;
|
||||||
|
pub use c_set_health::*;
|
||||||
pub use c_set_held_item::*;
|
pub use c_set_held_item::*;
|
||||||
pub use c_set_title::*;
|
pub use c_set_title::*;
|
||||||
pub use c_spawn_player::*;
|
pub use c_spawn_player::*;
|
||||||
|
|||||||
@ -17,8 +17,8 @@ use pumpkin_inventory::player::PlayerInventory;
|
|||||||
use pumpkin_protocol::{
|
use pumpkin_protocol::{
|
||||||
bytebuf::{packet_id::Packet, DeserializerError},
|
bytebuf::{packet_id::Packet, DeserializerError},
|
||||||
client::play::{
|
client::play::{
|
||||||
CGameEvent, CPlayDisconnect, CPlayerAbilities, CPlayerInfoUpdate, CSyncPlayerPosition,
|
CGameEvent, CPlayDisconnect, CPlayerAbilities, CPlayerInfoUpdate, CSetHealth,
|
||||||
CSystemChatMessage, GameEvent, PlayerAction,
|
CSyncPlayerPosition, CSystemChatMessage, GameEvent, PlayerAction,
|
||||||
},
|
},
|
||||||
server::play::{
|
server::play::{
|
||||||
SChatCommand, SChatMessage, SClickContainer, SClientInformationPlay, SConfirmTeleport,
|
SChatCommand, SChatMessage, SClickContainer, SClientInformationPlay, SConfirmTeleport,
|
||||||
@ -232,6 +232,8 @@ impl Player {
|
|||||||
self.entity.health.store(health);
|
self.entity.health.store(health);
|
||||||
self.food.store(food, std::sync::atomic::Ordering::Relaxed);
|
self.food.store(food, std::sync::atomic::Ordering::Relaxed);
|
||||||
self.food_saturation.store(food_saturation);
|
self.food_saturation.store(food_saturation);
|
||||||
|
self.client
|
||||||
|
.send_packet(&CSetHealth::new(health, food.into(), food_saturation));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_gamemode(&self, gamemode: GameMode) {
|
pub fn set_gamemode(&self, gamemode: GameMode) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user