1
0

Small cleanup in Jukeboxes

* Fixed creative players not tracking stats, and the code trying to "place" a record when they used one
This commit is contained in:
Tiger Wang 2020-09-23 16:03:39 +01:00 committed by Alexander Harkness
parent a2ecbf6a2e
commit 1a60164848
2 changed files with 19 additions and 14 deletions

View File

@ -65,17 +65,20 @@ bool cJukeboxEntity::UsedBy(cPlayer * a_Player)
EjectRecord(); EjectRecord();
return true; return true;
} }
else
{
const cItem & HeldItem = a_Player->GetEquippedItem(); const cItem & HeldItem = a_Player->GetEquippedItem();
if (PlayRecord(HeldItem.m_ItemType) && !a_Player->IsGameModeCreative()) if (PlayRecord(HeldItem.m_ItemType))
{ {
a_Player->GetStatManager().AddValue(Statistic::PlayRecord); a_Player->GetStatManager().AddValue(Statistic::PlayRecord);
if (!a_Player->IsGameModeCreative())
{
a_Player->GetInventory().RemoveOneEquippedItem(); a_Player->GetInventory().RemoveOneEquippedItem();
}
return true; return true;
} }
}
// No state change, continue with block placement:
return false; return false;
} }
@ -90,11 +93,13 @@ bool cJukeboxEntity::PlayRecord(int a_Record)
// This isn't a Record Item // This isn't a Record Item
return false; return false;
} }
if (IsPlayingRecord()) if (IsPlayingRecord())
{ {
// A Record is already in the Jukebox. // A Record is already in the Jukebox.
EjectRecord(); EjectRecord();
} }
m_Record = a_Record; m_Record = a_Record;
m_World->BroadcastSoundParticleEffect(EffectID::SFX_RANDOM_PLAY_MUSIC_DISC, GetPos(), m_Record); m_World->BroadcastSoundParticleEffect(EffectID::SFX_RANDOM_PLAY_MUSIC_DISC, GetPos(), m_Record);
m_World->SetBlockMeta(m_Pos, E_META_JUKEBOX_ON); m_World->SetBlockMeta(m_Pos, E_META_JUKEBOX_ON);
@ -113,12 +118,11 @@ bool cJukeboxEntity::EjectRecord(void)
return false; return false;
} }
cItems Drops; m_World->SpawnItemPickups(cItem(static_cast<short>(m_Record)), Vector3d(0.5, 0.5, 0.5) + m_Pos, 10);
Drops.push_back(cItem(static_cast<short>(m_Record), 1, 0));
m_Record = 0;
m_World->SpawnItemPickups(Drops, Vector3d(0.5, 0.5, 0.5) + m_Pos, 10);
m_World->SetBlockMeta(m_Pos, E_META_JUKEBOX_OFF); m_World->SetBlockMeta(m_Pos, E_META_JUKEBOX_OFF);
m_World->BroadcastSoundParticleEffect(EffectID::SFX_RANDOM_PLAY_MUSIC_DISC, GetPos(), 0); m_World->BroadcastSoundParticleEffect(EffectID::SFX_RANDOM_PLAY_MUSIC_DISC, GetPos(), 0);
m_Record = 0;
return true; 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;
} }

View File

@ -37,7 +37,7 @@ public: // tolua_export
bool EjectRecord(void); bool EjectRecord(void);
/** Is in the Jukebox a Record? */ /** Is in the Jukebox a Record? */
bool IsPlayingRecord(void); bool IsPlayingRecord(void) const;
static bool IsRecordItem(int a_Item) static bool IsRecordItem(int a_Item)
{ {
@ -48,6 +48,7 @@ public: // tolua_export
// cBlockEntity overrides: // cBlockEntity overrides:
virtual void Destroy(void) override; virtual void Destroy(void) override;
virtual cItems ConvertToPickups() const override;
virtual void CopyFrom(const cBlockEntity & a_Src) override; virtual void CopyFrom(const cBlockEntity & a_Src) override;
virtual bool UsedBy(cPlayer * a_Player) override; virtual bool UsedBy(cPlayer * a_Player) override;
virtual void SendTo(cClientHandle &) override {} virtual void SendTo(cClientHandle &) override {}