blob: 3f7e2ed98b0c2ddb8229aa551c068ecf7a392f58 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#include "stdafx.h"
#include "net.minecraft.world.entity.ai.navigation.h"
#include "net.minecraft.world.entity.ai.village.h"
#include "net.minecraft.world.entity.h"
#include "net.minecraft.world.level.h"
#include "RestrictOpenDoorGoal.h"
RestrictOpenDoorGoal::RestrictOpenDoorGoal(PathfinderMob *mob)
{
this->mob = mob;
}
bool RestrictOpenDoorGoal::canUse()
{
if (mob->level->isDay()) return false;
shared_ptr<Village> village = mob->level->villages->getClosestVillage(Mth::floor(mob->x), Mth::floor(mob->y), Mth::floor(mob->z), 16);
if (village == nullptr) return false;
shared_ptr<DoorInfo> _doorInfo = village->getClosestDoorInfo(Mth::floor(mob->x), Mth::floor(mob->y), Mth::floor(mob->z));
if (_doorInfo == nullptr) return false;
doorInfo = _doorInfo;
return _doorInfo->distanceToInsideSqr(Mth::floor(mob->x), Mth::floor(mob->y), Mth::floor(mob->z)) < 1.5 * 1.5;
}
bool RestrictOpenDoorGoal::canContinueToUse()
{
if (mob->level->isDay()) return false;
shared_ptr<DoorInfo> _doorInfo = doorInfo.lock();
if ( _doorInfo == nullptr ) return false;
return !_doorInfo->removed && _doorInfo->isInsideSide(Mth::floor(mob->x), Mth::floor(mob->z));
}
void RestrictOpenDoorGoal::start()
{
mob->getNavigation()->setCanOpenDoors(false);
mob->getNavigation()->setCanPassDoors(false);
}
void RestrictOpenDoorGoal::stop()
{
mob->getNavigation()->setCanOpenDoors(true);
mob->getNavigation()->setCanPassDoors(true);
doorInfo = weak_ptr<DoorInfo>();
}
void RestrictOpenDoorGoal::tick()
{
shared_ptr<DoorInfo> _doorInfo = doorInfo.lock();
if ( _doorInfo ) _doorInfo->incBookingCount();
}
|