Add Clientbound Set Health

This commit is contained in:
Snowiiii 2024-10-11 12:00:18 +02:00
parent b5452245d8
commit 4076cda942
3 changed files with 28 additions and 2 deletions

View 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,
}
}
}

View File

@ -28,6 +28,7 @@ mod c_remove_entities;
mod c_set_container_content;
mod c_set_container_property;
mod c_set_container_slot;
mod c_set_health;
mod c_set_held_item;
mod c_set_title;
mod c_spawn_player;
@ -72,6 +73,7 @@ pub use c_remove_entities::*;
pub use c_set_container_content::*;
pub use c_set_container_property::*;
pub use c_set_container_slot::*;
pub use c_set_health::*;
pub use c_set_held_item::*;
pub use c_set_title::*;
pub use c_spawn_player::*;

View File

@ -17,8 +17,8 @@ use pumpkin_inventory::player::PlayerInventory;
use pumpkin_protocol::{
bytebuf::{packet_id::Packet, DeserializerError},
client::play::{
CGameEvent, CPlayDisconnect, CPlayerAbilities, CPlayerInfoUpdate, CSyncPlayerPosition,
CSystemChatMessage, GameEvent, PlayerAction,
CGameEvent, CPlayDisconnect, CPlayerAbilities, CPlayerInfoUpdate, CSetHealth,
CSyncPlayerPosition, CSystemChatMessage, GameEvent, PlayerAction,
},
server::play::{
SChatCommand, SChatMessage, SClickContainer, SClientInformationPlay, SConfirmTeleport,
@ -232,6 +232,8 @@ impl Player {
self.entity.health.store(health);
self.food.store(food, std::sync::atomic::Ordering::Relaxed);
self.food_saturation.store(food_saturation);
self.client
.send_packet(&CSetHealth::new(health, food.into(), food_saturation));
}
pub fn set_gamemode(&self, gamemode: GameMode) {