summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-01-25 20:02:13 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-01-25 20:02:13 +0100
commit7468ba0f107ed01275f346c87ff5bb265dbbff3d (patch)
tree5c1c2563b5e95bfbfb999dee891150b99369f926 /src
parentAttack() is no longer always called (diff)
downloadcuberite-7468ba0f107ed01275f346c87ff5bb265dbbff3d.tar
cuberite-7468ba0f107ed01275f346c87ff5bb265dbbff3d.tar.gz
cuberite-7468ba0f107ed01275f346c87ff5bb265dbbff3d.tar.bz2
cuberite-7468ba0f107ed01275f346c87ff5bb265dbbff3d.tar.lz
cuberite-7468ba0f107ed01275f346c87ff5bb265dbbff3d.tar.xz
cuberite-7468ba0f107ed01275f346c87ff5bb265dbbff3d.tar.zst
cuberite-7468ba0f107ed01275f346c87ff5bb265dbbff3d.zip
Diffstat (limited to 'src')
-rw-r--r--src/Entities/Entity.h5
-rw-r--r--src/Entities/Player.cpp6
-rw-r--r--src/Entities/Player.h2
-rw-r--r--src/Mobs/Monster.cpp31
-rw-r--r--src/Mobs/Monster.h8
5 files changed, 41 insertions, 11 deletions
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index f6fa58bb2..b2edfc2b4 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -29,6 +29,11 @@
return super::GetClass(); \
}
+#define POSX_TOINT (int)floor(GetPosX())
+#define POSY_TOINT (int)floor(GetPosY())
+#define POSZ_TOINT (int)floor(GetPosZ())
+#define POS_TOINT Vector3i(POSXTOINT, POSYTOINT, POSZTOINT)
+
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 2a5baedb6..71e304967 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -26,8 +26,6 @@
#include "inifile/iniFile.h"
#include "json/json.h"
-#define float2int(x) ((x)<0 ? ((int)(x))-1 : (int)(x))
-
@@ -440,7 +438,7 @@ void cPlayer::SetTouchGround(bool a_bTouchGround)
cWorld * World = GetWorld();
if ((GetPosY() >= 0) && (GetPosY() < cChunkDef::Height))
{
- BLOCKTYPE BlockType = World->GetBlock(float2int(GetPosX()), float2int(GetPosY()), float2int(GetPosZ()));
+ BLOCKTYPE BlockType = World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()));
if (BlockType != E_BLOCK_AIR)
{
m_bTouchGround = true;
@@ -470,7 +468,7 @@ void cPlayer::SetTouchGround(bool a_bTouchGround)
TakeDamage(dtFalling, NULL, Damage, Damage, 0);
}
- // Mojang uses floor() to get X and Z positions, instead of just casting it to an (int)
+ // Fall particles
GetWorld()->BroadcastSoundParticleEffect(2006, (int)floor(GetPosX()), (int)GetPosY() - 1, (int)floor(GetPosZ()), Damage /* Used as particle effect speed modifier */);
}
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index 449df978f..50f7560d6 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -415,7 +415,7 @@ protected:
float m_LastBlockActionTime;
int m_LastBlockActionCnt;
eGameMode m_GameMode;
- std::string m_IP;
+ AString m_IP;
/// The item being dragged by the cursor while in a UI window
cItem m_DraggingItem;
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index 9ba18f4d1..42c7d2899 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -82,6 +82,7 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString
, m_AttackRange(2)
, m_AttackInterval(0)
, m_BurnsInDaylight(false)
+ , m_LastGroundHeight(POSY_TOINT)
{
if (!a_ConfigName.empty())
{
@@ -113,7 +114,7 @@ void cMonster::TickPathFinding()
std::vector<Vector3d> m_PotentialCoordinates;
m_TraversedCoordinates.push_back(Vector3i(PosX, PosY, PosZ));
- static const struct // Define which directions the torch can power
+ static const struct // Define which directions to try to move to
{
int x, z;
} gCrossCoords[] =
@@ -261,9 +262,9 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk)
{
if (m_bOnGround)
{
- int NextHeight = FindFirstNonAirBlockPosition(m_Destination.x, m_Destination.z);
+ m_Destination.y = FindFirstNonAirBlockPosition(m_Destination.x, m_Destination.z);
- if (DoesPosYRequireJump(NextHeight))
+ if (DoesPosYRequireJump(m_Destination.y))
{
m_bOnGround = false;
AddPosY(1.5); // Jump!!
@@ -298,10 +299,11 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk)
}
}
- if (ReachedFinalDestination())
+ if (ReachedFinalDestination() && (m_Target != NULL))
Attack(a_Dt);
SetPitchAndYawFromDestination();
+ HandleFalling();
switch (m_EMState)
{
@@ -369,6 +371,27 @@ void cMonster::SetPitchAndYawFromDestination()
+void cMonster::HandleFalling()
+{
+ if (m_bOnGround)
+ {
+ int Damage = (m_LastGroundHeight - POSY_TOINT) - 3;
+
+ if (Damage > 0)
+ {
+ TakeDamage(dtFalling, NULL, Damage, Damage, 0);
+
+ // Fall particles
+ GetWorld()->BroadcastSoundParticleEffect(2006, POSX_TOINT, POSY_TOINT - 1, POSZ_TOINT, Damage /* Used as particle effect speed modifier */);
+ }
+
+ m_LastGroundHeight = (int)floor(GetPosY());
+ }
+}
+
+
+
+
int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ)
{
int PosY = (int)floor(GetPosY());
diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h
index d04cb8941..1dd302cdc 100644
--- a/src/Mobs/Monster.h
+++ b/src/Mobs/Monster.h
@@ -199,9 +199,13 @@ protected:
/** Sets the body yaw and head yaw/pitch based on next/ultimate destinations */
void SetPitchAndYawFromDestination(void);
- /* ===========================*/
+ /* =========================== */
+ /* ========= FALLING ========= */
-
+ virtual void HandleFalling(void);
+ int m_LastGroundHeight;
+
+ /* =========================== */
float m_IdleInterval;
float m_DestroyTimer;