aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/Path.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Minecraft.World/Path.cpp')
-rw-r--r--Minecraft.World/Path.cpp116
1 files changed, 116 insertions, 0 deletions
diff --git a/Minecraft.World/Path.cpp b/Minecraft.World/Path.cpp
new file mode 100644
index 00000000..538917f6
--- /dev/null
+++ b/Minecraft.World/Path.cpp
@@ -0,0 +1,116 @@
+#include "stdafx.h"
+#include "net.minecraft.world.entity.h"
+#include "net.minecraft.world.level.pathfinder.h"
+#include "path.h"
+
+Path::~Path()
+{
+ if( nodes.data )
+ {
+ for( int i = 0; i < nodes.length; i++ )
+ delete nodes.data[i];
+ delete[] nodes.data;
+ }
+}
+
+Path::Path(NodeArray nodes)
+{
+ index = 0;
+
+ length = nodes.length;
+ // 4J - copying these nodes over from a NodeArray (which is an array of Node * references) to just a straight array of Nodes,
+ // so that this Path is no longer dependent of Nodes allocated elsewhere and can handle its own destruction
+ // Note: cameFrom pointer will be useless now but that isn't used once this is just a path
+ this->nodes = NodeArray(length);
+
+ for( int i = 0; i < length; i++ )
+ {
+ this->nodes.data[i] = new Node();
+ memcpy(this->nodes.data[i],nodes[i],sizeof(Node));
+ }
+}
+
+void Path::next()
+{
+ index++;
+}
+
+bool Path::isDone()
+{
+ return index >= length;
+}
+
+Node *Path::last()
+{
+ if (length > 0)
+ {
+ return nodes[length - 1];
+ }
+ return NULL;
+}
+
+Node *Path::get(int i)
+{
+ return nodes[i];
+}
+
+int Path::getSize()
+{
+ return length;
+}
+
+void Path::setSize(int length)
+{
+ this->length = length;
+}
+
+int Path::getIndex()
+{
+ return index;
+}
+
+void Path::setIndex(int index)
+{
+ this->index = index;
+}
+
+Vec3 *Path::getPos(shared_ptr<Entity> e, int index)
+{
+ double x = nodes[index]->x + (int) (e->bbWidth + 1) * 0.5;
+ double y = nodes[index]->y;
+ double z = nodes[index]->z + (int) (e->bbWidth + 1) * 0.5;
+ return Vec3::newTemp(x, y, z);
+}
+
+Vec3 *Path::currentPos(shared_ptr<Entity> e)
+{
+ return getPos(e, index);
+}
+
+Vec3 *Path::currentPos()
+{
+ return Vec3::newTemp( nodes[index]->x, nodes[index]->y, nodes[index]->z );
+}
+
+bool Path::sameAs(Path *path)
+{
+ if (path == NULL) return false;
+ if (path->nodes.length != nodes.length) return false;
+ for (int i = 0; i < nodes.length; ++i)
+ if (nodes[i]->x != path->nodes[i]->x || nodes[i]->y != path->nodes[i]->y || nodes[i]->z != path->nodes[i]->z) return false;
+ return true;
+}
+
+bool Path::endsIn(Vec3 *pos)
+{
+ Node *lastNode = last();
+ if (lastNode == NULL) return false;
+ return lastNode->x == (int) pos->x && lastNode->y == (int) pos->y && lastNode->z == (int) pos->z;
+}
+
+bool Path::endsInXZ(Vec3 *pos)
+{
+ Node *lastNode = last();
+ if (lastNode == NULL) return false;
+ return lastNode->x == (int) pos->x && lastNode->z == (int) pos->z;
+} \ No newline at end of file