Cuberite
A lightweight, fast and extensible game server for Minecraft
SplashPotionEntity.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 "SplashPotionEntity.h"
4 #include "Pawn.h"
5 #include "../EffectID.h"
6 
7 
8 
9 
10 
12 // cSplashPotionEntity:
13 
15  cEntity * a_Creator,
16  Vector3d a_Pos,
17  Vector3d a_Speed,
18  const cItem & a_Item
19 ):
20  Super(pkSplashPotion, a_Creator, a_Pos, a_Speed, 0.25f, 0.25f),
21  m_Item(a_Item)
22 {
27  );
29 }
30 
31 
32 
33 
34 
36 {
37  // Look for entities in 8.25 (width) x 4.25 (height) cuboid _centred_ on hit position:
38  m_World->ForEachEntityInBox({ a_HitPos.addedY(-4.25 / 2), 8.25 / 2, 4.25 }, [this, a_HitPos](cEntity & a_Entity)
39  {
40  if (!a_Entity.IsPawn())
41  {
42  // Not an entity that can take effects
43  return false;
44  }
45 
46  double SplashDistance = (a_Entity.GetPosition() - a_HitPos).Length();
47  double Reduction = -0.25 * SplashDistance + 1.0; // y = -0.25x + 1, where x is the distance from the player. Approximation for potion splash.
48  Reduction = std::max(Reduction, 0.0);
49 
50  static_cast<cPawn &>(a_Entity).AddEntityEffect(m_EntityEffectType, m_EntityEffect.GetDuration(), m_EntityEffect.GetIntensity(), Reduction);
51  return false;
52  });
53 
56  a_HitPos.Floor(),
58  );
59 }
60 
61 
62 
63 
64 
65 void cSplashPotionEntity::OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos)
66 {
67  Super::OnHitEntity(a_EntityHit, a_HitPos);
68 
69  a_EntityHit.TakeDamage(dtRangedAttack, this, 0, 1);
70  Splash(a_HitPos);
71  Destroy();
72 }
73 
74 
75 
76 
77 
79 {
80  Super::OnHitSolidBlock(a_HitPos, a_HitFace);
81 
82  Splash(a_HitPos);
83  Destroy();
84 }
@ dtRangedAttack
Definition: Defines.h:247
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
Definition: Defines.h:38
@ PARTICLE_SPLASH_POTION
Definition: Entity.h:76
cWorld * m_World
Definition: Entity.h:624
void Destroy()
Destroys the entity, schedules it for memory freeing and broadcasts the DestroyEntity packet.
Definition: Entity.cpp:243
void TakeDamage(cEntity &a_Attacker)
Makes this pawn take damage from an attack by a_Attacker.
Definition: Entity.cpp:272
static int GetPotionEffectDuration(short a_ItemDamage)
Returns the effect duration, in ticks, based on the potion's damage value.
static int GetPotionColor(short a_ItemDamage)
Returns the potion color (used by the client for visuals), based on the potion's damage value.
short GetIntensity(void) const
Returns how strong the effect will be applied.
Definition: EntityEffect.h:93
int GetDuration(void) const
Returns the duration of the effect.
Definition: EntityEffect.h:90
static short GetPotionEffectIntensity(short a_ItemDamage)
Retrieves the intensity level from the potion's damage value.
static cEntityEffect::eType GetPotionEffectType(short a_ItemDamage)
Translates the potion's damage value into the entity effect that the potion gives.
Definition: Pawn.h:17
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...
virtual void OnHitEntity(cEntity &a_EntityHit, Vector3d a_HitPos)
Called by the physics blocktracer when the entity hits another entity.
cEntityEffect m_EntityEffect
cEntityEffect::eType m_EntityEffectType
void Splash(Vector3d a_HitPos)
Splashes the potion, fires its particle effects and sounds.
virtual void OnHitEntity(cEntity &a_EntityHit, Vector3d a_HitPos) override
Called by the physics blocktracer when the entity hits another entity.
virtual void OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace) override
Called by the physics blocktracer when the entity hits a solid block, the hit position and the face h...
cSplashPotionEntity(cEntity *a_Creator, Vector3d a_Pos, Vector3d a_Speed, const cItem &a_Item)
Definition: Item.h:37
short m_ItemDamage
Definition: Item.h:165
Vector3< T > addedY(T a_AddY) const
Returns a copy of this vector moved by the specified amount on the y axis.
Definition: Vector3.h:314
Vector3< int > Floor(void) const
Returns a new Vector3i with coords set to std::floor() of this vector's coords.
Definition: Vector3.h:177
virtual bool ForEachEntityInBox(const cBoundingBox &a_Box, cEntityCallback a_Callback) override
Calls the callback for each entity that has a nonempty intersection with the specified boundingbox.
Definition: World.cpp:2445
virtual void BroadcastSoundParticleEffect(const EffectID a_EffectID, Vector3i a_SrcPos, int a_Data, const cClientHandle *a_Exclude=nullptr) override