summaryrefslogtreecommitdiffstats
path: root/source/Entities/ProjectileEntity.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-09-07 17:14:37 +0200
committermadmaxoft <github@xoft.cz>2013-09-07 17:14:37 +0200
commit3f4718154bcce6fd06939fcc0f0b20ea7181be1e (patch)
treec46f4da46e44156681ed79fbe5ecb1f65c88d9f6 /source/Entities/ProjectileEntity.cpp
parentRemoved an unused include (diff)
downloadcuberite-3f4718154bcce6fd06939fcc0f0b20ea7181be1e.tar
cuberite-3f4718154bcce6fd06939fcc0f0b20ea7181be1e.tar.gz
cuberite-3f4718154bcce6fd06939fcc0f0b20ea7181be1e.tar.bz2
cuberite-3f4718154bcce6fd06939fcc0f0b20ea7181be1e.tar.lz
cuberite-3f4718154bcce6fd06939fcc0f0b20ea7181be1e.tar.xz
cuberite-3f4718154bcce6fd06939fcc0f0b20ea7181be1e.tar.zst
cuberite-3f4718154bcce6fd06939fcc0f0b20ea7181be1e.zip
Diffstat (limited to 'source/Entities/ProjectileEntity.cpp')
-rw-r--r--source/Entities/ProjectileEntity.cpp37
1 files changed, 30 insertions, 7 deletions
diff --git a/source/Entities/ProjectileEntity.cpp b/source/Entities/ProjectileEntity.cpp
index b97f72884..81ac336f0 100644
--- a/source/Entities/ProjectileEntity.cpp
+++ b/source/Entities/ProjectileEntity.cpp
@@ -16,6 +16,13 @@
+/// Converts an angle in radians into a byte representation used by the network protocol
+#define ANGLE_TO_PROTO(X) (Byte)(X * 255 / 360)
+
+
+
+
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cProjectileTracerCallback:
@@ -189,6 +196,8 @@ cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, const Ve
m_IsInGround(false)
{
SetSpeed(a_Speed);
+ SetRotationFromSpeed();
+ SetPitchFromSpeed();
}
@@ -321,12 +330,15 @@ void cProjectileEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
NewSpeed.y += m_Gravity / 20;
NewSpeed *= TracerCallback.GetSlowdownCoeff();
SetSpeed(NewSpeed);
+ SetRotationFromSpeed();
+ SetPitchFromSpeed();
// DEBUG:
- LOGD("Projectile %d: pos {%.02f, %.02f, %.02f}, speed {%.02f, %.02f, %.02f}",
+ LOGD("Projectile %d: pos {%.02f, %.02f, %.02f}, speed {%.02f, %.02f, %.02f}, rot {%.02f, %.02f}",
m_UniqueID,
GetPosX(), GetPosY(), GetPosZ(),
- GetSpeedX(), GetSpeedY(), GetSpeedZ()
+ GetSpeedX(), GetSpeedY(), GetSpeedZ(),
+ GetRotation(), GetPitch()
);
}
@@ -337,7 +349,8 @@ void cProjectileEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
void cProjectileEntity::SpawnOn(cClientHandle & a_Client)
{
// Default spawning - use the projectile kind to spawn an object:
- a_Client.SendSpawnObject(*this, m_ProjectileKind, 0, 0, 0);
+ a_Client.SendSpawnObject(*this, m_ProjectileKind, 12, ANGLE_TO_PROTO(GetRotation()), ANGLE_TO_PROTO(GetPitch()));
+ a_Client.SendEntityMetadata(*this);
}
@@ -355,8 +368,11 @@ cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a
{
SetSpeed(a_Speed);
SetMass(0.1);
- LOGD("Created arrow %d with speed {%.02f, %.02f, %.02f}",
- m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ()
+ SetRotationFromSpeed();
+ SetPitchFromSpeed();
+ LOGD("Created arrow %d with speed {%.02f, %.02f, %.02f} and rot {%.02f, %.02f}",
+ m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ(),
+ GetRotation(), GetPitch()
);
}
@@ -392,14 +408,21 @@ bool cArrowEntity::CanPickup(const cPlayer & a_Player) const
-void cArrowEntity::SpawnOn(cClientHandle & a_Client)
+void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace)
{
- a_Client.SendSpawnObject(*this, pkArrow, 0, 0, 0);
+ super::OnHitSolidBlock(a_HitPos, a_HitFace);
+
+ // Broadcast the position and speed packets before teleporting:
+ BroadcastMovementUpdate();
+
+ // Teleport the entity to the exact hit coords:
+ m_World->BroadcastTeleportEntity(*this);
}
+
void cArrowEntity::OnHitEntity(cEntity & a_EntityHit)
{
if (!a_EntityHit.IsMob() && !a_EntityHit.IsMinecart() && !a_EntityHit.IsPlayer())