1
0

Villager: Few more comments.

This commit is contained in:
STRWarrior 2014-01-27 21:39:00 +01:00
parent 33ad2761a0
commit 8bf9043f98
2 changed files with 9 additions and 4 deletions

View File

@ -50,7 +50,7 @@ void cVillager::Tick(float a_Dt, cChunk & a_Chunk)
{ {
case vtFarmer: case vtFarmer:
{ {
HandleFarmerNoCountDown(); HandleFarmerEndCountDown();
} }
} }
} }
@ -93,6 +93,8 @@ void cVillager::Tick(float a_Dt, cChunk & a_Chunk)
////////////////////////////////////////////////////////////////////////////////
// Farmer functions.
void cVillager::HandleFarmerAttemptSpecialAction() void cVillager::HandleFarmerAttemptSpecialAction()
{ {
cBlockArea Surrounding; cBlockArea Surrounding;
@ -107,7 +109,6 @@ void cVillager::HandleFarmerAttemptSpecialAction()
(int) GetPosZ() + 5 (int) GetPosZ() + 5
); );
for (int I = 0; I < 5; I++) for (int I = 0; I < 5; I++)
{ {
for (int Y = 0; Y < 6; Y++) for (int Y = 0; Y < 6; Y++)
@ -116,6 +117,7 @@ void cVillager::HandleFarmerAttemptSpecialAction()
int X = m_World->GetTickRandomNumber(11); int X = m_World->GetTickRandomNumber(11);
int Z = m_World->GetTickRandomNumber(11); int Z = m_World->GetTickRandomNumber(11);
// A villager can't farm this.
if (!IsBlockFarmable(Surrounding.GetRelBlockType(X, Y, Z))) if (!IsBlockFarmable(Surrounding.GetRelBlockType(X, Y, Z)))
{ {
continue; continue;
@ -139,8 +141,10 @@ void cVillager::HandleFarmerAttemptSpecialAction()
void cVillager::HandleFarmerAction() void cVillager::HandleFarmerAction()
{ {
// Harvest the crops if the villager isn't moving and if the crops are closer then 2 blocks.
if (!m_bMovingToDestination && (GetPosition() - m_CropsPos).Length() < 2) if (!m_bMovingToDestination && (GetPosition() - m_CropsPos).Length() < 2)
{ {
// Check if the blocks didn't change while the villager was walking to the coordinates.
BLOCKTYPE CropBlock = m_World->GetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z); BLOCKTYPE CropBlock = m_World->GetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z);
if (IsBlockFarmable(CropBlock) && m_World->GetBlockMeta(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z) == 0x7) if (IsBlockFarmable(CropBlock) && m_World->GetBlockMeta(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z) == 0x7)
{ {
@ -155,8 +159,9 @@ void cVillager::HandleFarmerAction()
void cVillager::HandleFarmerNoCountDown() void cVillager::HandleFarmerEndCountDown()
{ {
// Check if there is still farmland at the spot where the crops were.
if (m_World->GetBlock(m_CropsPos.x, m_CropsPos.y - 1, m_CropsPos.z) == E_BLOCK_FARMLAND) if (m_World->GetBlock(m_CropsPos.x, m_CropsPos.y - 1, m_CropsPos.z) == E_BLOCK_FARMLAND)
{ {
m_World->SetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z, E_BLOCK_CROPS, 0); m_World->SetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z, E_BLOCK_CROPS, 0);

View File

@ -39,7 +39,7 @@ public:
// Farmer functions // Farmer functions
void HandleFarmerAttemptSpecialAction(); void HandleFarmerAttemptSpecialAction();
void HandleFarmerAction(); void HandleFarmerAction();
void HandleFarmerNoCountDown(); void HandleFarmerEndCountDown();
// Get and set functions. // Get and set functions.
int GetVilType(void) const { return m_Type; } int GetVilType(void) const { return m_Type; }