From 8bf9043f98900a870c18389fe367e156da6b9f6c Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Mon, 27 Jan 2014 21:39:00 +0100 Subject: Villager: Few more comments. --- src/Mobs/Villager.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/Mobs/Villager.cpp') diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index e39d8bc1f..262f13a99 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -50,7 +50,7 @@ void cVillager::Tick(float a_Dt, cChunk & a_Chunk) { case vtFarmer: { - HandleFarmerNoCountDown(); + HandleFarmerEndCountDown(); } } } @@ -93,6 +93,8 @@ void cVillager::Tick(float a_Dt, cChunk & a_Chunk) +//////////////////////////////////////////////////////////////////////////////// +// Farmer functions. void cVillager::HandleFarmerAttemptSpecialAction() { cBlockArea Surrounding; @@ -107,7 +109,6 @@ void cVillager::HandleFarmerAttemptSpecialAction() (int) GetPosZ() + 5 ); - for (int I = 0; I < 5; I++) { for (int Y = 0; Y < 6; Y++) @@ -116,6 +117,7 @@ void cVillager::HandleFarmerAttemptSpecialAction() int X = m_World->GetTickRandomNumber(11); int Z = m_World->GetTickRandomNumber(11); + // A villager can't farm this. if (!IsBlockFarmable(Surrounding.GetRelBlockType(X, Y, Z))) { continue; @@ -139,8 +141,10 @@ void cVillager::HandleFarmerAttemptSpecialAction() 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) { + // 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); 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) { m_World->SetBlock(m_CropsPos.x, m_CropsPos.y, m_CropsPos.z, E_BLOCK_CROPS, 0); -- cgit v1.2.3