Cuberite
A lightweight, fast and extensible game server for Minecraft
Mooshroom.cpp
Go to the documentation of this file.
1 
2 #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
3 
4 #include "Mooshroom.h"
5 #include "../Entities/Player.h"
6 
7 
8 
9 
10 
12  Super("Mooshroom", mtMooshroom, "entity.cow.hurt", "entity.cow.death", "entity.cow.ambient", 0.9f, 1.4f)
13 {
14 }
15 
16 
17 
18 
19 
20 void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer)
21 {
22  if (IsBaby())
23  {
24  return; // Babies don't drop items
25  }
26 
27  unsigned int LootingLevel = 0;
28  if (a_Killer != nullptr)
29  {
31  }
32  AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER);
33  AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF);
34 }
35 
36 
37 
38 
39 
41 {
42  switch (a_Player.GetEquippedItem().m_ItemType)
43  {
44  case E_ITEM_BUCKET:
45  {
46  // Milk the cow.
47  if (!a_Player.IsGameModeCreative())
48  {
50  }
51  } break;
52  case E_ITEM_BOWL:
53  {
54  // Soup the cow.
55  if (!a_Player.IsGameModeCreative())
56  {
58  }
59  } break;
60  case E_ITEM_SHEARS:
61  {
62  if (!a_Player.IsGameModeCreative())
63  {
64  a_Player.UseEquippedItem();
65  }
66 
67  cItems Drops;
68  Drops.emplace_back(E_BLOCK_RED_MUSHROOM, static_cast<char>(5), static_cast<char>(0));
69  m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10);
70  m_World->SpawnMob(GetPosX(), GetPosY(), GetPosZ(), mtCow, false);
71  Destroy();
72  } break;
73  }
74 }
@ E_BLOCK_RED_MUSHROOM
Definition: BlockType.h:50
@ E_ITEM_STEAK
Definition: BlockType.h:409
@ E_ITEM_RAW_BEEF
Definition: BlockType.h:408
@ E_ITEM_BOWL
Definition: BlockType.h:325
@ E_ITEM_MILK
Definition: BlockType.h:379
@ E_ITEM_LEATHER
Definition: BlockType.h:378
@ E_ITEM_MUSHROOM_SOUP
Definition: BlockType.h:326
@ E_ITEM_BUCKET
Definition: BlockType.h:369
@ E_ITEM_SHEARS
Definition: BlockType.h:404
@ mtCow
Definition: MonsterTypes.h:20
@ mtMooshroom
Definition: MonsterTypes.h:41
unsigned int GetLevel(int a_EnchantmentID) const
Returns the level for the specified enchantment; 0 if not stored.
Definition: Entity.h:76
double GetPosX(void) const
Definition: Entity.h:195
cWorld * m_World
Definition: Entity.h:624
double GetPosZ(void) const
Definition: Entity.h:197
void Destroy()
Destroys the entity, schedules it for memory freeing and broadcasts the DestroyEntity packet.
Definition: Entity.cpp:243
virtual bool IsOnFire(void) const
Definition: Entity.h:489
double GetPosY(void) const
Definition: Entity.h:196
virtual cItem GetEquippedWeapon(void) const
Returns the curently equipped weapon; empty item if none.
Definition: Entity.h:333
Definition: Player.h:29
const cItem & GetEquippedItem(void) const
Definition: Player.h:162
bool IsGameModeCreative(void) const
Returns true if the player is in Creative mode, either explicitly, or by inheriting from current worl...
Definition: Player.cpp:1025
void ReplaceOneEquippedItemTossRest(const cItem &)
Removes one item from the the current equipped item stack, and attempts to add the specified item sta...
Definition: Player.cpp:1745
void UseEquippedItem(short a_Damage=1)
Damage the player's equipped item by a_Damage, possibly less if the equipped item is enchanted.
Definition: Player.cpp:2033
Definition: Item.h:37
cEnchantments m_Enchantments
Definition: Item.h:166
short m_ItemType
Definition: Item.h:163
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
void AddRandomDropItem(cItems &a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth=0)
Adds a random number of a_Item between a_Min and a_Max to itemdrops a_Drops.
Definition: Monster.cpp:1518
bool IsBaby(void) const
Definition: Monster.h:156
virtual void OnRightClicked(cPlayer &a_Player) override
Called when the specified player right-clicks this entity.
Definition: Mooshroom.cpp:40
virtual void GetDrops(cItems &a_Drops, cEntity *a_Killer=nullptr) override
Returns the list of drops for this pawn when it is killed.
Definition: Mooshroom.cpp:20
virtual UInt32 SpawnMob(double a_PosX, double a_PosY, double a_PosZ, eMonsterType a_MonsterType, bool a_Baby=false) override
Spawns a mob of the specified type.
Definition: World.cpp:2897
void SpawnItemPickups(const cItems &a_Pickups, Vector3i a_BlockPos, double a_FlyAwaySpeed=1.0, bool a_IsPlayerCreated=false)
Spawns item pickups for each item in the list.
Definition: World.cpp:1806