8 #include "../Bindings/PluginManager.h"
10 #include "../BlockInfo.h"
11 #include "../ClientHandle.h"
12 #include "../LineBlockTracer.h"
13 #include "../BoundingBox.h"
14 #include "../ChunkMap.h"
37 public cBlockTracer::cCallbacks
88 LOGD(
"WEIRD! block tracer reports a hit, but BBox tracer doesn't. Ignoring the hit.");
223 Super(etProjectile, a_Pos, a_Width, a_Height),
224 m_ProjectileKind(a_Kind),
226 ((a_Creator != nullptr) ? a_Creator->GetUniqueID() :
cEntity::INVALID_ID),
227 ((a_Creator != nullptr) ? (a_Creator->IsPlayer() ? static_cast<
cPlayer *>(a_Creator)->GetName() :
"") :
""),
228 ((a_Creator != nullptr) ? a_Creator->GetEquippedWeapon().m_Enchantments :
cEnchantments())
256 const cItem * a_Item,
261 if (a_Speed !=
nullptr)
268 case pkArrow:
return std::make_unique<cArrowEntity> (a_Creator, a_Pos, Speed);
269 case pkEgg:
return std::make_unique<cThrownEggEntity> (a_Creator, a_Pos, Speed);
270 case pkEnderPearl:
return std::make_unique<cThrownEnderPearlEntity>(a_Creator, a_Pos, Speed);
271 case pkSnowball:
return std::make_unique<cThrownSnowballEntity> (a_Creator, a_Pos, Speed);
272 case pkGhastFireball:
return std::make_unique<cGhastFireballEntity> (a_Creator, a_Pos, Speed);
273 case pkFireCharge:
return std::make_unique<cFireChargeEntity> (a_Creator, a_Pos, Speed);
274 case pkExpBottle:
return std::make_unique<cExpBottleEntity> (a_Creator, a_Pos, Speed);
275 case pkSplashPotion:
return std::make_unique<cSplashPotionEntity> (a_Creator, a_Pos, Speed, *a_Item);
276 case pkWitherSkull:
return std::make_unique<cWitherSkullEntity> (a_Creator, a_Pos, Speed);
279 ASSERT(a_Item !=
nullptr);
285 return std::make_unique<cFireworkEntity>(a_Creator, a_Pos, *a_Item);
289 LOGWARNING(
"%s: Unknown projectile kind: %d", __FUNCTION__, a_Kind);
304 FLOGD(
"Projectile {0}: pos {1:.02f}, hit solid block at face {2}",
322 auto EntityHit =
static_cast<cPawn *
>(&a_EntityHit);
325 static_cast<cPlayer&
>(a_Hitter).NotifyNearbyWolves(EntityHit,
true);
342 case pkEgg:
return "Egg";
381 auto DtSec = std::chrono::duration_cast<std::chrono::duration<double>>(a_Dt);
385 const Vector3d NextPos = Pos + DeltaSpeed;
390 if (EntityCollisionCallback.
HasHit())
396 FLOGD(
"Projectile {0} has hit an entity {1} ({2}) at {3:.02f} (coeff {4:.03f})",
427 NewSpeed -= NewSpeed * (
m_AirDrag * 20.0f) * DtSec.count();
@ E_BLOCK_STATIONARY_LAVA
@ E_BLOCK_STATIONARY_WATER
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
unsigned char BLOCKTYPE
The datatype used by blockdata.
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
void LOGWARNING(std::string_view a_Format, const Args &... args)
static cPluginManager * Get(void)
Returns the instance of the Plugin Manager (there is only ever one)
static bool IsSolid(BLOCKTYPE Block)
Is this block solid (player cannot walk through)?
Represents two sets of coords, minimum and maximum for each direction.
bool CalcLineIntersection(Vector3d a_LinePoint1, Vector3d a_LinePoint2, double &a_LineCoeff, eBlockFace &a_Face) const
Returns true if this bounding box is intersected by the line specified by its two points Also calcula...
bool ForEachEntity(cEntityCallback a_Callback) const
Calls the callback for each entity; returns true if all entities processed, false if the callback abo...
void SendSpawnEntity(const cEntity &a_Entity)
void SendEntityMetadata(const cEntity &a_Entity)
Class that stores item enchantments or stored-enchantments The enchantments may be serialized to a st...
const Vector3d & GetSpeed(void) const
Exported in ManualBindings.
bool IsPlayer(void) const
cBoundingBox GetBoundingBox() const
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk)
float m_AirDrag
Stores the air drag that is applied to the entity every tick, measured in speed ratio per tick Acts a...
bool IsEnderCrystal(void) const
void SetPitchFromSpeed(void)
Sets the pitch to match the speed vector (entity gies "face-forward")
virtual const char * GetClass(void) const
Returns the topmost class name for the object.
bool IsTicking(void) const
Returns true if the entity is valid and ticking.
float m_Gravity
Stores gravity that is applied to an entity every tick For realistic effects, this should be negative...
UInt32 m_UniqueID
The ID of the entity that is guaranteed to be unique within a single run of the server.
void SetGravity(float a_Gravity)
void SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ)
Sets the speed of the entity, measured in m / sec.
void SetPosition(double a_PosX, double a_PosY, double a_PosZ)
float GetWidth(void) const
bool IsMinecart(void) const
UInt32 GetUniqueID(void) const
float GetHeight(void) const
void SetAirDrag(float a_AirDrag)
void StopBurning(void)
Stops the entity from burning, resets all burning timers.
long int GetTicksAlive(void) const
Gets number of ticks this entity has been alive for.
const Vector3d & GetPosition(void) const
Exported in ManualBindings.
void SetYawFromSpeed(void)
Sets the rotation to match the speed vector (entity goes "face-forward")
virtual void BroadcastMovementUpdate(const cClientHandle *a_Exclude=nullptr)
Updates clients of changes in the entity.
void StartBurning(int a_TicksLeftBurning)
Puts the entity on fire for the specified amount of ticks.
bool IsGameModeSpectator(void) const
Returns true if the player is in Spectator mode, either explicitly, or by inheriting from current wor...
cProjectileEntity * m_Projectile
virtual bool OnNextBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, eBlockFace a_EntryFace) override
cProjectileTracerCallback(cProjectileEntity *a_Projectile)
double GetSlowdownCoeff(void) const
cProjectileEntityCollisionCallback(cProjectileEntity *a_Projectile, const Vector3d &a_Pos, const Vector3d &a_NextPos)
bool operator()(cEntity &a_Entity)
cProjectileEntity * m_Projectile
const Vector3d & m_NextPos
cEntity * GetHitEntity(void) const
Returns the nearest entity that was hit, after the enumeration has been completed.
bool HasHit(void) const
Returns true if the callback has encountered a true hit.
double GetMinCoeff(void) const
Returns the line coeff where the hit was encountered, after the enumeration has been completed.
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.
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.
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...
cFireworkItem m_FireworkItem
bool Trace(Vector3d a_Start, Vector3d a_End)
Traces one line between Start and End; returns true if the entire line was traced (until OnNoMoreHits...
bool DoWithEntityByID(UInt32 a_UniqueID, cEntityCallback a_Callback)
Calls the callback if the entity with the specified ID is found, with the entity object as the callba...
std::vector< int > m_Colours