summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSTRWarrior <niels.breuker@hotmail.nl>2014-01-27 14:40:31 +0100
committerSTRWarrior <niels.breuker@hotmail.nl>2014-01-27 14:40:31 +0100
commited95f4d81b3f54111430aec00d429aff267dfa92 (patch)
tree5e9c88ca3bbf715ca16a6ac4a9787881807c43fc
parentMerge pull request #589 from mc-server/minecartimprovements (diff)
downloadcuberite-ed95f4d81b3f54111430aec00d429aff267dfa92.tar
cuberite-ed95f4d81b3f54111430aec00d429aff267dfa92.tar.gz
cuberite-ed95f4d81b3f54111430aec00d429aff267dfa92.tar.bz2
cuberite-ed95f4d81b3f54111430aec00d429aff267dfa92.tar.lz
cuberite-ed95f4d81b3f54111430aec00d429aff267dfa92.tar.xz
cuberite-ed95f4d81b3f54111430aec00d429aff267dfa92.tar.zst
cuberite-ed95f4d81b3f54111430aec00d429aff267dfa92.zip
-rw-r--r--src/Mobs/Villager.cpp72
-rw-r--r--src/Mobs/Villager.h5
2 files changed, 76 insertions, 1 deletions
diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp
index c8ff4f101..0bf87157a 100644
--- a/src/Mobs/Villager.cpp
+++ b/src/Mobs/Villager.cpp
@@ -3,6 +3,8 @@
#include "Villager.h"
#include "../World.h"
+#include "../Blockarea.h"
+#include "../Blocks/BlockHandler.h"
@@ -10,7 +12,8 @@
cVillager::cVillager(eVillagerType VillagerType) :
super("Villager", mtVillager, "", "", 0.6, 1.8),
- m_Type(VillagerType)
+ m_Type(VillagerType),
+ m_DidFindCrops(false)
{
}
@@ -33,3 +36,70 @@ void cVillager::DoTakeDamage(TakeDamageInfo & a_TDI)
+
+void cVillager::Tick(float a_Dt, cChunk & a_Chunk)
+{
+ super::Tick(a_Dt, a_Chunk);
+ if (m_DidFindCrops)
+ {
+ Vector3i Pos = Vector3i(GetPosition());
+ std::cout << Pos.Equals(m_CropsPos) << "\n";
+ if (Pos.Equals(m_CropsPos))
+ {
+ cBlockHandler Handler(E_BLOCK_CROPS);
+ Handler.DropBlock(m_World, this, m_CropsPos.x, m_CropsPos.y, m_CropsPos.z);
+ m_DidFindCrops = false;
+ }
+ }
+
+ if (m_World->GetTickRandomNumber(50) != 0)
+ {
+ return;
+ }
+
+ switch (m_Type)
+ {
+ case vtFarmer:
+ {
+ HandleFarmer();
+ }
+ }
+
+}
+
+
+
+
+void cVillager::HandleFarmer()
+{
+ cBlockArea Surrounding;
+ Surrounding.Read(m_World,
+ (int) GetPosX() - 5,
+ (int) GetPosX() + 5,
+ (int) GetPosY() - 3,
+ (int) GetPosY() + 3,
+ (int) GetPosZ() - 5,
+ (int) GetPosZ() + 5);
+
+ // Check for crops in a 10x6x10 area.
+ for (int X = 0; X < 10; X++)
+ {
+ for (int Y = 0; Y < 6; Y++)
+ {
+ for (int Z = 0; Z < 10; Z++)
+ {
+ if (Surrounding.GetRelBlockType(X, Y, Z) == E_BLOCK_CROPS && Surrounding.GetRelBlockMeta(X, Y, Z) == 0x7)
+ {
+ m_DidFindCrops = true;
+ m_CropsPos = Vector3i((int) GetPosX() + X - 5, (int) GetPosY() + Y - 3, (int) GetPosZ() + Z - 5);
+ MoveToPosition(Vector3f((float) GetPosX() + X - 5, (float) GetPosY() + Y - 3, (float) GetPosZ() + Z - 5));
+ return;
+ }
+ }
+ }
+ }
+}
+
+
+
+
diff --git a/src/Mobs/Villager.h b/src/Mobs/Villager.h
index 4cd9aaa8e..b7cbe8ed0 100644
--- a/src/Mobs/Villager.h
+++ b/src/Mobs/Villager.h
@@ -30,11 +30,16 @@ public:
CLASS_PROTODEF(cVillager);
virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override;
+ virtual void Tick (float a_Dt, cChunk & a_Chunk) override;
+
+ void HandleFarmer();
int GetVilType(void) const { return m_Type; }
private:
int m_Type;
+ bool m_DidFindCrops;
+ Vector3i m_CropsPos;
} ;