feat(bedrock) add & send health packet

This commit is contained in:
Alexander Medvedev 2026-05-04 19:39:32 +02:00
parent bb0941bfeb
commit 26da644c1d
3 changed files with 39 additions and 7 deletions

View File

@ -18,6 +18,7 @@ pub mod resource_pack_stack;
pub mod resource_packs_info; pub mod resource_packs_info;
pub mod set_actor_data; pub mod set_actor_data;
pub mod set_actor_motion; pub mod set_actor_motion;
pub mod set_health;
pub mod set_player_gamemode; pub mod set_player_gamemode;
pub mod set_time; pub mod set_time;
pub mod set_title; pub mod set_title;

View File

@ -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),
}
}
}

View File

@ -2304,13 +2304,26 @@ impl Player {
return; return;
} }
self.client match &self.client {
.enqueue_packet(&CSetHealth::new( ClientPlatform::Java(client) => {
self.living_entity.health.load(), client
self.hunger_manager.level.load().into(), .enqueue_packet(&CSetHealth::new(
self.hunger_manager.saturation.load(), self.living_entity.health.load(),
)) self.hunger_manager.level.load().into(),
.await; 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) { pub async fn tick_health(&self) {