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  {
45  } ;
46 
47  // tolua_end
48 
50 
51  cProjectileEntity(eKind a_Kind, cEntity * a_Creator, Vector3d a_Pos, float a_Width, float a_Height);
52  cProjectileEntity(eKind a_Kind, cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed, float a_Width, float a_Height);
53 
56  static std::unique_ptr<cProjectileEntity> Create(
57  eKind a_Kind,
58  cEntity * a_Creator,
59  Vector3d a_Pos,
60  const cItem * a_Item,
61  const Vector3d * a_Speed = nullptr
62  );
63 
67  static std::unique_ptr<cProjectileEntity> Create(
68  eKind a_Kind,
69  cEntity * a_Creator,
70  double a_PosX, double a_PosY, double a_PosZ,
71  const cItem * a_Item,
72  const Vector3d * a_Speed = nullptr
73  )
74  {
75  return Create(a_Kind, a_Creator, {a_PosX, a_PosY, a_PosZ}, a_Item, a_Speed);
76  }
77 
79  virtual void OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace);
80 
82  virtual void OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos);
83 
85  virtual void CollectedBy(cPlayer & a_Dest);
86 
87  // tolua_begin
88 
90  eKind GetProjectileKind(void) const { return m_ProjectileKind; }
91 
96 
100  AString GetCreatorName(void) const { return m_CreatorData.m_Name; }
101 
103  AString GetMCAClassName(void) const;
104 
106  bool IsInGround(void) const { return m_IsInGround; }
107 
108  // tolua_end
109 
111  void SetIsInGround(bool a_IsInGround) { m_IsInGround = a_IsInGround; }
112 
113 protected:
114 
117  struct CreatorData
118  {
119  CreatorData(UInt32 a_UniqueID, const AString & a_Name, const cEnchantments & a_Enchantments) :
120  m_UniqueID(a_UniqueID),
121  m_Name(a_Name),
122  m_Enchantments(a_Enchantments)
123  {
124  }
125 
129  };
130 
133 
137 
140 
141  // cEntity overrides:
142  virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
143  virtual void HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
144  virtual void SpawnOn(cClientHandle & a_Client) final override;
145 
146 } ; // tolua_export
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
Definition: Defines.h:38
#define CLASS_PROTODEF(classname)
Definition: Entity.h:13
unsigned int UInt32
Definition: Globals.h:157
std::string AString
Definition: StringUtils.h:11
Definition: Chunk.h:36
Class that stores item enchantments or stored-enchantments The enchantments may be serialized to a st...
Definition: Enchantments.h:42
Definition: Entity.h:76
cEntity(eEntityType a_EntityType, Vector3d a_Pos, float a_Width, float a_Height)
Definition: Entity.cpp:37
Definition: Player.h:29
UInt32 GetCreatorUniqueID(void) const
Returns the unique ID of the entity who created this projectile May return an ID <0.
eKind
The kind of the projectile.
eKind m_ProjectileKind
The type of projectile I am.
cProjectileEntity(eKind a_Kind, cEntity *a_Creator, Vector3d a_Pos, float a_Width, float a_Height)
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 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.
CreatorData m_CreatorData
The structure for containing the entity ID and name who has created this projectile The ID and / or n...
bool IsInGround(void) const
Returns true if the projectile has hit the ground and is stuck there.
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
bool m_IsInGround
True if the projectile has hit the ground and is stuck there.
virtual void CollectedBy(cPlayer &a_Dest)
Called by Chunk when the projectile is eligible for player collection.
AString GetMCAClassName(void) const
Returns the string that is used as the entity type (class name) in MCA files.
virtual void OnHitEntity(cEntity &a_EntityHit, Vector3d a_HitPos)
Called by the physics blocktracer when the entity hits another entity.
eKind GetProjectileKind(void) const
Returns the kind of the projectile (fast class identification)
virtual void SpawnOn(cClientHandle &a_Client) final override
Descendants override this function to send a command to the specified client to spawn the entity on t...
void SetIsInGround(bool a_IsInGround)
Sets the internal InGround flag.
static std::unique_ptr< cProjectileEntity > Create(eKind a_Kind, cEntity *a_Creator, double a_PosX, double a_PosY, double a_PosZ, const cItem *a_Item, const Vector3d *a_Speed=nullptr)
OBSOLETE, use the Vector3d-based overload instead.
A structure that stores the Entity ID and Playername of the projectile's creator Used to migitate inv...
CreatorData(UInt32 a_UniqueID, const AString &a_Name, const cEnchantments &a_Enchantments)
Definition: Item.h:37