Cuberite
A lightweight, fast and extensible game server for Minecraft
Guardian.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 "Guardian.h"
5 #include "../Chunk.h"
6 
7 
8 
9 
10 
12  Super("Guardian", mtGuardian, "entity.guardian.hurt", "entity.guardian.death", "entity.guardian.ambient", 0.85f, 0.85f)
13 {
14 }
15 
16 
17 
18 
19 
20 void cGuardian::GetDrops(cItems & a_Drops, cEntity * a_Killer)
21 {
22  // Drops 0-3 Ink Sacs
23  unsigned int LootingLevel = 0;
24  if (a_Killer != nullptr)
25  {
27  }
28  AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_PRISMARINE_SHARD);
29  AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_RAW_FISH);
30  AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_PRISMARINE_CRYSTALS); // TODO: Prismarine Crystals only drop if the raw fish drop is 0
31 }
32 
33 
34 
35 
36 
37 void cGuardian::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
38 {
39  m_PathfinderActivated = false; // Disable Pathfinding until it's fixed. TODO
40 
41  // We must first process current location, and only then tick, otherwise we risk processing a location in a chunk
42  // that is not where the entity currently resides (FS #411)
43  Vector3d Pos = GetPosition();
44 
45  int RelY = FloorC(Pos.y);
46  if ((RelY < 0) || (RelY >= cChunkDef::Height))
47  {
48  return;
49  }
50 
51  Super::Tick(a_Dt, a_Chunk);
52 }
53 
54 
55 
56 
@ E_ITEM_PRISMARINE_CRYSTALS
Definition: BlockType.h:456
@ E_ITEM_RAW_FISH
Definition: BlockType.h:394
@ E_ITEM_PRISMARINE_SHARD
Definition: BlockType.h:455
std::enable_if< std::is_arithmetic< T >::value, C >::type FloorC(T a_Value)
Floors a value, then casts it to C (an int by default).
Definition: Globals.h:347
@ mtGuardian
Definition: MonsterTypes.h:33
Definition: Chunk.h:36
static const int Height
Definition: ChunkDef.h:125
unsigned int GetLevel(int a_EnchantmentID) const
Returns the level for the specified enchantment; 0 if not stored.
Definition: Entity.h:76
virtual cItem GetEquippedWeapon(void) const
Returns the curently equipped weapon; empty item if none.
Definition: Entity.h:333
const Vector3d & GetPosition(void) const
Exported in ManualBindings.
Definition: Entity.h:297
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
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
Definition: Guardian.cpp:37
virtual void GetDrops(cItems &a_Drops, cEntity *a_Killer=nullptr) override
Returns the list of drops for this pawn when it is killed.
Definition: Guardian.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 m_PathfinderActivated
Stores if pathfinder is being used - set when final destination is set, and unset when stopped moving...
Definition: Monster.h:258
T y
Definition: Vector3.h:17