summaryrefslogtreecommitdiffstats
path: root/src/BlockEntities
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2020-09-23 17:03:39 +0200
committerAlexander Harkness <me@bearbin.net>2020-09-25 11:07:01 +0200
commit1a60164848396e0078bd56659f8d43c1e58a03d8 (patch)
tree1910b8f310ba9fe6d655212c3e14f9daeb61b97c /src/BlockEntities
parentFix cItems::AddItemGrid adding empty items (diff)
downloadcuberite-1a60164848396e0078bd56659f8d43c1e58a03d8.tar
cuberite-1a60164848396e0078bd56659f8d43c1e58a03d8.tar.gz
cuberite-1a60164848396e0078bd56659f8d43c1e58a03d8.tar.bz2
cuberite-1a60164848396e0078bd56659f8d43c1e58a03d8.tar.lz
cuberite-1a60164848396e0078bd56659f8d43c1e58a03d8.tar.xz
cuberite-1a60164848396e0078bd56659f8d43c1e58a03d8.tar.zst
cuberite-1a60164848396e0078bd56659f8d43c1e58a03d8.zip
Diffstat (limited to 'src/BlockEntities')
-rw-r--r--src/BlockEntities/JukeboxEntity.cpp28
-rw-r--r--src/BlockEntities/JukeboxEntity.h3
2 files changed, 18 insertions, 13 deletions
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<short>(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<short>(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 {}