From 3ff57559e36d3254c64e334fbe3bdd47398fe16f Mon Sep 17 00:00:00 2001 From: x12xx12x <44411062+12xx12@users.noreply.github.com> Date: Thu, 2 Dec 2021 00:31:10 +0100 Subject: ItemHandler initialisation is a constant expression (#5344) * Transition to non-pointer item handler * That is my destructor - I decide when I leave this world * I declare your destruction private and you final --- src/Items/ItemThrowable.h | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'src/Items/ItemThrowable.h') diff --git a/src/Items/ItemThrowable.h b/src/Items/ItemThrowable.h index 606f655e9..ed4d73316 100644 --- a/src/Items/ItemThrowable.h +++ b/src/Items/ItemThrowable.h @@ -14,7 +14,7 @@ class cItemThrowableHandler: public: - cItemThrowableHandler(int a_ItemType, cProjectileEntity::eKind a_ProjectileKind, double a_SpeedCoeff): + constexpr cItemThrowableHandler(int a_ItemType, cProjectileEntity::eKind a_ProjectileKind, double a_SpeedCoeff): Super(a_ItemType), m_ProjectileKind(a_ProjectileKind), m_SpeedCoeff(a_SpeedCoeff) @@ -32,7 +32,7 @@ public: const cItem & a_HeldItem, const Vector3i a_ClickedBlockPos, eBlockFace a_ClickedBlockFace - ) override + ) const override { auto Pos = a_Player->GetThrowStartPos(); auto Speed = a_Player->GetLookVector() * m_SpeedCoeff; @@ -62,21 +62,23 @@ protected: /** The speed multiplier (to the player's normalized look vector) to set for the new projectile. */ double m_SpeedCoeff; + + ~cItemThrowableHandler() = default; } ; -class cItemEggHandler: +class cItemEggHandler final: public cItemThrowableHandler { using Super = cItemThrowableHandler; public: - cItemEggHandler(): - Super(E_ITEM_EGG, cProjectileEntity::pkEgg, 30) + constexpr cItemEggHandler(int a_ItemType): + Super(a_ItemType, cProjectileEntity::pkEgg, 30) { } } ; @@ -84,15 +86,15 @@ public: -class cItemSnowballHandler: +class cItemSnowballHandler final: public cItemThrowableHandler { using Super = cItemThrowableHandler; public: - cItemSnowballHandler(): - Super(E_ITEM_SNOWBALL, cProjectileEntity::pkSnowball, 30) + constexpr cItemSnowballHandler(int a_ItemType): + Super(a_ItemType, cProjectileEntity::pkSnowball, 30) { } } ; @@ -101,15 +103,15 @@ public: -class cItemEnderPearlHandler: +class cItemEnderPearlHandler final: public cItemThrowableHandler { using Super = cItemThrowableHandler; public: - cItemEnderPearlHandler(): - Super(E_ITEM_ENDER_PEARL, cProjectileEntity::pkEnderPearl, 30) + constexpr cItemEnderPearlHandler(int a_ItemType): + Super(a_ItemType, cProjectileEntity::pkEnderPearl, 30) { } } ; @@ -118,15 +120,15 @@ public: -class cItemBottleOEnchantingHandler: +class cItemBottleOEnchantingHandler final : public cItemThrowableHandler { using Super = cItemThrowableHandler; public: - cItemBottleOEnchantingHandler(): - Super(E_ITEM_BOTTLE_O_ENCHANTING, cProjectileEntity::pkExpBottle, 14) + constexpr cItemBottleOEnchantingHandler(int a_ItemType): + Super(a_ItemType, cProjectileEntity::pkExpBottle, 14) { } }; @@ -135,15 +137,15 @@ public: -class cItemFireworkHandler: +class cItemFireworkHandler final: public cItemThrowableHandler { using Super = cItemThrowableHandler; public: - cItemFireworkHandler(): - Super(E_ITEM_FIREWORK_ROCKET, cProjectileEntity::pkFirework, 0) + constexpr cItemFireworkHandler(int a_ItemType): + Super(a_ItemType, cProjectileEntity::pkFirework, 0) { } @@ -158,7 +160,7 @@ public: const cItem & a_HeldItem, const Vector3i a_ClickedBlockPos, eBlockFace a_ClickedBlockFace - ) override + ) const override { if (a_World->GetBlock(a_ClickedBlockPos) == E_BLOCK_AIR) { @@ -177,5 +179,4 @@ public: return true; } - }; -- cgit v1.2.3