blob: 1e3bfe11b2b3bc4e8879e2d544292c369c55228f (
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#include "stdafx.h"
#include "net.minecraft.world.entity.h"
#include "net.minecraft.world.entity.ai.navigation.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.pathfinder.h"
#include "net.minecraft.world.level.tile.h"
#include "DoorInteractGoal.h"
DoorInteractGoal::DoorInteractGoal(Mob *mob)
{
doorX = doorY = doorZ = 0;
doorTile = NULL;
passed = false;
doorOpenDirX = doorOpenDirZ = 0.0f;
this->mob = mob;
}
bool DoorInteractGoal::canUse()
{
if (!mob->horizontalCollision) return false;
PathNavigation *pathNav = mob->getNavigation();
Path *path = pathNav->getPath();
if (path == NULL || path->isDone() || !pathNav->canOpenDoors()) return false;
for (int i = 0; i < min(path->getIndex() + 2, path->getSize()); ++i)
{
Node *n = path->get(i);
doorX = n->x;
doorY = n->y + 1;
doorZ = n->z;
if (mob->distanceToSqr(doorX, mob->y, doorZ) > 1.5 * 1.5) continue;
doorTile = getDoorTile(doorX, doorY, doorZ);
if (doorTile == NULL) continue;
return true;
}
doorX = Mth::floor(mob->x);
doorY = Mth::floor(mob->y + 1);
doorZ = Mth::floor(mob->z);
doorTile = getDoorTile(doorX, doorY, doorZ);
return doorTile != NULL;
}
bool DoorInteractGoal::canContinueToUse()
{
return !passed;
}
void DoorInteractGoal::start()
{
passed = false;
doorOpenDirX = (float) (doorX + 0.5f - mob->x);
doorOpenDirZ = (float) (doorZ + 0.5f - mob->z);
}
void DoorInteractGoal::tick()
{
float newDoorDirX = (float) (doorX + 0.5f - mob->x);
float newDoorDirZ = (float) (doorZ + 0.5f - mob->z);
float dot = doorOpenDirX * newDoorDirX + doorOpenDirZ * newDoorDirZ;
if (dot < 0)
{
passed = true;
}
}
DoorTile *DoorInteractGoal::getDoorTile(int x, int y, int z)
{
int tileId = mob->level->getTile(x, y, z);
if (tileId != Tile::door_wood_Id) return NULL;
return (DoorTile *) Tile::tiles[tileId];
}
|