* Add PathfinderMob base

* Normalize tab style in source/CMakeLists.txt
This commit is contained in:
iProgramInCpp 2023-12-06 21:20:14 +02:00
parent 8602de2428
commit 805087d36a
15 changed files with 471 additions and 112 deletions

View file

@ -353,9 +353,6 @@
<ClInclude Include="$(MC_ROOT)\source\client\player\input\CustomInputHolder.hpp">
<Filter>Header Files\Player\Input</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\GameMods.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\player\input\UnifiedTurnBuild.hpp">
<Filter>Header Files\Player\Input</Filter>
</ClInclude>
@ -371,60 +368,6 @@
<ClInclude Include="$(MC_ROOT)\source\client\model\QuadrupedModel.hpp">
<Filter>Header Files\Model</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\model\ChickenModel.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\model\CowModel.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\model\CreeperModel.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\model\PigModel.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\model\SheepFurModel.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\model\SheepModel.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\model\SkeletonModel.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\model\SpiderModel.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\model\ZombieModel.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\renderer\entity\ChickenRenderer.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\renderer\entity\CowRenderer.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\renderer\entity\CreeperRenderer.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\renderer\entity\PigRenderer.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\renderer\entity\SheepFurRenderer.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\renderer\entity\SheepRenderer.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\renderer\entity\SkeletonRenderer.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\renderer\entity\SpiderRenderer.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\renderer\entity\ZombieRenderer.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\renderer\GrassColor.hpp">
<Filter>Header Files\Renderer</Filter>
</ClInclude>
@ -434,6 +377,63 @@
<ClInclude Include="$(MC_ROOT)\source\client\gui\components\OptionList.hpp">
<Filter>Header Files\GUI\Components</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\renderer\entity\ZombieRenderer.hpp">
<Filter>Header Files\Renderer\Entity</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\renderer\entity\SpiderRenderer.hpp">
<Filter>Header Files\Renderer\Entity</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\renderer\entity\SkeletonRenderer.hpp">
<Filter>Header Files\Renderer\Entity</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\renderer\entity\SheepRenderer.hpp">
<Filter>Header Files\Renderer\Entity</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\renderer\entity\SheepFurRenderer.hpp">
<Filter>Header Files\Renderer\Entity</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\renderer\entity\PigRenderer.hpp">
<Filter>Header Files\Renderer\Entity</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\renderer\entity\CreeperRenderer.hpp">
<Filter>Header Files\Renderer\Entity</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\renderer\entity\CowRenderer.hpp">
<Filter>Header Files\Renderer\Entity</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\renderer\entity\ChickenRenderer.hpp">
<Filter>Header Files\Renderer\Entity</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\model\ZombieModel.hpp">
<Filter>Header Files\Model</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\model\ChickenModel.hpp">
<Filter>Header Files\Model</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\model\CowModel.hpp">
<Filter>Header Files\Model</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\model\CreeperModel.hpp">
<Filter>Header Files\Model</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\GameMods.hpp">
<Filter>Header Files\Model</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\model\PigModel.hpp">
<Filter>Header Files\Model</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\model\SheepFurModel.hpp">
<Filter>Header Files\Model</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\model\SheepModel.hpp">
<Filter>Header Files\Model</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\model\SkeletonModel.hpp">
<Filter>Header Files\Model</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\client\model\SpiderModel.hpp">
<Filter>Header Files\Model</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MC_ROOT)\source\client\gui\components\AvailableGamesList.cpp">

View file

@ -336,6 +336,10 @@
<ClCompile Include="$(MC_ROOT)\source\world\level\path\Path.cpp" />
<ClCompile Include="$(MC_ROOT)\source\world\level\path\PathFinder.cpp" />
<ClCompile Include="$(MC_ROOT)\source\world\level\path\BinaryHeap.cpp" />
<ClCompile Include="$(MC_ROOT)\source\world\entity\Animal.cpp" />
<ClCompile Include="$(MC_ROOT)\source\world\entity\Monster.cpp" />
<ClCompile Include="$(MC_ROOT)\source\world\entity\PathfinderMob.cpp" />
<ClCompile Include="$(MC_ROOT)\source\world\entity\WaterAnimal.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MC_ROOT)\source\world\entity\Entity.hpp" />
@ -435,6 +439,10 @@
<ClInclude Include="$(MC_ROOT)\source\world\level\path\Path.hpp" />
<ClInclude Include="$(MC_ROOT)\source\world\level\path\PathFinder.hpp" />
<ClInclude Include="$(MC_ROOT)\source\world\level\path\BinaryHeap.hpp" />
<ClInclude Include="$(MC_ROOT)\source\world\entity\Animal.hpp" />
<ClInclude Include="$(MC_ROOT)\source\world\entity\Monster.hpp" />
<ClInclude Include="$(MC_ROOT)\source\world\entity\PathfinderMob.hpp" />
<ClInclude Include="$(MC_ROOT)\source\world\entity\WaterAnimal.hpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View file

@ -422,9 +422,6 @@
<ClCompile Include="$(MC_ROOT)\source\world\tile\WireTile.cpp">
<Filter>Source Files\Tile</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\world\level\path\BinaryHeap.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\world\level\path\Node.cpp">
<Filter>Source Files\Level\Path</Filter>
</ClCompile>
@ -434,6 +431,21 @@
<ClCompile Include="$(MC_ROOT)\source\world\level\path\PathFinder.cpp">
<Filter>Source Files\Level\Path</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\world\level\path\BinaryHeap.cpp">
<Filter>Source Files\Level\Path</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\source\world\entity\PathfinderMob.cpp">
<Filter>Source Files\Entity</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\source\world\entity\Animal.cpp">
<Filter>Source Files\Entity</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\source\world\entity\Monster.cpp">
<Filter>Source Files\Entity</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\source\world\entity\WaterAnimal.cpp">
<Filter>Source Files\Entity</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MC_ROOT)\source\world\entity\Entity.hpp">
@ -715,9 +727,6 @@
<ClInclude Include="$(MC_ROOT)\source\world\tile\WireTile.hpp">
<Filter>Header Files\Tile</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\world\level\path\BinaryHeap.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\world\level\path\Node.hpp">
<Filter>Header Files\Level\Path</Filter>
</ClInclude>
@ -727,5 +736,20 @@
<ClInclude Include="$(MC_ROOT)\source\world\level\path\PathFinder.hpp">
<Filter>Header Files\Level\Path</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\world\level\path\BinaryHeap.hpp">
<Filter>Header Files\Level\Path</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\source\world\entity\PathfinderMob.hpp">
<Filter>Header Files\Entity</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\source\world\entity\WaterAnimal.hpp">
<Filter>Header Files\Entity</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\source\world\entity\Monster.hpp">
<Filter>Header Files\Entity</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\source\world\entity\Animal.hpp">
<Filter>Header Files\Entity</Filter>
</ClInclude>
</ItemGroup>
</Project>

View file

