summaryrefslogtreecommitdiffstats
path: root/source/ClientHandle.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-07-12 22:01:25 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-07-12 22:01:25 +0200
commit4fb771f3fffb63d8c54c9201ca6d2ce21bd09e5f (patch)
tree9b4f5f3e7da05719a3458c2d0e2a9694764b48c5 /source/ClientHandle.cpp
parentAdded the cFastRandom class (diff)
downloadcuberite-4fb771f3fffb63d8c54c9201ca6d2ce21bd09e5f.tar
cuberite-4fb771f3fffb63d8c54c9201ca6d2ce21bd09e5f.tar.gz
cuberite-4fb771f3fffb63d8c54c9201ca6d2ce21bd09e5f.tar.bz2
cuberite-4fb771f3fffb63d8c54c9201ca6d2ce21bd09e5f.tar.lz
cuberite-4fb771f3fffb63d8c54c9201ca6d2ce21bd09e5f.tar.xz
cuberite-4fb771f3fffb63d8c54c9201ca6d2ce21bd09e5f.tar.zst
cuberite-4fb771f3fffb63d8c54c9201ca6d2ce21bd09e5f.zip
Diffstat (limited to 'source/ClientHandle.cpp')
-rw-r--r--source/ClientHandle.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp
index 52f3b92ed..155eac38a 100644
--- a/source/ClientHandle.cpp
+++ b/source/ClientHandle.cpp
@@ -501,6 +501,13 @@ void cClientHandle::HandlePlayerPos(double a_PosX, double a_PosY, double a_PosZ,
SendPlayerMoveLook();
return;
}
+
+ // If a jump just started, process food exhaustion:
+ if ((a_PosY > m_Player->GetPosY()) && !a_IsOnGround && m_Player->IsOnGround())
+ {
+ m_Player->AddFoodExhaustion(m_Player->IsSprinting() ? 0.8 : 0.2);
+ }
+
m_Player->MoveTo(Pos);
m_Player->SetStance(a_Stance);
m_Player->SetTouchGround(a_IsOnGround);
@@ -1054,6 +1061,7 @@ void cClientHandle::HandleUseEntity(int a_TargetEntityID, bool a_IsLeftClick)
{
// TODO: Let plugins interfere via a hook
+ // If it is a right click, call the entity's OnRightClicked() handler:
if (!a_IsLeftClick)
{
class cRclkEntity : public cEntityCallback
@@ -1062,7 +1070,7 @@ void cClientHandle::HandleUseEntity(int a_TargetEntityID, bool a_IsLeftClick)
virtual bool Item(cEntity * a_Entity) override
{
a_Entity->OnRightClicked(m_Player);
- return true;
+ return false;
}
public:
cRclkEntity(cPlayer & a_Player) : m_Player(a_Player) {}
@@ -1073,24 +1081,22 @@ void cClientHandle::HandleUseEntity(int a_TargetEntityID, bool a_IsLeftClick)
return;
}
+ // If it is a left click, attack the entity:
class cDamageEntity : public cEntityCallback
{
virtual bool Item(cEntity * a_Entity) override
{
if (!a_Entity->GetWorld()->IsPVPEnabled())
{
- // PVP is disabled
- if (a_Entity->IsA("cPlayer") && m_Attacker->IsA("cPlayer"))
+ // PVP is disabled, disallow players hurting other players:
+ if (a_Entity->IsPlayer())
{
// Player is hurting another player which is not allowed when PVP is disabled so ignore it
return true;
}
}
- if (a_Entity->IsA("cPawn"))
- {
- reinterpret_cast<cPawn *>(a_Entity)->TakeDamage(*m_Attacker);
- }
- return true;
+ a_Entity->TakeDamage(*m_Attacker);
+ return false;
}
public:
cPawn * m_Attacker;
@@ -1099,7 +1105,11 @@ void cClientHandle::HandleUseEntity(int a_TargetEntityID, bool a_IsLeftClick)
Callback.m_Attacker = m_Player;
cWorld * World = m_Player->GetWorld();
- World->DoWithEntityByID(a_TargetEntityID, Callback);
+ if (World->DoWithEntityByID(a_TargetEntityID, Callback))
+ {
+ // Any kind of an attack implies food exhaustion
+ m_Player->AddFoodExhaustion(0.3);
+ }
}