Cuberite
A lightweight, fast and extensible game server for Minecraft
ProjectileEntity.h
Go to the documentation of this file.
1 
2 // ProjectileEntity.h
3 
4 // Declares the cProjectileEntity class representing the common base class for projectiles
5 
6 
7 
8 
9 
10 #pragma once
11 
12 #include "Entity.h"
13 
14 
15 
16 
17 
18 // tolua_begin
19 
21  public cEntity
22 {
23  // tolua_end
24 
25  using super = cEntity;
26 
27  // tolua_begin
28 
29 
30 public:
31 
33  enum eKind
34  {
35  pkArrow = 60,
36  pkSnowball = 61,
37  pkEgg = 62,
43  pkFirework = 76,
46  } ;
47 
48  // tolua_end
49 
51 
52  cProjectileEntity(eKind a_Kind, cEntity * a_Creator, Vector3d a_Pos, double a_Width, double a_Height);
53  cProjectileEntity(eKind a_Kind, cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed, double a_Width, double a_Height);
54 
57  static std::unique_ptr<cProjectileEntity> Create(
58  eKind a_Kind,
59  cEntity * a_Creator,
60  Vector3d a_Pos,
61  const cItem * a_Item,
62  const Vector3d * a_Speed = nullptr
63  );
64 
68  static std::unique_ptr<cProjectileEntity> Create(
69  eKind a_Kind,
70  cEntity * a_Creator,
71  double a_PosX, double a_PosY, double a_PosZ,
72  const cItem * a_Item,
73  const Vector3d * a_Speed = nullptr
74  )
75  {
76  return Create(a_Kind, a_Creator, {a_PosX, a_PosY, a_PosZ}, a_Item, a_Speed);
77  }
78 
80  virtual void OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace);
81 
83  virtual void OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos);
84 
86  virtual void CollectedBy(cPlayer & a_Dest);
87 
88  // tolua_begin
89 
91  eKind GetProjectileKind(void) const { return m_ProjectileKind; }
92 
97 
101  AString GetCreatorName(void) const { return m_CreatorData.m_Name; }
102 
104  AString GetMCAClassName(void) const;
105 
107  bool IsInGround(void) const { return m_IsInGround; }
108 
109  // tolua_end
110 
112  void SetIsInGround(bool a_IsInGround) { m_IsInGround = a_IsInGround; }
113 
114 protected:
115 
118  struct CreatorData
119  {
120  CreatorData(UInt32 a_UniqueID, const AString & a_Name, const cEnchantments & a_Enchantments) :
121  m_UniqueID(a_UniqueID),
122  m_Name(a_Name),
123  m_Enchantments(a_Enchantments)
124  {
125  }
126 
130  };
131 
134 
138 
141 
142  // cEntity overrides:
143  virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
144  virtual void HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
145  virtual void SpawnOn(cClientHandle & a_Client) override;
146 
147 } ; // tolua_export
Definition: FastNBT.h:131
CreatorData(UInt32 a_UniqueID, const AString &a_Name, const cEnchantments &a_Enchantments)
CreatorData m_CreatorData
The structure for containing the entity ID and name who has created this projectile The ID and / or n...
AString GetMCAClassName(void) const
Returns the string that is used as the entity type (class name) in MCA files.
eKind GetProjectileKind(void) const
Returns the kind of the projectile (fast class identification)
Definition: Player.h:27
AString GetCreatorName(void) const
Returns the name of the player that created the projectile Will be empty for non-player creators...
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
eKind
The kind of the projectile.
Definition: Chunk.h:49
virtual void OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace)
Called by the physics blocktracer when the entity hits a solid block, the hit position and the face h...
static std::unique_ptr< cProjectileEntity > Create(eKind a_Kind, cEntity *a_Creator, Vector3d a_Pos, const cItem *a_Item, const Vector3d *a_Speed=nullptr)
Creates a new instance of the specified projectile entity.
void SetIsInGround(bool a_IsInGround)
Sets the internal InGround flag.
virtual void SpawnOn(cClientHandle &a_Client) override
Descendants override this function to send a command to the specified client to spawn the entity on t...
virtual void CollectedBy(cPlayer &a_Dest)
Called by Chunk when the projectile is eligible for player collection.
std::string AString
Definition: StringUtils.h:13
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
Definition: Defines.h:29
bool IsInGround(void) const
Returns true if the projectile has hit the ground and is stuck there.
A structure that stores the Entity ID and Playername of the projectile&#39;s creator Used to migitate inv...
Definition: Entity.h:73
bool m_IsInGround
True if the projectile has hit the ground and is stuck there.
cEntity(eEntityType a_EntityType, Vector3d a_Pos, double a_Width, double a_Height)
Definition: Entity.cpp:35
unsigned int UInt32
Definition: Globals.h:113
eKind m_ProjectileKind
The type of projectile I am.
virtual void HandlePhysics(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
Handles the physics of the entity - updates position based on speed, updates speed based on environme...
virtual void OnHitEntity(cEntity &a_EntityHit, Vector3d a_HitPos)
Called by the physics blocktracer when the entity hits another entity.
UInt32 GetCreatorUniqueID(void)
Returns the unique ID of the entity who created this projectile May return an ID <0.
#define CLASS_PROTODEF(classname)
Definition: Entity.h:11
Class that stores item enchantments or stored-enchantments The enchantments may be serialized to a st...
Definition: Enchantments.h:40
Definition: Item.h:36