From 1a60164848396e0078bd56659f8d43c1e58a03d8 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 23 Sep 2020 16:03:39 +0100 Subject: Small cleanup in Jukeboxes * Fixed creative players not tracking stats, and the code trying to "place" a record when they used one --- src/BlockEntities/JukeboxEntity.cpp | 28 ++++++++++++++++------------ src/BlockEntities/JukeboxEntity.h | 3 ++- 2 files changed, 18 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/BlockEntities/JukeboxEntity.cpp b/src/BlockEntities/JukeboxEntity.cpp index 6f25c4a36..f5380e789 100644 --- a/src/BlockEntities/JukeboxEntity.cpp +++ b/src/BlockEntities/JukeboxEntity.cpp @@ -65,17 +65,20 @@ bool cJukeboxEntity::UsedBy(cPlayer * a_Player) EjectRecord(); return true; } - else + + const cItem & HeldItem = a_Player->GetEquippedItem(); + if (PlayRecord(HeldItem.m_ItemType)) { - const cItem & HeldItem = a_Player->GetEquippedItem(); - if (PlayRecord(HeldItem.m_ItemType) && !a_Player->IsGameModeCreative()) + a_Player->GetStatManager().AddValue(Statistic::PlayRecord); + if (!a_Player->IsGameModeCreative()) { - a_Player->GetStatManager().AddValue(Statistic::PlayRecord); - a_Player->GetInventory().RemoveOneEquippedItem(); - return true; } + + return true; } + + // No state change, continue with block placement: return false; } @@ -90,11 +93,13 @@ bool cJukeboxEntity::PlayRecord(int a_Record) // This isn't a Record Item return false; } + if (IsPlayingRecord()) { // A Record is already in the Jukebox. EjectRecord(); } + m_Record = a_Record; m_World->BroadcastSoundParticleEffect(EffectID::SFX_RANDOM_PLAY_MUSIC_DISC, GetPos(), m_Record); m_World->SetBlockMeta(m_Pos, E_META_JUKEBOX_ON); @@ -113,12 +118,11 @@ bool cJukeboxEntity::EjectRecord(void) return false; } - cItems Drops; - Drops.push_back(cItem(static_cast(m_Record), 1, 0)); - m_Record = 0; - m_World->SpawnItemPickups(Drops, Vector3d(0.5, 0.5, 0.5) + m_Pos, 10); + m_World->SpawnItemPickups(cItem(static_cast(m_Record)), Vector3d(0.5, 0.5, 0.5) + m_Pos, 10); m_World->SetBlockMeta(m_Pos, E_META_JUKEBOX_OFF); m_World->BroadcastSoundParticleEffect(EffectID::SFX_RANDOM_PLAY_MUSIC_DISC, GetPos(), 0); + + m_Record = 0; return true; } @@ -126,9 +130,9 @@ bool cJukeboxEntity::EjectRecord(void) -bool cJukeboxEntity::IsPlayingRecord(void) +bool cJukeboxEntity::IsPlayingRecord(void) const { - return (m_Record != 0); + return m_Record != 0; } diff --git a/src/BlockEntities/JukeboxEntity.h b/src/BlockEntities/JukeboxEntity.h index 223861149..5af2012bd 100644 --- a/src/BlockEntities/JukeboxEntity.h +++ b/src/BlockEntities/JukeboxEntity.h @@ -37,7 +37,7 @@ public: // tolua_export bool EjectRecord(void); /** Is in the Jukebox a Record? */ - bool IsPlayingRecord(void); + bool IsPlayingRecord(void) const; static bool IsRecordItem(int a_Item) { @@ -48,6 +48,7 @@ public: // tolua_export // cBlockEntity overrides: virtual void Destroy(void) override; + virtual cItems ConvertToPickups() const override; virtual void CopyFrom(const cBlockEntity & a_Src) override; virtual bool UsedBy(cPlayer * a_Player) override; virtual void SendTo(cClientHandle &) override {} -- cgit v1.2.3