summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-06-26 18:42:28 +0200
committerMattes D <github@xoft.cz>2014-06-26 18:42:28 +0200
commite60b73ce69b715b1368058cf3992fe7ec197a077 (patch)
treee914e15ab89488db2454a86c47d7998104595367 /src/Entities
parentMerged branch 'howaner/Pickups'. (diff)
parentAdd comment. (diff)
downloadcuberite-e60b73ce69b715b1368058cf3992fe7ec197a077.tar
cuberite-e60b73ce69b715b1368058cf3992fe7ec197a077.tar.gz
cuberite-e60b73ce69b715b1368058cf3992fe7ec197a077.tar.bz2
cuberite-e60b73ce69b715b1368058cf3992fe7ec197a077.tar.lz
cuberite-e60b73ce69b715b1368058cf3992fe7ec197a077.tar.xz
cuberite-e60b73ce69b715b1368058cf3992fe7ec197a077.tar.zst
cuberite-e60b73ce69b715b1368058cf3992fe7ec197a077.zip
Diffstat (limited to 'src/Entities')
-rw-r--r--src/Entities/ArrowEntity.cpp51
-rw-r--r--src/Entities/Player.cpp6
-rw-r--r--src/Entities/Player.h2
3 files changed, 46 insertions, 13 deletions
diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp
index 8d2569125..4727f67a9 100644
--- a/src/Entities/ArrowEntity.cpp
+++ b/src/Entities/ArrowEntity.cpp
@@ -3,6 +3,7 @@
#include "Player.h"
#include "ArrowEntity.h"
#include "../Chunk.h"
+#include "FastRandom.h"
@@ -24,9 +25,9 @@ cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a
SetYawFromSpeed();
SetPitchFromSpeed();
LOGD("Created arrow %d with speed {%.02f, %.02f, %.02f} and rot {%.02f, %.02f}",
- m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ(),
- GetYaw(), GetPitch()
- );
+ m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ(),
+ GetYaw(), GetPitch()
+ );
}
@@ -44,6 +45,10 @@ cArrowEntity::cArrowEntity(cPlayer & a_Player, double a_Force) :
m_bIsCollected(false),
m_HitBlockPos(0, 0, 0)
{
+ if (a_Player.IsGameModeCreative())
+ {
+ m_PickupState = psInCreative;
+ }
}
@@ -109,7 +114,14 @@ 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));
+ m_World->BroadcastSoundEffect(
+ "random.successful_hit",
+ (int)std::floor(GetPosX() * 8.0),
+ (int)std::floor(GetPosY() * 8.0),
+ (int)std::floor(GetPosZ() * 8.0),
+ 0.5f,
+ 0.75f + ((float)((GetUniqueID() * 23) % 32)) / 64.0f
+ );
Destroy();
}
@@ -120,16 +132,33 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos)
void cArrowEntity::CollectedBy(cPlayer * a_Dest)
{
- if ((m_IsInGround) && (!m_bIsCollected) && (CanPickup(*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
+ // Do not add the arrow to the inventory when the player is in creative:
+ if (!a_Dest->IsGameModeCreative())
{
- 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;
+ int NumAdded = a_Dest->GetInventory().AddItem(E_ITEM_ARROW);
+ if (NumAdded == 0)
+ {
+ // No space in the inventory
+ return;
+ }
}
+
+ // TODO: BroadcastCollectPickup needs a cPickup, which we don't have
+ // m_World->BroadcastCollectPickup(*this, *a_Dest);
+
+ m_bIsCollected = true;
+
+ cFastRandom Random;
+ m_World->BroadcastSoundEffect(
+ "random.pop",
+ (int)std::floor(GetPosX() * 8.0),
+ (int)std::floor(GetPosY() * 8),
+ (int)std::floor(GetPosZ() * 8),
+ 0.2F,
+ ((Random.NextFloat(1.0F) - Random.NextFloat(1.0F)) * 0.7F + 1.0F) * 2.0F
+ );
}
}
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index e1e03fded..7b4fd219d 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -1,4 +1,4 @@
-
+
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Player.h"
@@ -412,6 +412,7 @@ void cPlayer::StartChargingBow(void)
LOGD("Player \"%s\" started charging their bow", GetName().c_str());
m_IsChargingBow = true;
m_BowCharge = 0;
+ m_World->BroadcastEntityMetadata(*this, m_ClientHandle);
}
@@ -424,6 +425,8 @@ int cPlayer::FinishChargingBow(void)
int res = m_BowCharge;
m_IsChargingBow = false;
m_BowCharge = 0;
+ m_World->BroadcastEntityMetadata(*this, m_ClientHandle);
+
return res;
}
@@ -436,6 +439,7 @@ void cPlayer::CancelChargingBow(void)
LOGD("Player \"%s\" cancelled charging their bow at a charge of %d", GetName().c_str(), m_BowCharge);
m_IsChargingBow = false;
m_BowCharge = 0;
+ m_World->BroadcastEntityMetadata(*this, m_ClientHandle);
}
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index b2142a18b..2f7957f16 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -404,7 +404,7 @@ public:
// cEntity overrides:
virtual bool IsCrouched (void) const { return m_IsCrouched; }
virtual bool IsSprinting(void) const { return m_IsSprinting; }
- virtual bool IsRclking (void) const { return IsEating(); }
+ virtual bool IsRclking (void) const { return IsEating() || IsChargingBow(); }
virtual void Detach(void);