From 68cced73afe546328cf94ed07c57deee47bfadec Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 20 Sep 2020 14:50:52 +0100 Subject: BlockHandler initialisation is a constant expression (#4891) * BlockHandler initialisation is a constant expression If we can't make it all namespaces, this is the next best I guess. + Tag handlers constexpr, const as needed + Inherit constructors * Privatise handler functions * More constexpr Co-authored-by: Alexander Harkness --- src/Blocks/BlockVine.h | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'src/Blocks/BlockVine.h') diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h index 25b6efe47..b652a2498 100644 --- a/src/Blocks/BlockVine.h +++ b/src/Blocks/BlockVine.h @@ -13,14 +13,9 @@ class cBlockVineHandler : public: - cBlockVineHandler(BLOCKTYPE a_BlockType): - Super(a_BlockType) - { - } - - - + using Super::Super; +private: virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, @@ -29,7 +24,7 @@ public: eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta - ) override + ) const override { // TODO: Disallow placement where the vine doesn't attach to something properly BLOCKTYPE BlockType = 0; @@ -51,7 +46,7 @@ public: - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) override + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, 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)) @@ -128,7 +123,7 @@ public: /** Returns the meta that has the maximum allowable sides of the vine, given the surroundings */ - NIBBLETYPE GetMaxMeta(cChunk & a_Chunk, Vector3i a_RelPos) + static NIBBLETYPE GetMaxMeta(cChunk & a_Chunk, Vector3i a_RelPos) { static const struct { @@ -162,7 +157,7 @@ public: - virtual void OnNeighborChanged(cChunkInterface & a_ChunkInterface, Vector3i a_BlockPos, eBlockFace a_WhichNeighbor) override + virtual void OnNeighborChanged(cChunkInterface & a_ChunkInterface, Vector3i a_BlockPos, eBlockFace a_WhichNeighbor) const override { a_ChunkInterface.DoWithChunkAt(a_BlockPos, [&](cChunk & a_Chunk) { @@ -203,7 +198,7 @@ public: - virtual bool DoesIgnoreBuildCollision(cChunkInterface & a_ChunkInterface, Vector3i a_Pos, cPlayer & a_Player, NIBBLETYPE a_Meta) override + virtual bool DoesIgnoreBuildCollision(cChunkInterface & a_ChunkInterface, Vector3i a_Pos, cPlayer & a_Player, NIBBLETYPE a_Meta) const override { return true; } @@ -212,7 +207,7 @@ public: - virtual bool DoesDropOnUnsuitable(void) override + virtual bool DoesDropOnUnsuitable(void) const override { return false; } @@ -227,7 +222,7 @@ public: cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, const Vector3i a_RelPos - ) override + ) const override { UNUSED(a_ChunkInterface); UNUSED(a_WorldInterface); @@ -256,7 +251,7 @@ public: - virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override + virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) const override { return ((a_Meta >> 1) | (a_Meta << 3)) & 0x0f; // Rotate bits to the right } @@ -265,7 +260,7 @@ public: - virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override + virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) const override { return ((a_Meta << 1) | (a_Meta >> 3)) & 0x0f; // Rotate bits to the left } @@ -274,7 +269,7 @@ public: - virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override + virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) const override { // Bits 2 and 4 stay, bits 1 and 3 swap return static_cast((a_Meta & 0x0a) | ((a_Meta & 0x01) << 2) | ((a_Meta & 0x04) >> 2)); @@ -284,7 +279,7 @@ public: - virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override + virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) const override { // Bits 1 and 3 stay, bits 2 and 4 swap return static_cast((a_Meta & 0x05) | ((a_Meta & 0x02) << 2) | ((a_Meta & 0x08) >> 2)); @@ -294,7 +289,7 @@ public: - virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override + virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override { UNUSED(a_Meta); return 7; -- cgit v1.2.3