diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2020-09-23 17:06:27 +0200 |
---|---|---|
committer | Alexander Harkness <me@bearbin.net> | 2020-09-25 11:07:01 +0200 |
commit | c53a0ba5f6f71da384a45a07685f8e25c3f91a29 (patch) | |
tree | bc8d016d1f5c5b5206b3b4f5580295bd91bb6099 | |
parent | Small cleanup in Jukeboxes (diff) | |
download | cuberite-c53a0ba5f6f71da384a45a07685f8e25c3f91a29.tar cuberite-c53a0ba5f6f71da384a45a07685f8e25c3f91a29.tar.gz cuberite-c53a0ba5f6f71da384a45a07685f8e25c3f91a29.tar.bz2 cuberite-c53a0ba5f6f71da384a45a07685f8e25c3f91a29.tar.lz cuberite-c53a0ba5f6f71da384a45a07685f8e25c3f91a29.tar.xz cuberite-c53a0ba5f6f71da384a45a07685f8e25c3f91a29.tar.zst cuberite-c53a0ba5f6f71da384a45a07685f8e25c3f91a29.zip |
Diffstat (limited to '')
80 files changed, 181 insertions, 214 deletions
diff --git a/src/BlockEntities/BedEntity.cpp b/src/BlockEntities/BedEntity.cpp index 55fc53b98..3d7005b12 100644 --- a/src/BlockEntities/BedEntity.cpp +++ b/src/BlockEntities/BedEntity.cpp @@ -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); diff --git a/src/BlockEntities/BedEntity.h b/src/BlockEntities/BedEntity.h index 0a5d25767..fe5970681 100644 --- a/src/BlockEntities/BedEntity.h +++ b/src/BlockEntities/BedEntity.h @@ -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; diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp index 7e7f5eaab..44d5e2d19 100644 --- a/src/BlockEntities/BlockEntity.cpp +++ b/src/BlockEntities/BlockEntity.cpp @@ -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: diff --git a/src/BlockEntities/BlockEntity.h b/src/BlockEntities/BlockEntity.h index 474192107..6232eb1ef 100644 --- a/src/BlockEntities/BlockEntity.h +++ b/src/BlockEntities/BlockEntity.h @@ -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. */ diff --git a/src/BlockEntities/BlockEntityWithItems.cpp b/src/BlockEntities/BlockEntityWithItems.cpp index 9821bd539..5a52b9767 100644 --- a/src/BlockEntities/BlockEntityWithItems.cpp +++ b/src/BlockEntities/BlockEntityWithItems.cpp @@ -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); diff --git a/src/BlockEntities/BlockEntityWithItems.h b/src/BlockEntities/BlockEntityWithItems.h index 2a809bb35..74e02693d 100644 --- a/src/BlockEntities/BlockEntityWithItems.h +++ b/src/BlockEntities/BlockEntityWithItems.h @@ -44,6 +44,7 @@ public: // tolua_export ); // cBlockEntity overrides: + virtual cItems ConvertToPickups() const override; virtual void CopyFrom(const cBlockEntity & a_Src) override; // tolua_begin diff --git a/src/BlockEntities/EnchantingTableEntity.cpp b/src/BlockEntities/EnchantingTableEntity.cpp index 55124e7d3..81c42caaf 100644 --- a/src/BlockEntities/EnchantingTableEntity.cpp +++ b/src/BlockEntities/EnchantingTableEntity.cpp @@ -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); diff --git a/src/BlockEntities/EnchantingTableEntity.h b/src/BlockEntities/EnchantingTableEntity.h index f10fa3c87..d5e947838 100644 --- a/src/BlockEntities/EnchantingTableEntity.h +++ b/src/BlockEntities/EnchantingTableEntity.h @@ -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; diff --git a/src/BlockEntities/JukeboxEntity.cpp b/src/BlockEntities/JukeboxEntity.cpp index f5380e789..11d50b19a 100644 --- a/src/BlockEntities/JukeboxEntity.cpp +++ b/src/BlockEntities/JukeboxEntity.cpp @@ -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(); } diff --git a/src/BlockEntities/MobHeadEntity.cpp b/src/BlockEntities/MobHeadEntity.cpp index 36402f59f..eee6cf9c1 100644 --- a/src/BlockEntities/MobHeadEntity.cpp +++ b/src/BlockEntities/MobHeadEntity.cpp @@ -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); diff --git a/src/BlockEntities/MobHeadEntity.h b/src/BlockEntities/MobHeadEntity.h index 5c41b40d8..fe82a1027 100644 --- a/src/BlockEntities/MobHeadEntity.h +++ b/src/BlockEntities/MobHeadEntity.h @@ -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; diff --git a/src/Blocks/BlockAnvil.h b/src/Blocks/BlockAnvil.h index c3a7f5745..8eaed870c 100644 --- a/src/Blocks/BlockAnvil.h +++ b/src/Blocks/BlockAnvil.h @@ -21,7 +21,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { return cItem(m_BlockType, 1, a_BlockMeta >> 2); } diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index 0277f522c..fb6bb29c7 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -168,14 +168,10 @@ void cBlockBedHandler::OnPlacedByPlayer(cChunkInterface & a_ChunkInterface, cWor -cItems cBlockBedHandler::ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const +cItems cBlockBedHandler::ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const { - short color = E_META_WOOL_RED; - if (a_BlockEntity != nullptr) - { - color = reinterpret_cast<cBedEntity *>(a_BlockEntity)->GetColor(); - } - return cItem(E_ITEM_BED, 1, color); + // Drops handled by the block entity: + return {}; } diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h index aacd26e73..8aac898df 100644 --- a/src/Blocks/BlockBed.h +++ b/src/Blocks/BlockBed.h @@ -67,12 +67,7 @@ private: const Vector3i a_CursorPos ) const override; - virtual cItems ConvertToPickups( - NIBBLETYPE a_BlockMeta, - cBlockEntity * a_BlockEntity, - const cEntity * a_Digger, - const cItem * a_Tool - ) const override; + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override; virtual void OnPlacedByPlayer( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, diff --git a/src/Blocks/BlockBigFlower.h b/src/Blocks/BlockBigFlower.h index cb2053c77..848cdce16 100644 --- a/src/Blocks/BlockBigFlower.h +++ b/src/Blocks/BlockBigFlower.h @@ -47,7 +47,7 @@ private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { if (IsMetaTopPart(a_BlockMeta)) { diff --git a/src/Blocks/BlockBookShelf.h b/src/Blocks/BlockBookShelf.h index 28994c009..dcc29eab0 100644 --- a/src/Blocks/BlockBookShelf.h +++ b/src/Blocks/BlockBookShelf.h @@ -15,7 +15,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { if (ToolHasSilkTouch(a_Tool)) { diff --git a/src/Blocks/BlockBrewingStand.h b/src/Blocks/BlockBrewingStand.h index e23a60b67..27ba33ca7 100644 --- a/src/Blocks/BlockBrewingStand.h +++ b/src/Blocks/BlockBrewingStand.h @@ -1,7 +1,6 @@ #pragma once -#include "../BlockEntities/BrewingstandEntity.h" #include "Mixins.h" @@ -19,15 +18,9 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { - cItems res(cItem(E_ITEM_BREWING_STAND, 1)); // We have to drop the item form of a brewing stand - if (a_BlockEntity != nullptr) - { - auto be = static_cast<cBrewingstandEntity *>(a_BlockEntity); - res.AddItemGrid(be->GetContents()); - } - return res; + return cItem(E_ITEM_BREWING_STAND); // We have to drop the item form of a brewing stand } diff --git a/src/Blocks/BlockCake.h b/src/Blocks/BlockCake.h index 089dc58bd..639015df2 100644 --- a/src/Blocks/BlockCake.h +++ b/src/Blocks/BlockCake.h @@ -49,7 +49,7 @@ private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // Give nothing return {}; diff --git a/src/Blocks/BlockCauldron.h b/src/Blocks/BlockCauldron.h index b8cd9081c..f5471ded7 100644 --- a/src/Blocks/BlockCauldron.h +++ b/src/Blocks/BlockCauldron.h @@ -19,7 +19,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { return cItem(E_ITEM_CAULDRON, 1, 0); } diff --git a/src/Blocks/BlockChest.h b/src/Blocks/BlockChest.h index 122a345ca..e3a6fb623 100644 --- a/src/Blocks/BlockChest.h +++ b/src/Blocks/BlockChest.h @@ -1,7 +1,6 @@ #pragma once -#include "../BlockEntities/ChestEntity.h" #include "../BlockArea.h" #include "../Entities/Player.h" #include "Mixins.h" @@ -11,9 +10,9 @@ class cBlockChestHandler : - public cYawRotator<cContainerEntityHandler<cBlockEntityHandler>, 0x07, 0x03, 0x04, 0x02, 0x05> + public cYawRotator<cClearMetaOnDrop<cBlockEntityHandler>, 0x07, 0x03, 0x04, 0x02, 0x05> { - using Super = cYawRotator<cContainerEntityHandler<cBlockEntityHandler>, 0x07, 0x03, 0x04, 0x02, 0x05>; + using Super = cYawRotator<cClearMetaOnDrop<cBlockEntityHandler>, 0x07, 0x03, 0x04, 0x02, 0x05>; public: diff --git a/src/Blocks/BlockCobWeb.h b/src/Blocks/BlockCobWeb.h index 661880141..c8b0433d4 100644 --- a/src/Blocks/BlockCobWeb.h +++ b/src/Blocks/BlockCobWeb.h @@ -18,7 +18,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // Silk touch gives cobweb, anything else gives just string: if (ToolHasSilkTouch(a_Tool)) diff --git a/src/Blocks/BlockCocoaPod.h b/src/Blocks/BlockCocoaPod.h index 6cf2e0e5d..557367dcf 100644 --- a/src/Blocks/BlockCocoaPod.h +++ b/src/Blocks/BlockCocoaPod.h @@ -70,7 +70,7 @@ private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // If fully grown, give 3 items, otherwise just one: auto growState = a_BlockMeta >> 2; diff --git a/src/Blocks/BlockCommandBlock.h b/src/Blocks/BlockCommandBlock.h index 6d4aad40a..03b20aba2 100644 --- a/src/Blocks/BlockCommandBlock.h +++ b/src/Blocks/BlockCommandBlock.h @@ -18,7 +18,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // Don't allow as a pickup: return {}; diff --git a/src/Blocks/BlockComparator.h b/src/Blocks/BlockComparator.h index 53edaca50..d20c70aeb 100644 --- a/src/Blocks/BlockComparator.h +++ b/src/Blocks/BlockComparator.h @@ -182,7 +182,7 @@ private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { return cItem(E_ITEM_COMPARATOR, 1, 0); } diff --git a/src/Blocks/BlockCrops.h b/src/Blocks/BlockCrops.h index 7208c8ff8..1d612e685 100644 --- a/src/Blocks/BlockCrops.h +++ b/src/Blocks/BlockCrops.h @@ -21,7 +21,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { auto & rand = GetRandomProvider(); diff --git a/src/Blocks/BlockDeadBush.h b/src/Blocks/BlockDeadBush.h index 0653f538b..f7ae8bb96 100644 --- a/src/Blocks/BlockDeadBush.h +++ b/src/Blocks/BlockDeadBush.h @@ -52,7 +52,7 @@ private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // If cutting down with shears, drop self: if ((a_Tool != nullptr) && (a_Tool->m_ItemType == E_ITEM_SHEARS)) diff --git a/src/Blocks/BlockDirt.h b/src/Blocks/BlockDirt.h index 860bc66c8..fade1f992 100644 --- a/src/Blocks/BlockDirt.h +++ b/src/Blocks/BlockDirt.h @@ -18,7 +18,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { if (a_BlockMeta == E_META_DIRT_COARSE) { diff --git a/src/Blocks/BlockDoor.h b/src/Blocks/BlockDoor.h index ff3757d79..36dc788aa 100644 --- a/src/Blocks/BlockDoor.h +++ b/src/Blocks/BlockDoor.h @@ -196,7 +196,7 @@ private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { switch (m_BlockType) { diff --git a/src/Blocks/BlockDropSpenser.h b/src/Blocks/BlockDropSpenser.h index fa591bf93..793cc0be9 100644 --- a/src/Blocks/BlockDropSpenser.h +++ b/src/Blocks/BlockDropSpenser.h @@ -5,8 +5,6 @@ #pragma once -#include "../Blocks/BlockPiston.h" -#include "../BlockEntities/DropSpenserEntity.h" #include "Mixins.h" @@ -14,9 +12,9 @@ class cBlockDropSpenserHandler : - public cPitchYawRotator<cBlockEntityHandler, 0x07, 0x03, 0x04, 0x02, 0x05, 0x01, 0x00> + public cPitchYawRotator<cClearMetaOnDrop<cBlockEntityHandler>, 0x07, 0x03, 0x04, 0x02, 0x05, 0x01, 0x00> { - using Super = cPitchYawRotator<cBlockEntityHandler, 0x07, 0x03, 0x04, 0x02, 0x05, 0x01, 0x00>; + using Super = cPitchYawRotator<cClearMetaOnDrop<cBlockEntityHandler>, 0x07, 0x03, 0x04, 0x02, 0x05, 0x01, 0x00>; public: @@ -24,28 +22,9 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override - { - cItems res(cItem(m_BlockType, 1)); - if (a_BlockEntity != nullptr) - { - auto be = static_cast<cDropSpenserEntity *>(a_BlockEntity); - res.AddItemGrid(be->GetContents()); - } - return res; - } - - - - - virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override { UNUSED(a_Meta); return 11; } } ; - - - - diff --git a/src/Blocks/BlockEnchantingTable.h b/src/Blocks/BlockEnchantingTable.h index a03ae7a2a..5edf9fdda 100644 --- a/src/Blocks/BlockEnchantingTable.h +++ b/src/Blocks/BlockEnchantingTable.h @@ -62,17 +62,10 @@ private: } - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { - if ((a_BlockEntity == nullptr) || (a_BlockEntity->GetBlockType() != E_BLOCK_ENCHANTMENT_TABLE)) - { - return {}; - } - - auto & EnchantingTable = static_cast<const cEnchantingTableEntity &>(*a_BlockEntity); - cItem Item = cItem(E_BLOCK_ENCHANTMENT_TABLE); - Item.m_CustomName = EnchantingTable.GetCustomName(); - return Item; + // Drops handled by the block entity: + return {}; } diff --git a/src/Blocks/BlockEnderchest.h b/src/Blocks/BlockEnderchest.h index 93009da64..fe5835f9a 100644 --- a/src/Blocks/BlockEnderchest.h +++ b/src/Blocks/BlockEnderchest.h @@ -1,7 +1,6 @@ #pragma once -#include "BlockEntity.h" #include "Mixins.h" @@ -18,7 +17,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // Only drop something when mined with a pickaxe: if ( @@ -29,13 +28,12 @@ private: // Only drop self when mined with a silk-touch pickaxe: if (a_Tool->m_Enchantments.GetLevel(cEnchantments::enchSilkTouch) > 0) { - return cItem(E_BLOCK_ENDER_CHEST, 1, 0); - } - else - { - return cItem(E_BLOCK_OBSIDIAN, 8, 0); + return cItem(E_BLOCK_ENDER_CHEST); } + + return cItem(E_BLOCK_OBSIDIAN, 8); } + return {}; } diff --git a/src/Blocks/BlockEntity.h b/src/Blocks/BlockEntity.h index b1aee7526..4b9de1f12 100644 --- a/src/Blocks/BlockEntity.h +++ b/src/Blocks/BlockEntity.h @@ -4,7 +4,6 @@ #include "BlockHandler.h" #include "ChunkInterface.h" #include "../Item.h" -#include "../BlockEntities/BlockEntityWithItems.h" @@ -44,37 +43,3 @@ private: return true; } }; - - - - - -/** Wrapper for blocks that have a cBlockEntityWithItems descendant attached to them. -When converting to pickups, drops self with meta reset to zero, and adds the container contents. */ -template <typename Base = cBlockEntityHandler> -class cContainerEntityHandler: - public Base -{ -public: - - constexpr cContainerEntityHandler(BLOCKTYPE a_BlockType): - Base(a_BlockType) - { - } - -private: - - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override - { - // Reset meta to 0 - cItems res(cItem(Base::m_BlockType, 1, 0)); - - // Drop the contents: - if (a_BlockEntity != nullptr) - { - auto container = static_cast<cBlockEntityWithItems *>(a_BlockEntity); - res.AddItemGrid(container->GetContents()); - } - return res; - } -}; diff --git a/src/Blocks/BlockFarmland.h b/src/Blocks/BlockFarmland.h index c6340f58a..27ec7e89c 100644 --- a/src/Blocks/BlockFarmland.h +++ b/src/Blocks/BlockFarmland.h @@ -27,7 +27,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { return cItem(E_BLOCK_DIRT, 1, 0); } diff --git a/src/Blocks/BlockFire.h b/src/Blocks/BlockFire.h index eff29d03e..4227c67a0 100644 --- a/src/Blocks/BlockFire.h +++ b/src/Blocks/BlockFire.h @@ -52,7 +52,7 @@ private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // No pickups from this block return {}; diff --git a/src/Blocks/BlockFlower.h b/src/Blocks/BlockFlower.h index 527be7d5d..b5bc6f957 100644 --- a/src/Blocks/BlockFlower.h +++ b/src/Blocks/BlockFlower.h @@ -18,7 +18,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { NIBBLETYPE meta = a_BlockMeta & 0x7; return cItem(m_BlockType, 1, meta); diff --git a/src/Blocks/BlockFlowerPot.h b/src/Blocks/BlockFlowerPot.h index d91347654..d5e37c243 100644 --- a/src/Blocks/BlockFlowerPot.h +++ b/src/Blocks/BlockFlowerPot.h @@ -1,8 +1,6 @@ #pragma once -#include "BlockEntity.h" - @@ -18,7 +16,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { return cItem(E_ITEM_FLOWER_POT, 1, 0); } diff --git a/src/Blocks/BlockFluid.h b/src/Blocks/BlockFluid.h index b7510b9a9..05a7c0d62 100644 --- a/src/Blocks/BlockFluid.h +++ b/src/Blocks/BlockFluid.h @@ -18,7 +18,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // No pickups return {}; diff --git a/src/Blocks/BlockFurnace.h b/src/Blocks/BlockFurnace.h index 781843f5a..2c88cfafd 100644 --- a/src/Blocks/BlockFurnace.h +++ b/src/Blocks/BlockFurnace.h @@ -1,8 +1,6 @@ #pragma once -#include "../Blocks/BlockPiston.h" -#include "../BlockEntities/FurnaceEntity.h" #include "Mixins.h" @@ -19,15 +17,9 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { - cItems res(cItem(E_BLOCK_FURNACE, 1)); // We can't drop a lit furnace - if (a_BlockEntity != nullptr) - { - auto be = static_cast<cFurnaceEntity *>(a_BlockEntity); - res.AddItemGrid(be->GetContents()); - } - return res; + return cItem(E_BLOCK_FURNACE); // We can't drop a lit furnace } diff --git a/src/Blocks/BlockGlass.h b/src/Blocks/BlockGlass.h index 5269402d4..6dc82c1a5 100644 --- a/src/Blocks/BlockGlass.h +++ b/src/Blocks/BlockGlass.h @@ -16,7 +16,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // Only drop self when mined with silk-touch: if (ToolHasSilkTouch(a_Tool)) diff --git a/src/Blocks/BlockGlowstone.h b/src/Blocks/BlockGlowstone.h index 11aa5e379..1e187084d 100644 --- a/src/Blocks/BlockGlowstone.h +++ b/src/Blocks/BlockGlowstone.h @@ -16,7 +16,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // Drop self only when using silk-touch: if (ToolHasSilkTouch(a_Tool)) diff --git a/src/Blocks/BlockGrass.h b/src/Blocks/BlockGrass.h index 65a3f5908..1292ebfc2 100644 --- a/src/Blocks/BlockGrass.h +++ b/src/Blocks/BlockGrass.h @@ -31,7 +31,7 @@ private: DieInDarkness }; - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { if (!ToolHasSilkTouch(a_Tool)) { diff --git a/src/Blocks/BlockGravel.h b/src/Blocks/BlockGravel.h index 6e26c92ed..972dea4e4 100644 --- a/src/Blocks/BlockGravel.h +++ b/src/Blocks/BlockGravel.h @@ -16,7 +16,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // TODO: Handle the Fortune and Silk touch enchantments here if (GetRandomProvider().RandBool(0.10)) diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index f2eb4f966..371f34ec0 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -522,21 +522,13 @@ void cBlockHandler::NeighborChanged(cChunkInterface & a_ChunkInterface, Vector3i -cItems cBlockHandler::ConvertToPickups( - NIBBLETYPE a_BlockMeta, - cBlockEntity * a_BlockEntity, - const cEntity * a_Digger, - const cItem * a_Tool -) const +cItems cBlockHandler::ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const { - UNUSED(a_BlockEntity); UNUSED(a_Digger); UNUSED(a_Tool); // Add self: - cItems res; - res.push_back(cItem(m_BlockType, 1, a_BlockMeta)); - return res; + return cItem(m_BlockType, 1, a_BlockMeta); } diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index 87b259d54..91362960e 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -146,16 +146,10 @@ public: /** Returns the pickups that would result if the block was mined by a_Digger using a_Tool. Doesn't do any actual block change / mining, only calculates the pickups. - a_BlockEntity is the block entity present at the block, if any, nullptr if none. a_Digger is the entity that caused the conversion, usually the player digging. a_Tool is the tool used for the digging. The default implementation drops a single item created from m_BlockType and the current meta. */ - virtual cItems ConvertToPickups( - NIBBLETYPE a_BlockMeta, - cBlockEntity * a_BlockEntity, - const cEntity * a_Digger = nullptr, - const cItem * a_Tool = nullptr - ) const; + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger = nullptr, const cItem * a_Tool = nullptr) const; /** Checks if the block can stay at the specified relative coords in the chunk */ virtual bool CanBeAt( diff --git a/src/Blocks/BlockHopper.h b/src/Blocks/BlockHopper.h index d05bb3bf8..7380b8d34 100644 --- a/src/Blocks/BlockHopper.h +++ b/src/Blocks/BlockHopper.h @@ -8,9 +8,9 @@ class cBlockHopperHandler : - public cPitchYawRotator<cContainerEntityHandler<cBlockEntityHandler>> + public cPitchYawRotator<cClearMetaOnDrop<cBlockEntityHandler>> { - using Super = cPitchYawRotator<cContainerEntityHandler<cBlockEntityHandler>>; + using Super = cPitchYawRotator<cClearMetaOnDrop<cBlockEntityHandler>>; public: diff --git a/src/Blocks/BlockIce.h b/src/Blocks/BlockIce.h index 10cd71b8a..12505b3fd 100644 --- a/src/Blocks/BlockIce.h +++ b/src/Blocks/BlockIce.h @@ -18,7 +18,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // Only drop self when using silk-touch: if (ToolHasSilkTouch(a_Tool)) diff --git a/src/Blocks/BlockLeaves.h b/src/Blocks/BlockLeaves.h index 647f96211..c08f1b6bb 100644 --- a/src/Blocks/BlockLeaves.h +++ b/src/Blocks/BlockLeaves.h @@ -93,7 +93,7 @@ private: return false; } - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // If breaking with shears, drop self: if ((a_Tool != nullptr) && (a_Tool->m_ItemType == E_ITEM_SHEARS)) diff --git a/src/Blocks/BlockLever.h b/src/Blocks/BlockLever.h index 14389add0..d3b03bbda 100644 --- a/src/Blocks/BlockLever.h +++ b/src/Blocks/BlockLever.h @@ -45,7 +45,7 @@ private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // Reset meta to zero: return cItem(E_BLOCK_LEVER, 1, 0); diff --git a/src/Blocks/BlockMelon.h b/src/Blocks/BlockMelon.h index f5230b7e5..09841e642 100644 --- a/src/Blocks/BlockMelon.h +++ b/src/Blocks/BlockMelon.h @@ -18,7 +18,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { return cItem(E_ITEM_MELON_SLICE, GetRandomProvider().RandInt<char>(3, 7), 0); } diff --git a/src/Blocks/BlockMobHead.h b/src/Blocks/BlockMobHead.h index 71fb6c958..fb81a07d8 100644 --- a/src/Blocks/BlockMobHead.h +++ b/src/Blocks/BlockMobHead.h @@ -2,7 +2,6 @@ #pragma once #include "BlockEntity.h" -#include "../BlockEntities/MobHeadEntity.h" @@ -19,14 +18,10 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { - if ((a_BlockEntity == nullptr) || (a_BlockEntity->GetBlockType() != E_BLOCK_HEAD)) - { - return {}; - } - auto mobHeadEntity = static_cast<cMobHeadEntity *>(a_BlockEntity); - return cItem(E_ITEM_HEAD, 1, static_cast<short>(mobHeadEntity->GetType())); + // Drops handled by the block entity: + return {}; } diff --git a/src/Blocks/BlockMobSpawner.h b/src/Blocks/BlockMobSpawner.h index 5e3592f84..b9d8cd29f 100644 --- a/src/Blocks/BlockMobSpawner.h +++ b/src/Blocks/BlockMobSpawner.h @@ -44,7 +44,7 @@ private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // No pickups return {}; diff --git a/src/Blocks/BlockMycelium.h b/src/Blocks/BlockMycelium.h index 322c9d4d5..bf489eed7 100644 --- a/src/Blocks/BlockMycelium.h +++ b/src/Blocks/BlockMycelium.h @@ -18,7 +18,7 @@ private: // TODO: Add Mycel Spread - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { return cItem(E_BLOCK_DIRT, 1, 0); } diff --git a/src/Blocks/BlockNetherWart.h b/src/Blocks/BlockNetherWart.h index c1226224f..590a55772 100644 --- a/src/Blocks/BlockNetherWart.h +++ b/src/Blocks/BlockNetherWart.h @@ -19,7 +19,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { if (a_BlockMeta == 0x03) { diff --git a/src/Blocks/BlockOre.h b/src/Blocks/BlockOre.h index 5dbeac268..98db5198d 100644 --- a/src/Blocks/BlockOre.h +++ b/src/Blocks/BlockOre.h @@ -18,7 +18,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // If using silk-touch, drop self rather than the resource: if (ToolHasSilkTouch(a_Tool)) diff --git a/src/Blocks/BlockPiston.cpp b/src/Blocks/BlockPiston.cpp index 87b5c1480..7e6ff5e3f 100644 --- a/src/Blocks/BlockPiston.cpp +++ b/src/Blocks/BlockPiston.cpp @@ -339,7 +339,7 @@ void cBlockPistonHeadHandler::OnBroken( -cItems cBlockPistonHeadHandler::ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const +cItems cBlockPistonHeadHandler::ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const { // Give a normal\sticky piston base, not piston extension // With 1.7, the item forms of these technical blocks have been removed, so giving someone this will crash their client... diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h index f8d155196..cbde5967e 100644 --- a/src/Blocks/BlockPiston.h +++ b/src/Blocks/BlockPiston.h @@ -159,5 +159,5 @@ public: BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta ) const override; - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override; + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override; } ; diff --git a/src/Blocks/BlockPortal.h b/src/Blocks/BlockPortal.h index e3970bbbb..64815f38f 100644 --- a/src/Blocks/BlockPortal.h +++ b/src/Blocks/BlockPortal.h @@ -40,7 +40,7 @@ private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // No pickups return {}; diff --git a/src/Blocks/BlockRedstone.h b/src/Blocks/BlockRedstone.h index 14af7fe8a..39fdf7d2d 100644 --- a/src/Blocks/BlockRedstone.h +++ b/src/Blocks/BlockRedstone.h @@ -49,7 +49,7 @@ private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { return cItem(E_ITEM_REDSTONE_DUST, 1, 0); } diff --git a/src/Blocks/BlockRedstoneLamp.h b/src/Blocks/BlockRedstoneLamp.h index 1f3016e40..3382f543b 100644 --- a/src/Blocks/BlockRedstoneLamp.h +++ b/src/Blocks/BlockRedstoneLamp.h @@ -16,7 +16,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // Always drop the Off variant: return(cItem(E_BLOCK_REDSTONE_LAMP_OFF, 1, 0)); diff --git a/src/Blocks/BlockRedstoneRepeater.h b/src/Blocks/BlockRedstoneRepeater.h index 332f39cea..eccb497e6 100644 --- a/src/Blocks/BlockRedstoneRepeater.h +++ b/src/Blocks/BlockRedstoneRepeater.h @@ -135,7 +135,7 @@ private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { return cItem(E_ITEM_REDSTONE_REPEATER, 1, 0); } diff --git a/src/Blocks/BlockRedstoneTorch.h b/src/Blocks/BlockRedstoneTorch.h index d26b0bd8a..9680ca0dd 100644 --- a/src/Blocks/BlockRedstoneTorch.h +++ b/src/Blocks/BlockRedstoneTorch.h @@ -18,7 +18,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // Always drop the ON torch, meta 0 return cItem(E_BLOCK_REDSTONE_TORCH_ON, 1, 0); diff --git a/src/Blocks/BlockSapling.h b/src/Blocks/BlockSapling.h index 3ee48b1ed..3bce74fb1 100644 --- a/src/Blocks/BlockSapling.h +++ b/src/Blocks/BlockSapling.h @@ -19,7 +19,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // The low 3 bits store the sapling type; bit 0x08 is the growth timer (not used in pickups) return cItem(m_BlockType, 1, a_BlockMeta & 0x07); diff --git a/src/Blocks/BlockSeaLantern.h b/src/Blocks/BlockSeaLantern.h index 2ff100d85..9804642ca 100644 --- a/src/Blocks/BlockSeaLantern.h +++ b/src/Blocks/BlockSeaLantern.h @@ -18,7 +18,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // Drop self only when using silk-touch: if (ToolHasSilkTouch(a_Tool)) diff --git a/src/Blocks/BlockSideways.h b/src/Blocks/BlockSideways.h index c846c5543..95619f564 100644 --- a/src/Blocks/BlockSideways.h +++ b/src/Blocks/BlockSideways.h @@ -40,7 +40,7 @@ private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // Reset the orientation part of meta, keep the sub-type part of meta return cItem(m_BlockType, 1, a_BlockMeta & 0x03); diff --git a/src/Blocks/BlockSignPost.h b/src/Blocks/BlockSignPost.h index 717a85ecf..8f0a1c157 100644 --- a/src/Blocks/BlockSignPost.h +++ b/src/Blocks/BlockSignPost.h @@ -33,7 +33,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { return cItem(E_ITEM_SIGN, 1, 0); } diff --git a/src/Blocks/BlockSlab.h b/src/Blocks/BlockSlab.h index 0f6b0442f..2de4922b8 100644 --- a/src/Blocks/BlockSlab.h +++ b/src/Blocks/BlockSlab.h @@ -39,7 +39,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // Reset the "top half" flag: return cItem(m_BlockType, 1, a_BlockMeta & 0x07); @@ -246,7 +246,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { BLOCKTYPE Block = GetSingleSlabType(m_BlockType); return cItem(Block, 2, a_BlockMeta & 0x7); diff --git a/src/Blocks/BlockSnow.h b/src/Blocks/BlockSnow.h index 527d2c3b4..43e341e0c 100644 --- a/src/Blocks/BlockSnow.h +++ b/src/Blocks/BlockSnow.h @@ -81,7 +81,7 @@ private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // No drop unless dug up with a shovel if ((a_Tool == nullptr) || !ItemCategory::IsShovel(a_Tool->m_ItemType)) diff --git a/src/Blocks/BlockStems.h b/src/Blocks/BlockStems.h index 1742fe7e4..dc30fa6ec 100644 --- a/src/Blocks/BlockStems.h +++ b/src/Blocks/BlockStems.h @@ -22,7 +22,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { return cItem(StemPickupType, 1, 0); } diff --git a/src/Blocks/BlockStone.h b/src/Blocks/BlockStone.h index 910473623..846ddf5df 100644 --- a/src/Blocks/BlockStone.h +++ b/src/Blocks/BlockStone.h @@ -17,7 +17,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // Convert stone to cobblestone, unless using silk-touch: if ( diff --git a/src/Blocks/BlockSugarcane.h b/src/Blocks/BlockSugarcane.h index 49cf9db07..24c08db9f 100644 --- a/src/Blocks/BlockSugarcane.h +++ b/src/Blocks/BlockSugarcane.h @@ -18,7 +18,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { return cItem(E_ITEM_SUGARCANE, 1, 0); } diff --git a/src/Blocks/BlockTallGrass.h b/src/Blocks/BlockTallGrass.h index 2ae6e1910..f0da32cf5 100644 --- a/src/Blocks/BlockTallGrass.h +++ b/src/Blocks/BlockTallGrass.h @@ -29,7 +29,7 @@ private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // If using shears, drop self: if ((a_Tool != nullptr) && (a_Tool->m_ItemType == E_ITEM_SHEARS)) diff --git a/src/Blocks/BlockTripwire.h b/src/Blocks/BlockTripwire.h index b818a3628..7fbcc678d 100644 --- a/src/Blocks/BlockTripwire.h +++ b/src/Blocks/BlockTripwire.h @@ -18,7 +18,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { return cItem(E_ITEM_STRING, 1, 0); } diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h index b652a2498..5d4da0319 100644 --- a/src/Blocks/BlockVine.h +++ b/src/Blocks/BlockVine.h @@ -46,7 +46,7 @@ private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // Only drops self when using shears, otherwise drops nothing: if ((a_Tool == nullptr) || (a_Tool->m_ItemType != E_ITEM_SHEARS)) diff --git a/src/Blocks/BlockWallSign.h b/src/Blocks/BlockWallSign.h index 1e9ea2e1f..d4b1ca59d 100644 --- a/src/Blocks/BlockWallSign.h +++ b/src/Blocks/BlockWallSign.h @@ -38,7 +38,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { return cItem(E_ITEM_SIGN, 1, 0); } diff --git a/src/Blocks/Mixins.h b/src/Blocks/Mixins.h index 040969ddb..a5c3e751e 100644 --- a/src/Blocks/Mixins.h +++ b/src/Blocks/Mixins.h @@ -38,7 +38,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // Don't drop anything: return {}; @@ -63,7 +63,7 @@ public: private: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override { // Reset the meta to zero: return cItem(this->m_BlockType); diff --git a/src/Chunk.cpp b/src/Chunk.cpp index a2dd73b51..8f72d7c0f 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -930,20 +930,34 @@ void cChunk::ApplyWeatherToTop() cItems cChunk::PickupsFromBlock(Vector3i a_RelPos, const cEntity * a_Digger, const cItem * a_Tool) { - BLOCKTYPE blockType; - NIBBLETYPE blockMeta; - GetBlockTypeMeta(a_RelPos, blockType, blockMeta); - auto blockEntity = GetBlockEntityRel(a_RelPos); - cItems pickups (0); - auto toolHandler = a_Tool ? a_Tool->GetHandler() : cItemHandler::GetItemHandler(E_ITEM_EMPTY); - auto canHarvestBlock = toolHandler->CanHarvestBlock(blockType); - if (canHarvestBlock) - { - pickups = cBlockHandler::For(blockType).ConvertToPickups(blockMeta, blockEntity, a_Digger, a_Tool); - } - auto absPos = RelativeToAbsolute(a_RelPos); - cRoot::Get()->GetPluginManager()->CallHookBlockToPickups(*m_World, absPos, blockType, blockMeta, blockEntity, a_Digger, a_Tool, pickups); - return pickups; + BLOCKTYPE BlockType; + NIBBLETYPE BlockMeta; + GetBlockTypeMeta(a_RelPos, BlockType, BlockMeta); + + cItems Pickups; + const auto BlockEntity = GetBlockEntityRel(a_RelPos); + + const auto ToolHandler = (a_Tool != nullptr) ? a_Tool->GetHandler() : cItemHandler::GetItemHandler(E_ITEM_EMPTY); + if (ToolHandler->CanHarvestBlock(BlockType)) + { + Pickups = cBlockHandler::For(BlockType).ConvertToPickups(BlockMeta, a_Digger, a_Tool); + + if (BlockEntity != nullptr) + { + auto BlockEntityPickups = BlockEntity->ConvertToPickups(); + Pickups.insert(Pickups.end(), std::make_move_iterator(BlockEntityPickups.begin()), std::make_move_iterator(BlockEntityPickups.end())); + } + } + + // TODO: this should be in cWorld::DropBlockAsPickups. When it's here we can't check the return value and cancel spawning: + cRoot::Get()->GetPluginManager()->CallHookBlockToPickups( + *m_World, + cChunkDef::RelativeToAbsolute(a_RelPos, GetPos()), + BlockType, BlockMeta, BlockEntity, + a_Digger, a_Tool, Pickups + ); + + return Pickups; } diff --git a/src/Physics/Explodinator.cpp b/src/Physics/Explodinator.cpp index c6f254cfc..ca8b82b9b 100644 --- a/src/Physics/Explodinator.cpp +++ b/src/Physics/Explodinator.cpp @@ -140,10 +140,7 @@ namespace Explodinator else if (Random.RandBool(1.f / a_Power)) { const auto DestroyedMeta = a_Chunk.GetMeta(a_Position); - a_Chunk.GetWorld()->SpawnItemPickups( - cBlockHandler::For(DestroyedBlock).ConvertToPickups(DestroyedMeta, a_Chunk.GetBlockEntityRel(a_Position)), - Absolute - ); + a_Chunk.GetWorld()->SpawnItemPickups(cBlockHandler::For(DestroyedBlock).ConvertToPickups(DestroyedMeta), Absolute); } else if (a_Fiery && Random.RandBool(1.f / 3.f)) // 33% chance of starting fires if it can start fires { diff --git a/tests/Generating/Stubs.cpp b/tests/Generating/Stubs.cpp index f828b05ee..811809776 100644 --- a/tests/Generating/Stubs.cpp +++ b/tests/Generating/Stubs.cpp @@ -149,7 +149,7 @@ void cBlockHandler::NeighborChanged(cChunkInterface & a_ChunkInterface, Vector3i -cItems cBlockHandler::ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const +cItems cBlockHandler::ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const { return cItems(); } diff --git a/tests/LuaThreadStress/Stubs.cpp b/tests/LuaThreadStress/Stubs.cpp index 819c6b7ae..fe2687ef4 100644 --- a/tests/LuaThreadStress/Stubs.cpp +++ b/tests/LuaThreadStress/Stubs.cpp @@ -158,7 +158,7 @@ void cBlockHandler::NeighborChanged(cChunkInterface & a_ChunkInterface, Vector3i -cItems cBlockHandler::ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const +cItems cBlockHandler::ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const { return cItems(); } diff --git a/tests/SchematicFileSerializer/Stubs.cpp b/tests/SchematicFileSerializer/Stubs.cpp index 66d84ce06..96b8f9a8c 100644 --- a/tests/SchematicFileSerializer/Stubs.cpp +++ b/tests/SchematicFileSerializer/Stubs.cpp @@ -85,7 +85,7 @@ void cBlockHandler::NeighborChanged(cChunkInterface & a_ChunkInterface, Vector3i -cItems cBlockHandler::ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const +cItems cBlockHandler::ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const { return cItems(); } |