From 26da644c1d4e9fdf2fc92e8eda5a2fe07cc83371 Mon Sep 17 00:00:00 2001 From: Alexander Medvedev Date: Mon, 4 May 2026 19:39:32 +0200 Subject: [PATCH] feat(bedrock) add & send health packet --- pumpkin-protocol/src/bedrock/client/mod.rs | 1 + .../src/bedrock/client/set_health.rs | 18 +++++++++++++ pumpkin/src/entity/player.rs | 27 ++++++++++++++----- 3 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 pumpkin-protocol/src/bedrock/client/set_health.rs diff --git a/pumpkin-protocol/src/bedrock/client/mod.rs b/pumpkin-protocol/src/bedrock/client/mod.rs index 64e18efaf..d10a1ee6e 100644 --- a/pumpkin-protocol/src/bedrock/client/mod.rs +++ b/pumpkin-protocol/src/bedrock/client/mod.rs @@ -18,6 +18,7 @@ pub mod resource_pack_stack; pub mod resource_packs_info; pub mod set_actor_data; pub mod set_actor_motion; +pub mod set_health; pub mod set_player_gamemode; pub mod set_time; pub mod set_title; diff --git a/pumpkin-protocol/src/bedrock/client/set_health.rs b/pumpkin-protocol/src/bedrock/client/set_health.rs new file mode 100644 index 000000000..7d0d3021a --- /dev/null +++ b/pumpkin-protocol/src/bedrock/client/set_health.rs @@ -0,0 +1,18 @@ +use crate::{codec::var_int::VarInt, serial::PacketWrite}; +use pumpkin_macros::packet; + +#[derive(PacketWrite)] +#[packet(42)] +pub struct CSetHealth { + // https://mojang.github.io/bedrock-protocol-docs/html/SetHealthPacket.html + pub health: VarInt, +} + +impl CSetHealth { + #[must_use] + pub const fn new(health: i32) -> Self { + Self { + health: VarInt(health), + } + } +} diff --git a/pumpkin/src/entity/player.rs b/pumpkin/src/entity/player.rs index 99abe976d..bca3c1d36 100644 --- a/pumpkin/src/entity/player.rs +++ b/pumpkin/src/entity/player.rs @@ -2304,13 +2304,26 @@ impl Player { return; } - self.client - .enqueue_packet(&CSetHealth::new( - self.living_entity.health.load(), - self.hunger_manager.level.load().into(), - self.hunger_manager.saturation.load(), - )) - .await; + match &self.client { + ClientPlatform::Java(client) => { + client + .enqueue_packet(&CSetHealth::new( + self.living_entity.health.load(), + self.hunger_manager.level.load().into(), + self.hunger_manager.saturation.load(), + )) + .await; + } + ClientPlatform::Bedrock(client) => { + client + .send_game_packet( + &pumpkin_protocol::bedrock::client::set_health::CSetHealth::new( + self.living_entity.health.load() as i32, + ), + ) + .await; + } + } } pub async fn tick_health(&self) {