From 8405b8969f205ffae219361dfc03f3b4c680ce73 Mon Sep 17 00:00:00 2001 From: 12xx12 <44411062+12xx12@users.noreply.github.com> Date: Fri, 5 Mar 2021 16:08:30 +0100 Subject: Adding Boss bar (#5025) + Add boss bar Co-authored-by: Tiger Wang --- src/Mobs/Wither.cpp | 78 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 31 deletions(-) (limited to 'src/Mobs/Wither.cpp') diff --git a/src/Mobs/Wither.cpp b/src/Mobs/Wither.cpp index fc02b2971..bdbbfcadb 100644 --- a/src/Mobs/Wither.cpp +++ b/src/Mobs/Wither.cpp @@ -5,6 +5,8 @@ #include "../World.h" #include "../Entities/Player.h" +#include "../ClientHandle.h" +#include "../CompositeChat.h" @@ -48,40 +50,13 @@ bool cWither::DoTakeDamage(TakeDamageInfo & a_TDI) return false; } - return Super::DoTakeDamage(a_TDI); -} - - - - - -void cWither::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) -{ - Super::Tick(a_Dt, a_Chunk); - if (!IsTicking()) - { - // The base class tick destroyed us - return; - } - - if (m_WitherInvulnerableTicks > 0) + if (!Super::DoTakeDamage(a_TDI)) { - unsigned int NewTicks = m_WitherInvulnerableTicks - 1; - - if (NewTicks == 0) - { - m_World->DoExplosionAt(7.0, GetPosX(), GetPosY(), GetPosZ(), false, esWitherBirth, this); - } - - m_WitherInvulnerableTicks = NewTicks; - - if ((NewTicks % 10) == 0) - { - Heal(10); - } + return false; } - m_World->BroadcastEntityMetadata(*this); + m_World->BroadcastBossBarUpdateHealth(*this, GetUniqueID(), GetHealth() / GetMaxHealth()); + return true; } @@ -119,3 +94,44 @@ void cWither::KilledBy(TakeDamageInfo & a_TDI) + +void cWither::SpawnOn(cClientHandle & a_Client) +{ + Super::SpawnOn(a_Client); + + // Purple boss bar with no divisions that darkens the sky: + a_Client.SendBossBarAdd(GetUniqueID(), cCompositeChat("Wither"), GetHealth() / GetMaxHealth(), BossBarColor::Purple, BossBarDivisionType::None, true, false, false); +} + + + + + +void cWither::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) +{ + Super::Tick(a_Dt, a_Chunk); + if (!IsTicking()) + { + // The base class tick destroyed us + return; + } + + if (m_WitherInvulnerableTicks > 0) + { + unsigned int NewTicks = m_WitherInvulnerableTicks - 1; + + if (NewTicks == 0) + { + m_World->DoExplosionAt(7.0, GetPosX(), GetPosY(), GetPosZ(), false, esWitherBirth, this); + } + + m_WitherInvulnerableTicks = NewTicks; + + if ((NewTicks % 10) == 0) + { + Heal(10); + } + } + + m_World->BroadcastEntityMetadata(*this); +} -- cgit v1.2.3