summaryrefslogtreecommitdiffstats
path: root/source/Entities/ProjectileEntity.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2013-11-12 22:43:20 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2013-11-12 22:43:20 +0100
commit347162a82f2cba75c4eb7739d4405ea78de4f0b5 (patch)
tree35409f6d8f6061ae3f8fa4569c0962a8bd569186 /source/Entities/ProjectileEntity.cpp
parentBundled fixes [SEE DESC] (diff)
downloadcuberite-347162a82f2cba75c4eb7739d4405ea78de4f0b5.tar
cuberite-347162a82f2cba75c4eb7739d4405ea78de4f0b5.tar.gz
cuberite-347162a82f2cba75c4eb7739d4405ea78de4f0b5.tar.bz2
cuberite-347162a82f2cba75c4eb7739d4405ea78de4f0b5.tar.lz
cuberite-347162a82f2cba75c4eb7739d4405ea78de4f0b5.tar.xz
cuberite-347162a82f2cba75c4eb7739d4405ea78de4f0b5.tar.zst
cuberite-347162a82f2cba75c4eb7739d4405ea78de4f0b5.zip
Diffstat (limited to 'source/Entities/ProjectileEntity.cpp')
-rw-r--r--source/Entities/ProjectileEntity.cpp107
1 files changed, 104 insertions, 3 deletions
diff --git a/source/Entities/ProjectileEntity.cpp b/source/Entities/ProjectileEntity.cpp
index 08f46b3d9..c63b9523b 100644
--- a/source/Entities/ProjectileEntity.cpp
+++ b/source/Entities/ProjectileEntity.cpp
@@ -371,6 +371,16 @@ void cProjectileEntity::SpawnOn(cClientHandle & a_Client)
+void cProjectileEntity::CollectedBy(cPlayer * a_Dest)
+{
+ // Overriden in arrow
+ UNUSED(a_Dest);
+}
+
+
+
+
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cArrowEntity:
@@ -378,7 +388,10 @@ cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a
super(pkArrow, a_Creator, a_X, a_Y, a_Z, 0.5, 0.5),
m_PickupState(psNoPickup),
m_DamageCoeff(2),
- m_IsCritical(false)
+ m_IsCritical(false),
+ m_Timer(0),
+ m_bIsCollected(false),
+ m_HitBlockPos(Vector3i(0, 0, 0))
{
SetSpeed(a_Speed);
SetMass(0.1);
@@ -398,7 +411,10 @@ cArrowEntity::cArrowEntity(cPlayer & a_Player, double a_Force) :
super(pkArrow, &a_Player, a_Player.GetThrowStartPos(), a_Player.GetThrowSpeed(a_Force * 1.5 * 20), 0.5, 0.5),
m_PickupState(psInSurvivalOrCreative),
m_DamageCoeff(2),
- m_IsCritical((a_Force >= 1))
+ m_IsCritical((a_Force >= 1)),
+ m_Timer(0),
+ m_bIsCollected(false),
+ m_HitBlockPos(0, 0, 0)
{
}
@@ -424,7 +440,28 @@ bool cArrowEntity::CanPickup(const cPlayer & a_Player) const
void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace)
{
+ if (a_HitFace == BLOCK_FACE_NONE)
+ {
+ return;
+ }
+
super::OnHitSolidBlock(a_HitPos, a_HitFace);
+ int a_X = (int)a_HitPos.x, a_Y = (int)a_HitPos.y, a_Z = (int)a_HitPos.z;
+
+ if (a_HitFace != BLOCK_FACE_YP)
+ {
+ AddFaceDirection(a_X, a_Y, a_Z, a_HitFace);
+ }
+ else if (a_HitFace == BLOCK_FACE_YP) // These conditions because xoft got a little confused on block face directions, so AddFace works with all but YP & YM
+ {
+ a_Y--;
+ }
+ else
+ {
+ a_Y++;
+ }
+
+ m_HitBlockPos = Vector3i(a_X, a_Y, a_Z);
// Broadcast arrow hit sound
m_World->BroadcastSoundEffect("random.bowhit", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64));
@@ -442,7 +479,7 @@ void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace)
void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos)
{
- if (!a_EntityHit.IsMob() && !a_EntityHit.IsMinecart() && !a_EntityHit.IsPlayer())
+ if (!a_EntityHit.IsMob() && !a_EntityHit.IsMinecart() && !a_EntityHit.IsPlayer() && !a_EntityHit.IsBoat())
{
// Not an entity that interacts with an arrow
return;
@@ -455,6 +492,9 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos)
}
a_EntityHit.TakeDamage(dtRangedAttack, this, Damage, 1);
+ // Broadcast successful hit sound
+ m_World->BroadcastSoundEffect("random.successful_hit", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64));
+
Destroy();
}
@@ -462,6 +502,67 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos)
+void cArrowEntity::CollectedBy(cPlayer * a_Dest)
+{
+ if ((m_IsInGround) && (!m_bIsCollected) && (CanPickup(*a_Dest)))
+ {
+ int NumAdded = a_Dest->GetInventory().AddItem(E_ITEM_ARROW);
+ if (NumAdded > 0) // Only play effects if there was space in inventory
+ {
+ m_World->BroadcastCollectPickup((const cPickup &)*this, *a_Dest);
+ // Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;)
+ m_World->BroadcastSoundEffect("random.pop", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64));
+ m_bIsCollected = true;
+ }
+ }
+}
+
+
+
+
+
+void cArrowEntity::Tick(float a_Dt, cChunk & a_Chunk)
+{
+ super::Tick(a_Dt, a_Chunk);
+ m_Timer += a_Dt;
+
+ if (m_bIsCollected)
+ {
+ if (m_Timer > 500.f) // 0.5 seconds
+ {
+ Destroy();
+ return;
+ }
+ }
+ else if (m_Timer > 1000 * 60 * 5) // 5 minutes
+ {
+ Destroy();
+ return;
+ }
+
+ if (m_IsInGround)
+ {
+ int RelPosX = m_HitBlockPos.x - a_Chunk.GetPosX() * cChunkDef::Width;
+ int RelPosZ = m_HitBlockPos.z - a_Chunk.GetPosZ() * cChunkDef::Width;
+ cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelPosX, RelPosZ);
+
+ if (Chunk == NULL)
+ {
+ // Inside an unloaded chunk, abort
+ return;
+ }
+
+ if (Chunk->GetBlock(RelPosX, m_HitBlockPos.y, RelPosZ) == E_BLOCK_AIR) // Block attached to was destroyed?
+ {
+ m_IsInGround = false; // Yes, begin simulating physics again
+ }
+ }
+}
+
+
+
+
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cThrownEggEntity: