Files
MinecraftConsoles/Minecraft.World/BreakDoorGoal.cpp
ModMaker101 a9be52c41a Project modernization (#630)
* Fixed boats falling and a TP glitch #266

* Replaced every C-style cast with C++ ones

* Replaced every C-style cast with C++ ones

* Fixed boats falling and a TP glitch #266

* Updated NULL to nullptr and fixing some type issues

* Modernized and fixed a few bugs

- Replaced most instances of `NULL` with `nullptr`.
- Replaced most `shared_ptr(new ...)` with `make_shared`.
- Removed the `nullptr` macro as it was interfering with the actual nullptr keyword in some instances.

* Fixing more conflicts

* Replace int loops with size_t and start work on overrides
2026-03-08 09:56:03 +07:00

66 lines
1.7 KiB
C++

#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;
if (!mob->level->getGameRules()->getBoolean(GameRules::RULE_MOBGRIEFING)) 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 = static_cast<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->removeTile(doorX, doorY, doorZ);
mob->level->levelEvent(LevelEvent::SOUND_ZOMBIE_DOOR_CRASH, doorX, doorY, doorZ, 0);
mob->level->levelEvent(LevelEvent::PARTICLES_DESTROY_BLOCK, doorX, doorY, doorZ, doorTile->id);
}
}
}