6 #include "../BlockArea.h"
7 #include "../Blocks/BlockHandler.h"
8 #include "../BlockInServerPluginInterface.h"
15 Super(
"Villager",
mtVillager,
"entity.villager.hurt",
"entity.villager.death",
"entity.villager.ambient", 0.6f, 1.95f),
16 m_ActionCountDown(-1),
18 m_FarmerAction(faIdling),
181 for (
int Y = MinPos.y; Y <= MaxPos.y; Y++)
242 constexpr std::array<Vector3i, 4> Directions = {
Vector3i{0, 0, -1}, {0, 0, 1}, {1, 0, 0}, {-1, 0, 0} };
370 return a_BlockMeta == 0x03;
377 return a_BlockMeta == 0x07;
379 default:
return false;
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
unsigned char BLOCKTYPE
The datatype used by blockdata.
MTRand & GetRandomProvider()
Returns the current thread's random number source.
eMonsterType
Identifies individual monster type.
Vector3< double > Vector3d
bool Read(cForEachChunkProvider &a_ForEachChunkProvider, int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ, int a_DataTypes=baTypes|baMetas|baBlockEntities)
Reads an area of blocks specified.
void SetPitch(double a_Pitch)
bool IsPlayer(void) const
bool IsTicking(void) const
Returns true if the entity is valid and ticking.
double GetPosX(void) const
double GetPosZ(void) const
void Destroy()
Destroys the entity, schedules it for memory freeing and broadcasts the DestroyEntity packet.
double GetPosY(void) const
const Vector3d & GetPosition(void) const
Exported in ManualBindings.
IntType RandInt(IntType a_Min, IntType a_Max)
Return a random IntType in the range [a_Min, a_Max].
const cItem & GetSlot(int a_X, int a_Y) const
bool HasItems(const cItem &a_ItemStack)
Returns true if there are at least as many items of type a_ItemStack as in a_ItemStack.
cItem RemoveOneItem(int a_SlotNum)
Removes one item from the stack in the specified slot, and returns it.
Vector3d m_FinalDestination
Coordinates for the ultimate, final destination.
virtual void KilledBy(TakeDamageInfo &a_TDI) override
Called when the health drops below zero.
virtual void MoveToPosition(const Vector3d &a_Position)
Engage pathfinder and tell it to calculate a path to a given position, and move the mob accordingly.
eMonsterType GetMobType(void) const
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
virtual bool DoTakeDamage(TakeDamageInfo &a_TDI) override
When hit by someone, run away.
void TickFarmer()
Tick function for farmers.
bool IsPlantable(Vector3i a_CropsPos)
Returns true if seeds can be planted at a given location.
eFarmerAction m_FarmerAction
static eVillagerType GetRandomProfession()
Returns a random Profession.
static constexpr Vector3i FARMER_SCAN_CROPS_DIST
This distance from the Villager makes for a 31x3x31 area.
void HandleFarmerTryHarvestCrops()
Looks if the farmer has reached it's destination, and if it's still crops and the destination is clos...
bool IsHarvestable(Vector3i a_CropsPos)
Returns true if the block at the given location is a fully grown up crop.
void ScanAreaForWork()
Searches in a 31x3x31 area to harvest crops or spaces to plant crops.
static const int FARMER_RANDOM_TICK_SPEED
bool IsBlockFarmable(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Returns true if the given blocktype are: crops, potatoes or carrots and they have full grown up.
static constexpr double FARMER_SPECIAL_ACTION_CHANCE
With 10% chance, it takes about 20 seconds to find a spot.
bool CanPlantCrops()
Returns whether the farmer has crops in his inventory to plant.
bool IsIdling()
Returns whether the farmer is not working.
void CheckForNearbyCrops()
Checking for harvesting or planting nearby crops.
void HandleFarmerTryPlaceCrops()
Looks if the farmer has reached it's destination, and if it's still non obstructed farmland and the d...
virtual bool DoTakeDamage(TakeDamageInfo &a_TDI) override
When hit by someone, run away.
cVillager(eVillagerType VillagerType)
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
virtual void KilledBy(TakeDamageInfo &a_TDI) override
Called when the health drops below zero.
Vector3< T > addedY(T a_AddY) const
Returns a copy of this vector moved by the specified amount on the y axis.
Vector3< int > Floor(void) const
Returns a new Vector3i with coords set to std::floor() of this vector's coords.
bool DropBlockAsPickups(Vector3i a_BlockPos, const cEntity *a_Digger=nullptr, const cItem *a_Tool=nullptr)
Digs the specified block, and spawns the appropriate pickups for it.
virtual UInt32 SpawnMob(double a_PosX, double a_PosY, double a_PosZ, eMonsterType a_MonsterType, bool a_Baby=false) override
Spawns a mob of the specified type.
virtual void BroadcastEntityAnimation(const cEntity &a_Entity, EntityAnimation a_Animation, const cClientHandle *a_Exclude=nullptr) override
BLOCKTYPE GetBlock(Vector3i a_BlockPos) const
Returns the block type at the specified position.
int GetTickRandomNumber(int a_Range)
Returns a random number in range [0 .
virtual void BroadcastSoundParticleEffect(const EffectID a_EffectID, Vector3i a_SrcPos, int a_Data, const cClientHandle *a_Exclude=nullptr) override
bool VillagersShouldHarvestCrops(void) const
NIBBLETYPE GetBlockMeta(Vector3i a_BlockPos) const
Returns the block meta at the specified position.
void SetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Sets the block at the specified coords to the specified value.