blob: e808e2948001c531d4a5d637133dfb3b8695ccaf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#include "Globals.h"
#include "MovementComponent.h"
#include "../Monster.h"
#include "../../World.h"
cMovementComponent::cMovementComponent(cMonster * a_Entity) : m_Self(a_Entity){}
int cMovementComponent::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ)
{
int PosY = (int)floor(m_Self->GetPosY());
PosY = Clamp(PosY, 0, cChunkDef::Height);
if (!cBlockInfo::IsSolid(m_Self->GetWorld()->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))))
{
while (!cBlockInfo::IsSolid(m_Self->GetWorld()->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))) && (PosY > 0))
{
PosY--;
}
return PosY + 1;
}
else
{
while (cBlockInfo::IsSolid(m_Self->GetWorld()->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))) && (PosY < cChunkDef::Height))
{
PosY++;
}
return PosY;
}
}
bool cMovementComponent::IsNextYPosReachable(int a_PosY)
{
return (
(a_PosY <= (int)floor(m_Self->GetPosY())) ||
DoesPosYRequireJump(a_PosY)
);
}
/** Returns if a monster can reach a given height by jumping */
bool cMovementComponent::DoesPosYRequireJump(int a_PosY)
{
return ((a_PosY > (int)floor(m_Self->GetPosY())) && (a_PosY == (int)floor(m_Self->GetPosY()) + 1));
}
|