diff options
author | Samuel Barney <samjbarney@gmail.com> | 2014-08-26 01:22:56 +0200 |
---|---|---|
committer | Samuel Barney <samjbarney@gmail.com> | 2014-08-26 01:22:56 +0200 |
commit | 95c4b00dd0c2b23a6cf85f9f68cbd378d30989ad (patch) | |
tree | 312b439f6d5c31a279dd1491dece1c1806626011 /src/Mobs/Components/MovementComponent.cpp | |
parent | Added functionality to the Environment Component. (diff) | |
download | cuberite-95c4b00dd0c2b23a6cf85f9f68cbd378d30989ad.tar cuberite-95c4b00dd0c2b23a6cf85f9f68cbd378d30989ad.tar.gz cuberite-95c4b00dd0c2b23a6cf85f9f68cbd378d30989ad.tar.bz2 cuberite-95c4b00dd0c2b23a6cf85f9f68cbd378d30989ad.tar.lz cuberite-95c4b00dd0c2b23a6cf85f9f68cbd378d30989ad.tar.xz cuberite-95c4b00dd0c2b23a6cf85f9f68cbd378d30989ad.tar.zst cuberite-95c4b00dd0c2b23a6cf85f9f68cbd378d30989ad.zip |
Diffstat (limited to 'src/Mobs/Components/MovementComponent.cpp')
-rw-r--r-- | src/Mobs/Components/MovementComponent.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/Mobs/Components/MovementComponent.cpp b/src/Mobs/Components/MovementComponent.cpp index 6e92928d4..f99e89103 100644 --- a/src/Mobs/Components/MovementComponent.cpp +++ b/src/Mobs/Components/MovementComponent.cpp @@ -2,4 +2,32 @@ #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; + } +} |