blob: e8b791d13dd6a4a49763612539dfb74558af8ece (
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
50
51
|
#include "stdafx.h"
#include "net.minecraft.world.entity.npc.h"
#include "net.minecraft.world.entity.ai.control.h"
#include "net.minecraft.world.entity.ai.navigation.h"
#include "net.minecraft.world.inventory.h"
#include "TradeWithPlayerGoal.h"
TradeWithPlayerGoal::TradeWithPlayerGoal(Villager *mob)
{
this->mob = mob;
setRequiredControlFlags(Control::JumpControlFlag | Control::MoveControlFlag);
}
bool TradeWithPlayerGoal::canUse()
{
if (!mob->isAlive()) return false;
if (mob->isInWater()) return false;
if (!mob->onGround) return false;
if (mob->hurtMarked) return false;
shared_ptr<Player> trader = mob->getTradingPlayer();
if (trader == NULL)
{
// no interaction
return false;
}
if (mob->distanceToSqr(trader) > (4 * 4))
{
// too far away
return false;
}
if (!(trader->containerMenu == trader->inventoryMenu))
{
// closed container
return false;
}
return true;
}
void TradeWithPlayerGoal::start()
{
mob->getNavigation()->stop();
}
void TradeWithPlayerGoal::stop()
{
mob->setTradingPlayer(nullptr);
}
|