2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ItemHandler.h"
|
|
|
|
#include "../World.h"
|
2013-08-19 05:39:13 -04:00
|
|
|
#include "../Entities/Player.h"
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cItemSpawnEggHandler : public cItemHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cItemSpawnEggHandler(int a_ItemType) :
|
|
|
|
cItemHandler(a_ItemType)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-04 13:59:05 -05:00
|
|
|
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
if (a_BlockFace < 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
|
|
|
|
|
2013-12-06 15:00:49 -05:00
|
|
|
if (a_BlockFace == BLOCK_FACE_YM)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
a_BlockY--;
|
|
|
|
}
|
|
|
|
|
2014-09-17 13:40:10 -04:00
|
|
|
eMonsterType MonsterType = ItemDamageToMonsterType(a_Item.m_ItemDamage);
|
2014-05-02 13:13:57 -04:00
|
|
|
if (
|
2014-09-17 13:40:10 -04:00
|
|
|
(MonsterType != mtInvalidType) && // Valid monster type
|
2014-05-02 13:13:57 -04:00
|
|
|
(a_World->SpawnMob(a_BlockX + 0.5, a_BlockY, a_BlockZ + 0.5, MonsterType) >= 0)) // Spawning succeeded
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2013-12-06 15:00:49 -05:00
|
|
|
if (!a_Player->IsGameModeCreative())
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
// The mob was spawned, "use" the item:
|
|
|
|
a_Player->GetInventory().RemoveOneEquippedItem();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-02 13:13:57 -04:00
|
|
|
|
|
|
|
|
|
|
|
/** Converts the Spawn egg item damage to the monster type to spawn.
|
|
|
|
Returns mtInvalidType for invalid damage values. */
|
2014-09-17 13:40:10 -04:00
|
|
|
static eMonsterType ItemDamageToMonsterType(short a_ItemDamage)
|
2014-05-02 13:13:57 -04:00
|
|
|
{
|
|
|
|
switch (a_ItemDamage)
|
|
|
|
{
|
2014-09-17 13:40:10 -04:00
|
|
|
case E_META_SPAWN_EGG_BAT: return mtBat;
|
|
|
|
case E_META_SPAWN_EGG_BLAZE: return mtBlaze;
|
|
|
|
case E_META_SPAWN_EGG_CAVE_SPIDER: return mtCaveSpider;
|
|
|
|
case E_META_SPAWN_EGG_CHICKEN: return mtChicken;
|
|
|
|
case E_META_SPAWN_EGG_COW: return mtCow;
|
|
|
|
case E_META_SPAWN_EGG_CREEPER: return mtCreeper;
|
|
|
|
case E_META_SPAWN_EGG_ENDERMAN: return mtEnderman;
|
|
|
|
case E_META_SPAWN_EGG_GHAST: return mtGhast;
|
|
|
|
case E_META_SPAWN_EGG_HORSE: return mtHorse;
|
|
|
|
case E_META_SPAWN_EGG_MAGMA_CUBE: return mtMagmaCube;
|
|
|
|
case E_META_SPAWN_EGG_MOOSHROOM: return mtMooshroom;
|
|
|
|
case E_META_SPAWN_EGG_OCELOT: return mtOcelot;
|
|
|
|
case E_META_SPAWN_EGG_PIG: return mtPig;
|
|
|
|
case E_META_SPAWN_EGG_SHEEP: return mtSheep;
|
|
|
|
case E_META_SPAWN_EGG_SILVERFISH: return mtSilverfish;
|
|
|
|
case E_META_SPAWN_EGG_SKELETON: return mtSkeleton;
|
|
|
|
case E_META_SPAWN_EGG_SLIME: return mtSlime;
|
|
|
|
case E_META_SPAWN_EGG_SPIDER: return mtSpider;
|
|
|
|
case E_META_SPAWN_EGG_SQUID: return mtSquid;
|
|
|
|
case E_META_SPAWN_EGG_VILLAGER: return mtVillager;
|
|
|
|
case E_META_SPAWN_EGG_WITCH: return mtWitch;
|
|
|
|
case E_META_SPAWN_EGG_WOLF: return mtWolf;
|
|
|
|
case E_META_SPAWN_EGG_ZOMBIE: return mtZombie;
|
|
|
|
case E_META_SPAWN_EGG_ZOMBIE_PIGMAN: return mtZombiePigman;
|
2014-05-02 13:13:57 -04:00
|
|
|
}
|
2014-09-17 13:40:10 -04:00
|
|
|
return mtInvalidType;
|
2014-05-02 13:13:57 -04:00
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|