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", 0.9, 1.3)
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  if (!a_Player.IsGameModeCreative())
47  {
49  a_Player.GetInventory().AddItem(E_ITEM_MILK);
50  }
51  } break;
52  case E_ITEM_BOWL:
53  {
54  if (!a_Player.IsGameModeCreative())
55  {
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.push_back(cItem(E_BLOCK_RED_MUSHROOM, 5, 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 }
double GetPosY(void) const
Definition: Entity.h:207
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:3190
double GetPosX(void) const
Definition: Entity.h:206
cMooshroom(void)
Definition: Mooshroom.cpp:11
bool RemoveOneEquippedItem(void)
Removes one item out of the currently equipped item stack, returns true if successful, false if empty-handed.
Definition: Inventory.cpp:207
cWorld * m_World
Definition: Entity.h:620
const cItem & GetEquippedItem(void) const
Definition: Player.h:142
Definition: Player.h:27
virtual bool IsOnFire(void) const
Definition: Entity.h:486
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:1215
unsigned int GetLevel(int a_EnchantmentID) const
Returns the level for the specified enchantment; 0 if not stored.
bool IsBaby(void) const
Definition: Monster.h:150
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:1936
cEnchantments m_Enchantments
Definition: Item.h:212
int AddItem(const cItem &a_ItemStack, bool a_AllowNewStacks=true)
Adds as many items out of a_ItemStack as can fit.
Definition: Inventory.cpp:106
virtual void Destroy(bool a_ShouldBroadcast=true) override
Destroys the entity and schedules it for memory freeing; if a_ShouldBroadcast is set to true...
Definition: Monster.cpp:135
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
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:2397
virtual cItem GetEquippedWeapon(void) const
Returns the curently equipped weapon; empty item if none.
Definition: Entity.h:346
Definition: Entity.h:73
double GetPosZ(void) const
Definition: Entity.h:208
bool IsGameModeCreative(void) const
Returns true if the player is in Creative mode, either explicitly, or by inheriting from current worl...
Definition: Player.cpp:1260
short m_ItemType
Definition: Item.h:209
cInventory & GetInventory(void)
Definition: Player.h:136
virtual void OnRightClicked(cPlayer &a_Player) override
Called when the specified player right-clicks this entity.
Definition: Mooshroom.cpp:40
Definition: Item.h:36
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:234