Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make bossbar use EntityLayer for visibility #437

Merged
merged 6 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions crates/valence_boss_bar/src/components.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use std::borrow::Cow;

use bevy_ecs::prelude::{Bundle, Component};
use valence_entity::EntityLayerId;
use valence_server::protocol::packets::play::boss_bar_s2c::{
BossBarAction, BossBarColor, BossBarDivision, BossBarFlags, ToPacketAction,
};
use valence_server::{Text, UniqueId};

/// The bundle of components that make up a boss bar.
#[derive(Bundle, Default)]
pub struct BossBarBundle {
pub id: UniqueId,
pub title: BossBarTitle,
pub health: BossBarHealth,
pub style: BossBarStyle,
pub flags: BossBarFlags,
pub layer: EntityLayerId,
}

/// The title of a boss bar.
#[derive(Component, Clone, Default)]
pub struct BossBarTitle(pub Text);

impl ToPacketAction for BossBarTitle {
fn to_packet_action(&self) -> BossBarAction {
BossBarAction::UpdateTitle(Cow::Borrowed(&self.0))
}
}

/// The health of a boss bar.
#[derive(Component, Default)]
pub struct BossBarHealth(pub f32);

impl ToPacketAction for BossBarHealth {
fn to_packet_action(&self) -> BossBarAction {
BossBarAction::UpdateHealth(self.0)
}
}

/// The style of a boss bar. This includes the color and division of the boss
/// bar.
#[derive(Component, Default)]
pub struct BossBarStyle {
pub color: BossBarColor,
pub division: BossBarDivision,
}
Bafbi marked this conversation as resolved.
Show resolved Hide resolved

impl ToPacketAction for BossBarStyle {
fn to_packet_action(&self) -> BossBarAction {
BossBarAction::UpdateStyle(self.color, self.division)
}
}
Loading
Loading