summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2013-12-26 08:57:02 +0100
committerMattes D <github@xoft.cz>2013-12-26 08:57:02 +0100
commite0e01d0615fdeeb32a87dc74ca882e92a450ceb7 (patch)
tree22ef418f2fd3ff628fc010f52a5fe8e945519701 /src/Entities
parentMerge pull request #471 from mc-server/Fishing_Catapult (diff)
parentMoved increment operator to back of variables (diff)
downloadcuberite-e0e01d0615fdeeb32a87dc74ca882e92a450ceb7.tar
cuberite-e0e01d0615fdeeb32a87dc74ca882e92a450ceb7.tar.gz
cuberite-e0e01d0615fdeeb32a87dc74ca882e92a450ceb7.tar.bz2
cuberite-e0e01d0615fdeeb32a87dc74ca882e92a450ceb7.tar.lz
cuberite-e0e01d0615fdeeb32a87dc74ca882e92a450ceb7.tar.xz
cuberite-e0e01d0615fdeeb32a87dc74ca882e92a450ceb7.tar.zst
cuberite-e0e01d0615fdeeb32a87dc74ca882e92a450ceb7.zip
Diffstat (limited to 'src/Entities')
-rw-r--r--src/Entities/Entity.cpp25
-rw-r--r--src/Entities/Player.cpp23
2 files changed, 41 insertions, 7 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 8fcdcc82f..8a74c9da4 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -13,6 +13,7 @@
#include "../Bindings/PluginManager.h"
#include "../Tracer.h"
#include "Minecart.h"
+#include "Player.h"
@@ -239,10 +240,14 @@ void cEntity::TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_R
TDI.Attacker = a_Attacker;
TDI.RawDamage = a_RawDamage;
TDI.FinalDamage = a_FinalDamage;
- Vector3d Heading;
- Heading.x = sin(GetRotation());
- Heading.y = 0.4; // TODO: adjust the amount of "up" knockback when testing
- Heading.z = cos(GetRotation());
+
+ Vector3d Heading(0, 0, 0);
+ if (a_Attacker != NULL)
+ {
+ Heading = a_Attacker->GetLookVector() * (a_Attacker->IsSprinting() ? 10 : 8);
+ }
+ Heading.y = 2;
+
TDI.Knockback = Heading * a_KnockbackAmount;
DoTakeDamage(TDI);
}
@@ -297,6 +302,16 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
return;
}
+ if ((a_TDI.Attacker != NULL) && (a_TDI.Attacker->IsPlayer()))
+ {
+ // IsOnGround() only is false if the player is moving downwards
+ if (!((cPlayer *)a_TDI.Attacker)->IsOnGround()) // TODO: Better damage increase, and check for enchantments (and use magic critical instead of plain)
+ {
+ a_TDI.FinalDamage += 2;
+ m_World->BroadcastEntityAnimation(*this, 4); // Critical hit
+ }
+ }
+
m_Health -= (short)a_TDI.FinalDamage;
// TODO: Apply damage to armor
@@ -306,6 +321,8 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
m_Health = 0;
}
+ AddSpeed(a_TDI.Knockback * 2);
+
m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_HURT);
if (m_Health <= 0)
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index b923a094e..0fa8254ce 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -252,6 +252,11 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk)
m_World->SendPlayerList(this);
m_LastPlayerListTime = t1.GetNowTime();
}
+
+ if (IsFlying())
+ {
+ m_LastGroundHeight = (float)GetPosY();
+ }
}
@@ -452,10 +457,16 @@ void cPlayer::SetTouchGround(bool a_bTouchGround)
if (m_LastJumpHeight > m_LastGroundHeight) Damage++;
m_LastJumpHeight = (float)GetPosY();
- if ((Damage > 0) && (!IsGameModeCreative()))
+ if (Damage > 0)
{
- TakeDamage(dtFalling, NULL, Damage, Damage, 0);
- }
+ if (!IsGameModeCreative())
+ {
+ TakeDamage(dtFalling, NULL, Damage, Damage, 0);
+ }
+
+ // Mojang uses floor() to get X and Z positions, instead of just casting it to an (int)
+ GetWorld()->BroadcastSoundParticleEffect(2006, (int)floor(GetPosX()), (int)GetPosY() - 1, (int)floor(GetPosZ()), Damage /* Used as particle effect speed modifier */);
+ }
m_LastGroundHeight = (float)GetPosY();
}
@@ -979,6 +990,12 @@ void cPlayer::SetGameMode(eGameMode a_GameMode)
m_GameMode = a_GameMode;
m_ClientHandle->SendGameMode(a_GameMode);
+
+ if (!IsGameModeCreative())
+ {
+ SetFlying(false);
+ SetCanFly(false);
+ }
}