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", 0.9, 1.3)
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  if (!a_Player.IsGameModeCreative())
48  {
50  a_Player.GetInventory().AddItem(E_ITEM_MILK);
51  }
52  }
53 }
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
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
cEnchantments m_Enchantments
Definition: Item.h:212
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
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 cItem GetEquippedWeapon(void) const
Returns the curently equipped weapon; empty item if none.
Definition: Entity.h:346
Definition: Entity.h:73
virtual void OnRightClicked(cPlayer &a_Player) override
Called when the specified player right-clicks this entity.
Definition: Cow.cpp:40
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
virtual void OnRightClicked(cPlayer &a_Player) override
Called when the specified player right-clicks this entity.
cInventory & GetInventory(void)
Definition: Player.h:136
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:234