aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/BreakDoorGoal.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/BreakDoorGoal.cpp
parentdef8cb415354ac390b7e89052a50605285f1aca9 (diff)
Initial commit
Diffstat (limited to 'Minecraft.World/BreakDoorGoal.cpp')
-rw-r--r--Minecraft.World/BreakDoorGoal.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/Minecraft.World/BreakDoorGoal.cpp b/Minecraft.World/BreakDoorGoal.cpp
new file mode 100644
index 00000000..e4581c67
--- /dev/null
+++ b/Minecraft.World/BreakDoorGoal.cpp
@@ -0,0 +1,65 @@
+#include "stdafx.h"
+#include "net.minecraft.world.entity.h"
+#include "net.minecraft.world.level.h"
+#include "net.minecraft.world.level.tile.h"
+#include "net.minecraft.world.h"
+#include "SharedConstants.h"
+#include "BreakDoorGoal.h"
+
+BreakDoorGoal::BreakDoorGoal(Mob *mob) : DoorInteractGoal(mob)
+{
+ breakTime = 0;
+ lastBreakProgress = -1;
+}
+
+bool BreakDoorGoal::canUse()
+{
+ if (!DoorInteractGoal::canUse()) return false;
+ return !doorTile->isOpen(mob->level, doorX, doorY, doorZ);
+}
+
+void BreakDoorGoal::start()
+{
+ DoorInteractGoal::start();
+ breakTime = 0;
+}
+
+bool BreakDoorGoal::canContinueToUse()
+{
+ double d = mob->distanceToSqr(doorX, doorY, doorZ);
+ return breakTime <= DOOR_BREAK_TIME && !doorTile->isOpen(mob->level, doorX, doorY, doorZ) && d < 2 * 2;
+}
+
+void BreakDoorGoal::stop()
+{
+ DoorInteractGoal::stop();
+ mob->level->destroyTileProgress(mob->entityId, doorX, doorY, doorZ, -1);
+}
+
+void BreakDoorGoal::tick()
+{
+ DoorInteractGoal::tick();
+ if (mob->getRandom()->nextInt(20) == 0)
+ {
+ mob->level->levelEvent(LevelEvent::SOUND_ZOMBIE_WOODEN_DOOR, doorX, doorY, doorZ, 0);
+ }
+
+ breakTime++;
+
+ int progress = (int) (breakTime / (float) DOOR_BREAK_TIME * 10);
+ if (progress != lastBreakProgress)
+ {
+ mob->level->destroyTileProgress(mob->entityId, doorX, doorY, doorZ, progress);
+ lastBreakProgress = progress;
+ }
+
+ if (breakTime == DOOR_BREAK_TIME)
+ {
+ if (mob->level->difficulty == Difficulty::HARD)
+ {
+ mob->level->setTile(doorX, doorY, doorZ, 0);
+ mob->level->levelEvent(LevelEvent::SOUND_ZOMBIE_DOOR_CRASH, doorX, doorY, doorZ, 0);
+ mob->level->levelEvent(LevelEvent::PARTICLES_DESTROY_BLOCK, doorX, doorY, doorZ, doorTile->id);
+ }
+ }
+} \ No newline at end of file