the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "net.minecraft.world.entity.h"
3#include "net.minecraft.world.level.pathfinder.h"
4#include "path.h"
5
6Path::~Path()
7{
8 if( nodes.data )
9 {
10 for( int i = 0; i < nodes.length; i++ )
11 delete nodes.data[i];
12 delete[] nodes.data;
13 }
14}
15
16Path::Path(NodeArray nodes)
17{
18 index = 0;
19
20 length = nodes.length;
21 // 4J - copying these nodes over from a NodeArray (which is an array of Node * references) to just a straight array of Nodes,
22 // so that this Path is no longer dependent of Nodes allocated elsewhere and can handle its own destruction
23 // Note: cameFrom pointer will be useless now but that isn't used once this is just a path
24 this->nodes = NodeArray(length);
25
26 for( int i = 0; i < length; i++ )
27 {
28 this->nodes.data[i] = new Node();
29 memcpy(this->nodes.data[i],nodes[i],sizeof(Node));
30 }
31}
32
33void Path::next()
34{
35 index++;
36}
37
38bool Path::isDone()
39{
40 return index >= length;
41}
42
43Node *Path::last()
44{
45 if (length > 0)
46 {
47 return nodes[length - 1];
48 }
49 return NULL;
50}
51
52Node *Path::get(int i)
53{
54 return nodes[i];
55}
56
57int Path::getSize()
58{
59 return length;
60}
61
62void Path::setSize(int length)
63{
64 this->length = length;
65}
66
67int Path::getIndex()
68{
69 return index;
70}
71
72void Path::setIndex(int index)
73{
74 this->index = index;
75}
76
77Vec3 *Path::getPos(shared_ptr<Entity> e, int index)
78{
79 double x = nodes[index]->x + (int) (e->bbWidth + 1) * 0.5;
80 double y = nodes[index]->y;
81 double z = nodes[index]->z + (int) (e->bbWidth + 1) * 0.5;
82 return Vec3::newTemp(x, y, z);
83}
84
85Vec3 *Path::currentPos(shared_ptr<Entity> e)
86{
87 return getPos(e, index);
88}
89
90Vec3 *Path::currentPos()
91{
92 return Vec3::newTemp( nodes[index]->x, nodes[index]->y, nodes[index]->z );
93}
94
95bool Path::sameAs(Path *path)
96{
97 if (path == NULL) return false;
98 if (path->nodes.length != nodes.length) return false;
99 for (int i = 0; i < nodes.length; ++i)
100 if (nodes[i]->x != path->nodes[i]->x || nodes[i]->y != path->nodes[i]->y || nodes[i]->z != path->nodes[i]->z) return false;
101 return true;
102}
103
104bool Path::endsIn(Vec3 *pos)
105{
106 Node *lastNode = last();
107 if (lastNode == NULL) return false;
108 return lastNode->x == (int) pos->x && lastNode->y == (int) pos->y && lastNode->z == (int) pos->z;
109}
110
111bool Path::endsInXZ(Vec3 *pos)
112{
113 Node *lastNode = last();
114 if (lastNode == NULL) return false;
115 return lastNode->x == (int) pos->x && lastNode->z == (int) pos->z;
116}