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/BlockFence.h | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'src/Blocks/BlockFence.h') diff --git a/src/Blocks/BlockFence.h b/src/Blocks/BlockFence.h index 35a9b139a..13c4a6979 100644 --- a/src/Blocks/BlockFence.h +++ b/src/Blocks/BlockFence.h @@ -17,22 +17,17 @@ class cBlockFenceHandler: public: + using Super::Super; + +private: + // These are the min and max coordinates (X and Z) for a straight fence. // 0.4 and 0.6 are really just guesses, but they seem pretty good. // (0.4 to 0.6 is a fence that's 0.2 wide, down the center of the block) - const double MIN_COORD = 0.4; - const double MAX_COORD = 0.6; - - cBlockFenceHandler(BLOCKTYPE a_BlockType): - Super(a_BlockType) - { - } - - - - + static constexpr double MIN_COORD = 0.4; + static constexpr double MAX_COORD = 0.6; - virtual cBoundingBox GetPlacementCollisionBox(BLOCKTYPE a_XM, BLOCKTYPE a_XP, BLOCKTYPE a_YM, BLOCKTYPE a_YP, BLOCKTYPE a_ZM, BLOCKTYPE a_ZP) override + virtual cBoundingBox GetPlacementCollisionBox(BLOCKTYPE a_XM, BLOCKTYPE a_XP, BLOCKTYPE a_YM, BLOCKTYPE a_YP, BLOCKTYPE a_ZM, BLOCKTYPE a_ZP) const override { bool XMSolid = cBlockInfo::IsSolid(a_XM); bool XPSolid = cBlockInfo::IsSolid(a_XP); @@ -94,7 +89,7 @@ public: const Vector3i a_BlockPos, eBlockFace a_BlockFace, const Vector3i a_CursorPos - ) override + ) const override { auto LeashKnot = cLeashKnot::FindKnotAtPos(*a_Player.GetWorld(), a_BlockPos); auto KnotAlreadyExists = (LeashKnot != nullptr); @@ -140,7 +135,7 @@ public: cPlayer & a_Player, const Vector3i a_BlockPos, eBlockFace a_BlockFace - ) override + ) const override { a_WorldInterface.SendBlockTo(a_BlockPos, a_Player); } @@ -149,7 +144,7 @@ public: - virtual bool IsUseable(void) override + virtual bool IsUseable(void) const override { return true; } @@ -162,7 +157,7 @@ public: cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, Vector3i a_BlockPos, BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta - ) override + ) const override { // Destroy any leash knot tied to the fence: auto leashKnot = cLeashKnot::FindKnotAtPos(a_WorldInterface, a_BlockPos); -- cgit v1.2.3