Unify block entity pickup conversion

- Removed normal BlockHandler knowledge of block entities during conversion
+ Added cBlockEntity::ConvertToPickups that handles it
This commit is contained in:
Tiger Wang
2020-09-25 09:07:01 +00:00
committed by Alexander Harkness
parent 1a60164848
commit c53a0ba5f6
80 changed files with 179 additions and 212 deletions
+9
View File
@@ -24,6 +24,15 @@ cBedEntity::cBedEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a
cItems cBedEntity::ConvertToPickups() const
{
return cItem(E_ITEM_BED, 1, m_Color);
}
void cBedEntity::CopyFrom(const cBlockEntity & a_Src)
{
Super::CopyFrom(a_Src);
+1
View File
@@ -38,6 +38,7 @@ public: // tolua_export
// tolua_end
// cBlockEntity overrides:
virtual cItems ConvertToPickups() const override;
virtual void CopyFrom(const cBlockEntity & a_Src) override;
virtual bool UsedBy(cPlayer * a_Player) override { return false; }
virtual void SendTo(cClientHandle & a_Client) override;
+9
View File
@@ -128,6 +128,15 @@ OwnedBlockEntity cBlockEntity::Clone(Vector3i a_Pos)
cItems cBlockEntity::ConvertToPickups() const
{
return {};
}
void cBlockEntity::CopyFrom(const cBlockEntity & a_Src)
{
// Nothing to copy, but check that we're copying the right entity:
+5
View File
@@ -29,6 +29,7 @@
class cChunk;
class cItems;
class cPlayer;
class cWorld;
class cBlockEntity;
@@ -83,6 +84,10 @@ public:
Uses CopyFrom() to copy the properties. */
OwnedBlockEntity Clone(Vector3i a_Pos);
/** Returns the contents of this block entity that it would drop if broken.
Note that the block itself is not included; that's handled by the block handler. */
virtual cItems ConvertToPickups() const;
/** Copies all properties of a_Src into this entity, except for its m_World and location.
Each non-abstract descendant should override to copy its specific properties, and call
Super::CopyFrom(a_Src) to copy the common ones. */
@@ -26,6 +26,17 @@ cBlockEntityWithItems::cBlockEntityWithItems(
cItems cBlockEntityWithItems::ConvertToPickups() const
{
cItems Pickups;
Pickups.AddItemGrid(m_Contents);
return Pickups;
}
void cBlockEntityWithItems::CopyFrom(const cBlockEntity & a_Src)
{
Super::CopyFrom(a_Src);
+1
View File
@@ -44,6 +44,7 @@ public: // tolua_export
);
// cBlockEntity overrides:
virtual cItems ConvertToPickups() const override;
virtual void CopyFrom(const cBlockEntity & a_Src) override;
// tolua_begin
@@ -19,6 +19,17 @@ cEnchantingTableEntity::cEnchantingTableEntity(BLOCKTYPE a_BlockType, NIBBLETYPE
cItems cEnchantingTableEntity::ConvertToPickups() const
{
cItem Item(E_BLOCK_ENCHANTMENT_TABLE);
Item.m_CustomName = m_CustomName;
return Item;
}
void cEnchantingTableEntity::CopyFrom(const cBlockEntity & a_Src)
{
Super::CopyFrom(a_Src);
@@ -24,6 +24,7 @@ public:
private:
// cBlockEntity overrides:
virtual cItems ConvertToPickups() const override;
virtual void CopyFrom(const cBlockEntity & a_Src) override;
virtual bool UsedBy(cPlayer * a_Player) override;
virtual void SendTo(cClientHandle & a_Client) override;
+10 -1
View File
@@ -40,7 +40,16 @@ cJukeboxEntity::~cJukeboxEntity()
void cJukeboxEntity::Destroy(void)
{
ASSERT(m_World != nullptr);
EjectRecord();
m_World->BroadcastSoundParticleEffect(EffectID::SFX_RANDOM_PLAY_MUSIC_DISC, GetPos(), 0);
}
cItems cJukeboxEntity::ConvertToPickups() const
{
return IsPlayingRecord() ? cItem(static_cast<short>(m_Record)) : cItems();
}
+9
View File
@@ -25,6 +25,15 @@ cMobHeadEntity::cMobHeadEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Ve
cItems cMobHeadEntity::ConvertToPickups() const
{
return cItem(E_ITEM_HEAD, 1, static_cast<short>(m_Type));
}
void cMobHeadEntity::CopyFrom(const cBlockEntity & a_Src)
{
Super::CopyFrom(a_Src);
+1
View File
@@ -70,6 +70,7 @@ public: // tolua_export
cUUID GetOwnerUUID(void) const { return m_OwnerUUID; } // Exported in ManualBindings.cpp
// cBlockEntity overrides:
virtual cItems ConvertToPickups() const override;
virtual void CopyFrom(const cBlockEntity & a_Src) override;
virtual bool UsedBy(cPlayer * a_Player) override;
virtual void SendTo(cClientHandle & a_Client) override;