Cuberite
A lightweight, fast and extensible game server for Minecraft
Pickup.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "Entity.h"
5 #include "../Item.h"
6 
7 
8 
9 
10 
11 class cPlayer;
12 
13 
14 
15 
16 
17 // tolua_begin
18 class cPickup :
19  public cEntity
20 {
21  // tolua_end
22 
23  using super = cEntity;
24 
25 public: // tolua_export
26 
28 
29  cPickup(Vector3d a_Pos, const cItem & a_Item, bool IsPlayerCreated, Vector3f a_Speed = Vector3f(), int a_LifetimeTicks = 6000, bool a_CanCombine = true);
30 
31  cItem & GetItem(void) {return m_Item; } // tolua_export
32  const cItem & GetItem(void) const {return m_Item; }
33 
34  virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
35 
36  bool CollectedBy(cPlayer & a_Dest); // tolua_export
37 
38  virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
39 
40  virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override;
41 
42  virtual bool DoesPreventBlockPlacement(void) const override { return false; }
43 
45  bool CanCombine(void) const { return m_bCanCombine; } // tolua_export
46 
48  void SetCanCombine(bool a_CanCombine) { m_bCanCombine = a_CanCombine; } // tolua_export
49 
51  int GetAge(void) const { return std::chrono::duration_cast<cTickTime>(m_Timer).count(); } // tolua_export
52 
54  void SetAge(int a_Age) { m_Timer = cTickTime(a_Age); } // tolua_export
55 
57  int GetLifetime(void) const { return std::chrono::duration_cast<cTickTime>(m_Lifetime).count(); } // tolua_export
58 
60  void SetLifetime(int a_Lifetime) { m_Lifetime = cTickTime(a_Lifetime); } // tolua_export
61 
63  bool IsCollected(void) const { return m_bCollected; } // tolua_export
64 
66  bool IsPlayerCreated(void) const { return m_bIsPlayerCreated; } // tolua_export
67 
68 private:
69 
71  std::chrono::milliseconds m_Timer;
72 
74 
76 
78 
80 
81  std::chrono::milliseconds m_Lifetime;
82 }; // tolua_export
std::chrono::duration< int, std::ratio_multiply< std::chrono::milliseconds::period, std::ratio< 50 >>> cTickTime
Definition: Globals.h:388
std::chrono::milliseconds m_Timer
The number of ticks that the entity has existed / timer between collect and destroy; in msec...
Definition: Pickup.h:71
int GetLifetime(void) const
Returns the number of ticks that this pickup should live for.
Definition: Pickup.h:57
Definition: Player.h:27
bool IsCollected(void) const
Returns true if the pickup has already been collected.
Definition: Pickup.h:63
bool CollectedBy(cPlayer &a_Dest)
Definition: Pickup.cpp:214
cItem m_Item
Definition: Pickup.h:73
Definition: Pickup.h:18
bool IsPlayerCreated(void) const
Returns true if created by player (i.e.
Definition: Pickup.h:66
Definition: Chunk.h:49
virtual bool DoesPreventBlockPlacement(void) const override
Returns whether blocks can be placed intersecting this entities&#39; hitbox.
Definition: Pickup.h:42
std::chrono::milliseconds m_Lifetime
Definition: Pickup.h:81
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
Definition: Pickup.cpp:128
bool m_bIsPlayerCreated
Definition: Pickup.h:77
virtual void SpawnOn(cClientHandle &a_ClientHandle) override
Descendants override this function to send a command to the specified client to spawn the entity on t...
Definition: Pickup.cpp:119
void SetAge(int a_Age)
Set the number of ticks that this entity has existed.
Definition: Pickup.h:54
bool CanCombine(void) const
Returns whether this pickup is allowed to combine with other similar pickups.
Definition: Pickup.h:45
void SetLifetime(int a_Lifetime)
Set the number of ticks that this pickup should live for.
Definition: Pickup.h:60
cItem & GetItem(void)
Definition: Pickup.h:31
bool m_bCollected
Definition: Pickup.h:75
Definition: Entity.h:73
cEntity(eEntityType a_EntityType, Vector3d a_Pos, double a_Width, double a_Height)
Definition: Entity.cpp:35
const cItem & GetItem(void) const
Definition: Pickup.h:32
bool m_bCanCombine
Definition: Pickup.h:79
#define CLASS_PROTODEF(classname)
Definition: Entity.h:11
int GetAge(void) const
Returns the number of ticks that this entity has existed.
Definition: Pickup.h:51
void SetCanCombine(bool a_CanCombine)
Sets whether this pickup is allowed to combine with other similar pickups.
Definition: Pickup.h:48
Definition: Item.h:36
virtual bool DoTakeDamage(TakeDamageInfo &a_TDI) override
Makes this entity take damage specified in the a_TDI.
Definition: Pickup.cpp:199