summaryrefslogtreecommitdiffstats
path: root/src/Items/ItemSpawnEgg.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Items/ItemSpawnEgg.h')
-rw-r--r--src/Items/ItemSpawnEgg.h38
1 files changed, 25 insertions, 13 deletions
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)