@ -2,9 +2,9 @@ cmake_minimum_required(VERSION 3.16.0)
project(reminecraftpe-core)
if(NOT ANDROID)
set(INCLUDES . .. ../thirdparty/zlib)
set(INCLUDES . .. ../thirdparty/zlib)
else()
set(INCLUDES . ..)
set(INCLUDES . ..)
endif()
# Build
@ -155,10 +155,10 @@ add_library(reminecraftpe-core STATIC
world/level/levelgen/synth/Synth.cpp
world/level/levelgen/synth/ImprovedNoise.cpp
world/level/levelgen/synth/PerlinNoise.cpp
world/level/path/Node.cpp
world/level/path/Path.cpp
world/level/path/BinaryHeap.cpp
world/level/path/PathFinder.cpp
world/level/path/Node.cpp
world/level/path/Path.cpp
world/level/path/BinaryHeap.cpp
world/level/path/PathFinder.cpp
world/phys/HitResult.cpp
world/phys/Vec3.cpp
world/phys/AABB.cpp
@ -173,6 +173,10 @@ add_library(reminecraftpe-core STATIC
world/entity/FallingTile.cpp
world/entity/TripodCamera.cpp
world/entity/ItemEntity.cpp
world/entity/PathfinderMob.cpp
world/entity/Animal.cpp
world/entity/WaterAnimal.cpp
world/entity/Monster.cpp
world/level/Dimension.cpp
world/level/Material.cpp
world/level/LevelListener.cpp
@ -189,9 +193,10 @@ add_library(reminecraftpe-core STATIC
world/level/storage/LevelSource.cpp
world/level/storage/MemoryChunkStorage.cpp
world/level/storage/ExternalFileLevelStorageSource.cpp
world/level/path/Node.cpp
world/level/path/Path.cpp
world/level/path/PathFinder.cpp
world/level/path/Node.cpp
world/level/path/Path.cpp
world/level/path/PathFinder.cpp
world/level/path/BinaryHeap.cpp
world/level/levelgen/feature/BirchFeature.cpp
world/level/levelgen/feature/LargeFeature.cpp
world/level/levelgen/feature/Feature.cpp
@ -279,48 +284,48 @@ target_link_libraries(reminecraftpe-core PUBLIC raknet)
# zlib - Android builds with its own version
# Hack - If we're not building for Android, surely we're building with SDL
if(USE_SDL)
add_subdirectory(../thirdparty/zlib zlib)
target_link_libraries(reminecraftpe-core PUBLIC zlib)
# SDL
add_library(SDL INTERFACE)
if(EMSCRIPTEN)
set(SDL_FLAG -sUSE_SDL=2)
target_compile_options(SDL INTERFACE "${SDL_FLAG}")
target_link_options(SDL INTERFACE "${SDL_FLAG}")
else()
find_package(SDL2 REQUIRED)
target_link_libraries(SDL INTERFACE SDL2::SDL2)
endif()
target_link_libraries(reminecraftpe-core PUBLIC SDL)
# OpenGL
if(NOT EMSCRIPTEN)
option(USE_GLES1_COMPATIBILITY_LAYER "Whether To Enable The GLESv1_CM Compatibility Layer" TRUE)
else()
set(USE_GLES1_COMPATIBILITY_LAYER TRUE)
endif()
if(USE_GLES1_COMPATIBILITY_LAYER)
set(GLES_COMPATIBILITY_LAYER_USE_SDL TRUE CACHE BOOL "" FORCE)
set(GLES_COMPATIBILITY_LAYER_DEPENDENCY SDL CACHE STRING "" FORCE)
add_subdirectory(../thirdparty/gles-compatibility-layer gles-compatibility-layer)
target_link_libraries(reminecraftpe-core PUBLIC gles-compatibility-layer)
target_compile_definitions(reminecraftpe-core PUBLIC USE_GLES1_COMPATIBILITY_LAYER)
if(EMSCRIPTEN)
target_link_options(reminecraftpe-core PUBLIC -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2)
endif()
else()
find_package(OpenGL REQUIRED)
target_link_libraries(reminecraftpe-core PUBLIC OpenGL::OpenGL OpenGL::GLU)
endif()
add_subdirectory(../thirdparty/zlib zlib)
target_link_libraries(reminecraftpe-core PUBLIC zlib)
# SDL
add_library(SDL INTERFACE)
if(EMSCRIPTEN)
set(SDL_FLAG -sUSE_SDL=2)
target_compile_options(SDL INTERFACE "${SDL_FLAG}")
target_link_options(SDL INTERFACE "${SDL_FLAG}")
else()
find_package(SDL2 REQUIRED)
target_link_libraries(SDL INTERFACE SDL2::SDL2)
endif()
target_link_libraries(reminecraftpe-core PUBLIC SDL)
# OpenGL
if(NOT EMSCRIPTEN)
option(USE_GLES1_COMPATIBILITY_LAYER "Whether To Enable The GLESv1_CM Compatibility Layer" TRUE)
else()
set(USE_GLES1_COMPATIBILITY_LAYER TRUE)
endif()
if(USE_GLES1_COMPATIBILITY_LAYER)
set(GLES_COMPATIBILITY_LAYER_USE_SDL TRUE CACHE BOOL "" FORCE)
set(GLES_COMPATIBILITY_LAYER_DEPENDENCY SDL CACHE STRING "" FORCE)
add_subdirectory(../thirdparty/gles-compatibility-layer gles-compatibility-layer)
target_link_libraries(reminecraftpe-core PUBLIC gles-compatibility-layer)
target_compile_definitions(reminecraftpe-core PUBLIC USE_GLES1_COMPATIBILITY_LAYER)
if(EMSCRIPTEN)
target_link_options(reminecraftpe-core PUBLIC -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2)
endif()
else()
find_package(OpenGL REQUIRED)
target_link_libraries(reminecraftpe-core PUBLIC OpenGL::OpenGL OpenGL::GLU)
endif()
elseif(ANDROID)
# Add Android related stuff here.
# Add Android related stuff here.
endif()
# Sound Data
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../sound_data/sounds.h")
if(NOT DEFINED ENV{CI})
message(WARNING "Missing sound data! Did you run tools/grabsounds.py?")
endif()
target_compile_definitions(reminecraftpe-core PRIVATE MISSING_SOUND_DATA)
if(NOT DEFINED ENV{CI})
message(WARNING "Missing sound data! Did you run tools/grabsounds.py?")
endif()
target_compile_definitions(reminecraftpe-core PRIVATE MISSING_SOUND_DATA)
endif()

View file

View file

View file

@ -1,3 +1,4 @@
#include "Mob.hpp"
/********************************************************************
Minecraft: Pocket Edition - Decompilation Project
Copyright (C) 2023 iProgramInCpp
@ -547,7 +548,6 @@ void Mob::travel(float a2, float a3)
if (onLadder())
{
m_distanceFallen = 0.0f;
if (m_vel.y < -0.15f)
@ -873,6 +873,11 @@ std::string Mob::getDeathSound()
return "random.hurt";
}
float Mob::getWalkingSpeedModifier()
{
return 0.7f;
}
void Mob::defineSynchedData()
{

View file

@ -75,6 +75,7 @@ public:
virtual std::string getAmbientSound();
virtual std::string getHurtSound();
virtual std::string getDeathSound();
virtual float getWalkingSpeedModifier();
virtual void defineSynchedData();
float rotlerp(float, float, float);

View file

View file

View file

@ -0,0 +1,252 @@
/********************************************************************
Minecraft: Pocket Edition - Decompilation Project
Copyright (C) 2023 iProgramInCpp
The following code is licensed under the BSD 1 clause license.
SPDX-License-Identifier: BSD-1-Clause
********************************************************************/
#include "PathfinderMob.hpp"
#include "world/level/Level.hpp"
PathfinderMob::PathfinderMob(Level* pLevel) : Mob(pLevel)
{
field_BA0 = false;
field_BA4 = 0;
}
Entity* PathfinderMob::getAttackTarget()
{
return m_pAttackTarget;
}
void PathfinderMob::setAttackTarget(Entity* pEnt)
{
m_pAttackTarget = pEnt;
}
Entity* PathfinderMob::findAttackTarget()
{
return nullptr;
}
bool PathfinderMob::checkHurtTarget(Entity* pEnt, float f)
{
return false;
}
void PathfinderMob::checkCantSeeTarget(Entity* pEnt, float f)
{
if (f > 32.0f)
setAttackTarget(nullptr);
}
float PathfinderMob::getWalkTargetValue(int, int, int)
{
return 0.0f;
}
bool PathfinderMob::shouldHoldGround()
{
return false;
}
void PathfinderMob::findRandomStrollLocation()
{
bool foundLocation = false;
float maxDist = -99999.0f;
int dx = -1, dy = -1, dz = -1;
for (int i = 0; i < 10; i++)
{
int testX = Mth::floor(float(m_pos.x + m_random.nextInt(13)) - 6.0f);
int testY = Mth::floor(float(m_pos.y + m_random.nextInt(7)) - 3.0f);
int testZ = Mth::floor(float(m_pos.z + m_random.nextInt(13)) - 6.0f);
float wtv = getWalkTargetValue(testX, testY, testZ);
if (maxDist < wtv)
{
maxDist = wtv;
dx = testX;
dy = testY;
dz = testZ;
foundLocation = true;
}
}
if (foundLocation)
{
m_pLevel->findPath(&m_path, this, dx, dy, dz, 10.0f);
}
}
float PathfinderMob::getWalkingSpeedModifier()
{
float mod = Mob::getWalkingSpeedModifier();
if (field_BA4 > 0)
mod *= 2.0f;
return mod;
}
bool PathfinderMob::canSpawn()
{
if (!Mob::canSpawn())
return false;
return getWalkTargetValue(Mth::floor(m_pos.x), Mth::floor(m_hitbox.min.y), Mth::floor(m_pos.z)) >= 0.0f;
}
static Vec3 GetNodePosition(Node* pNode, Entity* pEnt)
{
float offset = float(int(pEnt->field_88 + 1.0f)) * 0.5f;
float fx = float(pNode->m_x) + offset;
float fz = float(pNode->m_z) + offset;
float fy = float(pNode->m_y);
return Vec3(fx, fy, fz);
}
void PathfinderMob::updateAi()
{
if (field_BA4 > 0)
field_BA4--;
field_BA0 = shouldHoldGround();
if (m_pAttackTarget)
{
if (!m_pAttackTarget->isAlive())
{
m_pAttackTarget = nullptr;
}
else
{
float dist = m_pAttackTarget->distanceTo(this);
if (canSee(m_pAttackTarget))
checkHurtTarget(m_pAttackTarget, dist);
else
checkCantSeeTarget(m_pAttackTarget, dist);
}
}
else
{
m_pAttackTarget = findAttackTarget();
if (m_pAttackTarget)
m_pLevel->findPath(&m_path, this, m_pAttackTarget, 16.0f);
}
// @TODO: fix gotos
if (!field_BA0)
{
if (m_pAttackTarget)
{
if (m_path.empty() || m_random.nextInt(20) == 0 || m_random.nextInt(20) == 0)
{
m_pLevel->findPath(&m_path, this, m_pAttackTarget, 16.0f);
goto label_1;
}
if (field_BA0)
goto label_1;
}
if ((m_path.empty() && m_random.nextInt(180) == 0) || m_random.nextInt(120) == 0 || (field_BA4 > 0 && (field_BA4 & 7) == 1))
{
if (field_AFC < 100)
findRandomStrollLocation();
}
}
label_1:
m_pitch = 0.0f;
if (m_path.empty() || m_random.nextInt(100) == 0)
{
Mob::updateAi();
return;
}
// follow path
Node* pCurrNode = m_path.getCurrentNode();
Vec3 nodePos = GetNodePosition(pCurrNode, this);
// Skip all nodes that we are inside of.
float sqdbl = (field_88 * 2.0f) * (field_88 * 2.0f);
while (sqdbl > nodePos.distanceToSqr(Vec3(m_pos.x, nodePos.y, m_pos.z)))
{
m_path.advance();
if (m_path.endOfPath())
{
m_path.clear();
pCurrNode = nullptr;
break;
}
nodePos = GetNodePosition(pCurrNode, this);
}
field_B0C = false;
bool inWater = isInWater();
bool inLava = isInLava();
if (!pCurrNode)
{
float ang = Mth::atan2(nodePos.z - m_pos.z, nodePos.x - m_pos.x) * 180.0f / float(M_PI) - 90.0f;
float heightDiff = nodePos.y - Mth::floor(m_hitbox.min.y + 0.5f);
float angDiff = ang - m_yaw;
while (angDiff < -180.0f) angDiff += 360.0f;
while (angDiff >= 180.0f) angDiff -= 360.0f;
if (angDiff > +30.0f) angDiff = +30.0f;
if (angDiff < -30.0f) angDiff = -30.0f;
float oldYaw = m_yaw;
m_yaw += angDiff;
if (field_BA0 && m_pAttackTarget)
{
float ang2 = Mth::atan2(m_pAttackTarget->m_pos.z - m_pos.z, m_pAttackTarget->m_pos.x - m_pos.x) * 180.0f / float(M_PI) - 90.0f;
m_yaw = ang2;
float thing = ((((angDiff + oldYaw) - ang2) + 90.0f) * float(M_PI)) / 180.0f;
// @NOTE: Using old field_B04 value
field_B00 = -field_B04 * Mth::sin(thing);
field_B04 = field_B04 * Mth::cos(thing);
}
field_B04 = field_B14;
if (heightDiff > 0.0f)
field_B0C = true;
}
if (m_pAttackTarget)
lookAt(m_pAttackTarget, 30.0f, 30.0f);
// if we hit a wall while moving
if (field_7D && !isPathFinding())
field_B0C = true;
// if we're in water, try to swim up
if (m_random.nextFloat() < 0.8f && (inWater || inLava))
field_B0C = true;
}
void PathfinderMob::setPath(Path& path)
{
// @TODO: Not sure if it calls the destructor here. In original Minecraft, it doesn't.
m_path = path;
}
bool PathfinderMob::isPathFinding()
{
return !m_path.empty();
}

View file

@ -0,0 +1,39 @@
/********************************************************************
Minecraft: Pocket Edition - Decompilation Project
Copyright (C) 2023 iProgramInCpp
The following code is licensed under the BSD 1 clause license.
SPDX-License-Identifier: BSD-1-Clause
********************************************************************/
#pragma once
#include "Mob.hpp"
#include "world/level/path/Path.hpp"
class PathfinderMob : public Mob
{
public:
PathfinderMob(Level* pLevel);
virtual Entity* getAttackTarget();
virtual void setAttackTarget(Entity*);
virtual Entity* findAttackTarget();
virtual bool checkHurtTarget(Entity*, float);
virtual void checkCantSeeTarget(Entity*, float);
virtual float getWalkTargetValue(int, int, int);
virtual bool shouldHoldGround();
virtual void findRandomStrollLocation();
float getWalkingSpeedModifier() override;
bool canSpawn() override;
void updateAi() override;
void setPath(Path& path);
bool isPathFinding();
private:
Entity* m_pAttackTarget;
bool field_BA0;
int field_BA4;
Path m_path;
};

View file

View file

View file

@ -32,6 +32,31 @@ public:
field_8 = 0;
}
bool empty()
{
return m_numNodes == 0 || m_pNodes == nullptr;
}
Node* getCurrentNode()
{
return m_pNodes[field_8];
}
void advance()
{
field_8++;
}
void rewind()
{
field_8 = 0;
}
bool endOfPath()
{
return field_8 >= m_numNodes;
}
private:
int m_numNodes;
Node** m_pNodes;