Cuberite
A lightweight, fast and extensible game server for Minecraft
Cow.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 "Cow.h"
5 #include "../Entities/Player.h"
6 
7 
8 
9 
10 
11 cCow::cCow(void) :
12  Super("Cow", mtCow, "entity.cow.hurt", "entity.cow.death", "entity.cow.ambient", 0.9f, 1.4f)
13 {
14 }
15 
16 
17 
18 
19 
20 void cCow::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 
40 void cCow::OnRightClicked(cPlayer & a_Player)
41 {
42  Super::OnRightClicked(a_Player);
43 
44  short HeldItem = a_Player.GetEquippedItem().m_ItemType;
45  if (HeldItem == E_ITEM_BUCKET)
46  {
47  // Milk the cow.
48  if (!a_Player.IsGameModeCreative())
49  {
51  }
52  }
53 }
@ E_ITEM_STEAK
Definition: BlockType.h:409
@ E_ITEM_RAW_BEEF
Definition: BlockType.h:408
@ E_ITEM_MILK
Definition: BlockType.h:379
@ E_ITEM_LEATHER
Definition: BlockType.h:378
@ E_ITEM_BUCKET
Definition: BlockType.h:369
@ mtCow
Definition: MonsterTypes.h:20
unsigned int GetLevel(int a_EnchantmentID) const
Returns the level for the specified enchantment; 0 if not stored.
Definition: Entity.h:76
virtual bool IsOnFire(void) const
Definition: Entity.h:489
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
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
virtual void OnRightClicked(cPlayer &a_Player) override
Called when the specified player right-clicks this entity.
Definition: Cow.cpp:40
cCow()
Definition: Cow.cpp:11
virtual void GetDrops(cItems &a_Drops, cEntity *a_Killer=nullptr) override
Returns the list of drops for this pawn when it is killed.
Definition: Cow.cpp:20
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.