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.h"
4#include "net.minecraft.world.level.tile.h"
5#include "net.minecraft.world.h"
6#include "SharedConstants.h"
7#include "BreakDoorGoal.h"
8
9BreakDoorGoal::BreakDoorGoal(Mob *mob) : DoorInteractGoal(mob)
10{
11 breakTime = 0;
12 lastBreakProgress = -1;
13}
14
15bool BreakDoorGoal::canUse()
16{
17 if (!DoorInteractGoal::canUse()) return false;
18 if (!mob->level->getGameRules()->getBoolean(GameRules::RULE_MOBGRIEFING)) return false;
19 return !doorTile->isOpen(mob->level, doorX, doorY, doorZ);
20}
21
22void BreakDoorGoal::start()
23{
24 DoorInteractGoal::start();
25 breakTime = 0;
26}
27
28bool BreakDoorGoal::canContinueToUse()
29{
30 double d = mob->distanceToSqr(doorX, doorY, doorZ);
31 return breakTime <= DOOR_BREAK_TIME && !doorTile->isOpen(mob->level, doorX, doorY, doorZ) && d < 2 * 2;
32}
33
34void BreakDoorGoal::stop()
35{
36 DoorInteractGoal::stop();
37 mob->level->destroyTileProgress(mob->entityId, doorX, doorY, doorZ, -1);
38}
39
40void BreakDoorGoal::tick()
41{
42 DoorInteractGoal::tick();
43 if (mob->getRandom()->nextInt(20) == 0)
44 {
45 mob->level->levelEvent(LevelEvent::SOUND_ZOMBIE_WOODEN_DOOR, doorX, doorY, doorZ, 0);
46 }
47
48 breakTime++;
49
50 int progress = (int) (breakTime / (float) DOOR_BREAK_TIME * 10);
51 if (progress != lastBreakProgress)
52 {
53 mob->level->destroyTileProgress(mob->entityId, doorX, doorY, doorZ, progress);
54 lastBreakProgress = progress;
55 }
56
57 if (breakTime == DOOR_BREAK_TIME)
58 {
59 if (mob->level->difficulty == Difficulty::HARD)
60 {
61 mob->level->removeTile(doorX, doorY, doorZ);
62 mob->level->levelEvent(LevelEvent::SOUND_ZOMBIE_DOOR_CRASH, doorX, doorY, doorZ, 0);
63 mob->level->levelEvent(LevelEvent::PARTICLES_DESTROY_BLOCK, doorX, doorY, doorZ, doorTile->id);
64 }
65 }
66}