From 487f9a2aa9b5497495cef1ac3b9c7a603e69f862 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Tue, 21 Apr 2020 22:19:22 +0200 Subject: Vector3 in Handlers (#4680) Refactored all cBlockHandler and cItemHandler descendants to use Vector3. --- src/Items/ItemSpawnEgg.h | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'src/Items/ItemSpawnEgg.h') diff --git a/src/Items/ItemSpawnEgg.h b/src/Items/ItemSpawnEgg.h index d57b93b2c..8408bd815 100644 --- a/src/Items/ItemSpawnEgg.h +++ b/src/Items/ItemSpawnEgg.h @@ -9,38 +9,47 @@ -class cItemSpawnEggHandler : public cItemHandler +class cItemSpawnEggHandler: + public cItemHandler { + using Super = cItemHandler; + public: - cItemSpawnEggHandler(int a_ItemType) : - cItemHandler(a_ItemType) - { + cItemSpawnEggHandler(int a_ItemType): + Super(a_ItemType) + { } + + virtual bool OnItemUse( - cWorld * a_World, cPlayer * a_Player, cBlockPluginInterface & a_PluginInterface, const cItem & a_Item, - int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace + cWorld * a_World, + cPlayer * a_Player, + cBlockPluginInterface & a_PluginInterface, + const cItem & a_HeldItem, + const Vector3i a_ClickedBlockPos, + eBlockFace a_ClickedBlockFace ) override { - if (a_BlockFace < 0) + // Must click a valid block: + if (a_ClickedBlockFace < 0) { return false; } - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); - - if (a_BlockFace == BLOCK_FACE_YM) + auto PlacementPos = AddFaceDirection(a_ClickedBlockPos, a_ClickedBlockFace); + if (a_ClickedBlockFace == BLOCK_FACE_YM) { - a_BlockY--; + PlacementPos.y--; } - eMonsterType MonsterType = ItemDamageToMonsterType(a_Item.m_ItemDamage); + auto MonsterType = ItemDamageToMonsterType(a_HeldItem.m_ItemDamage); if ( (MonsterType != mtInvalidType) && // Valid monster type - (a_World->SpawnMob(a_BlockX + 0.5, a_BlockY, a_BlockZ + 0.5, MonsterType, false) != cEntity::INVALID_ID)) // Spawning succeeded + (a_World->SpawnMob(PlacementPos.x + 0.5, PlacementPos.y, PlacementPos.z + 0.5, MonsterType, false) != cEntity::INVALID_ID)) // Spawning succeeded { if (!a_Player->IsGameModeCreative()) { @@ -54,6 +63,9 @@ public: } + + + /** Converts the Spawn egg item damage to the monster type to spawn. Returns mtInvalidType for invalid damage values. */ static eMonsterType ItemDamageToMonsterType(short a_ItemDamage) -- cgit v1.2.3