aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/DoorInteractGoal.cpp
diff options
context:
space:
mode:
authordaoge_cmd <3523206925@qq.com>2026-03-01 12:16:08 +0800
committerdaoge_cmd <3523206925@qq.com>2026-03-01 12:16:08 +0800
commitb691c43c44ff180d10e7d4a9afc83b98551ff586 (patch)
tree3e9849222cbc6ba49f2f1fc6e5fe7179632c7390 /Minecraft.World/DoorInteractGoal.cpp
parentdef8cb415354ac390b7e89052a50605285f1aca9 (diff)
Initial commit
Diffstat (limited to 'Minecraft.World/DoorInteractGoal.cpp')
-rw-r--r--Minecraft.World/DoorInteractGoal.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/Minecraft.World/DoorInteractGoal.cpp b/Minecraft.World/DoorInteractGoal.cpp
new file mode 100644
index 00000000..1e3bfe11
--- /dev/null
+++ b/Minecraft.World/DoorInteractGoal.cpp
@@ -0,0 +1,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];
+} \ No newline at end of file