Cuberite
A lightweight, fast and extensible game server for Minecraft
Chicken.cpp
Go to the documentation of this file.
1 #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
2 
3 #include "Chicken.h"
4 #include "../World.h"
5 
6 
7 
8 
9 
11  Super("Chicken", mtChicken, "entity.chicken.hurt", "entity.chicken.death", "entity.chicken.ambient", 0.4f, 0.7f),
12  m_EggDropTimer(0)
13 {
14  SetGravity(-2.0f);
15  SetAirDrag(0.0f);
16 }
17 
18 
19 
20 
21 
22 void cChicken::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
23 {
24  Super::Tick(a_Dt, a_Chunk);
25  if (!IsTicking())
26  {
27  // The base class tick destroyed us
28  return;
29  }
30 
31  if (IsBaby())
32  {
33  return; // Babies don't lay eggs
34  }
35 
36  if (
37  ((m_EggDropTimer == 6000) && GetRandomProvider().RandBool()) ||
38  m_EggDropTimer == 12000
39  )
40  {
41  cItems Drops;
42  m_EggDropTimer = 0;
43  Drops.emplace_back(E_ITEM_EGG, static_cast<char>(1));
44  m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10);
45  }
46  else
47  {
49  }
50 }
51 
52 
53 
54 
55 
56 void cChicken::GetDrops(cItems & a_Drops, cEntity * a_Killer)
57 {
58  if (IsBaby())
59  {
60  return; // Babies don't drop items
61  }
62 
63  unsigned int LootingLevel = 0;
64  if (a_Killer != nullptr)
65  {
67  }
68  AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_FEATHER);
70 }
71 
72 
73 
74 
75 
77 {
78  if (a_TDI.DamageType == dtFalling)
79  {
80  return false;
81  }
82 
83  return Super::DoTakeDamage(a_TDI);
84 }
@ E_ITEM_RAW_CHICKEN
Definition: BlockType.h:410
@ E_ITEM_FEATHER
Definition: BlockType.h:332
@ E_ITEM_COOKED_CHICKEN
Definition: BlockType.h:411
@ E_ITEM_EGG
Definition: BlockType.h:389
@ dtFalling
Definition: Defines.h:249
MTRand & GetRandomProvider()
Returns the current thread's random number source.
Definition: FastRandom.cpp:12
@ mtChicken
Definition: MonsterTypes.h:18
Definition: Chunk.h:36
unsigned int GetLevel(int a_EnchantmentID) const
Returns the level for the specified enchantment; 0 if not stored.
eDamageType DamageType
Definition: Entity.h:61
Definition: Entity.h:76
bool IsTicking(void) const
Returns true if the entity is valid and ticking.
Definition: Entity.cpp:2259
void SetGravity(float a_Gravity)
Definition: Entity.h:282
double GetPosX(void) const
Definition: Entity.h:195
cWorld * m_World
Definition: Entity.h:624
double GetPosZ(void) const
Definition: Entity.h:197
virtual bool IsOnFire(void) const
Definition: Entity.h:489
double GetPosY(void) const
Definition: Entity.h:196
void SetAirDrag(float a_AirDrag)
Definition: Entity.h:286
virtual cItem GetEquippedWeapon(void) const
Returns the curently equipped weapon; empty item if none.
Definition: Entity.h:333
cEnchantments m_Enchantments
Definition: Item.h:166
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
Definition: Chicken.cpp:22
virtual void GetDrops(cItems &a_Drops, cEntity *a_Killer=nullptr) override
Returns the list of drops for this pawn when it is killed.
Definition: Chicken.cpp:56
int m_EggDropTimer
Definition: Chicken.h:35
virtual bool DoTakeDamage(TakeDamageInfo &a_TDI) override
When hit by someone, run away.
Definition: Chicken.cpp:76
cChicken()
Definition: Chicken.cpp:10
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 Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
virtual bool DoTakeDamage(TakeDamageInfo &a_TDI) override
When hit by someone, run away.
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