From 7db4e20fd7ee7cf1c25d5c2c5e9e1b1cf97d4c97 Mon Sep 17 00:00:00 2001 From: Debucquoy Anthony tonitch Date: Tue, 26 Sep 2023 23:54:37 +0200 Subject: adding endermite (#5460) * First Draft of adding endermite * Update src/Mobs/Endermite.h Co-authored-by: x12xx12x <44411062+12xx12@users.noreply.github.com> * Adding Protocols + SpawnEgg TODO: don't forget to put the endermite in core plugin for the summon command * Adding endermite to monster.ini * Adding 5% change of spawning endermite when throwing enderpearl * Spawn endermite at last position instead of Hit Position + .cache to .gitignore * fixup! Spawn endermite at last position instead of Hit Position + .cache to .gitignore * destroy endermite if 2 min, not if name is set * Syntax * Adding Enderman targeting endermite + fixing syntax * Fixing compile error + return error [but crash on enderman spawn] * Fix crash but enderman doesn't target * Enderman targeting endermite finished * checking style because i'm a noob at git... * fixup! checking style because i'm a noob at git... * Added endermite egg meta to docs * Final touches Removed unnecesary imports fixed callback to run only in sight distance and actually check sigtlines * Fixed error after not pulling branch --------- Co-authored-by: x12xx12x <44411062+12xx12@users.noreply.github.com> Co-authored-by: Debucquoy --- src/Mobs/AggressiveMonster.cpp | 61 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) (limited to 'src/Mobs/AggressiveMonster.cpp') diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index f7392d92e..c93985b90 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -3,9 +3,9 @@ #include "AggressiveMonster.h" -#include "../World.h" -#include "../Entities/Player.h" -#include "../LineBlockTracer.h" +#include "LineBlockTracer.h" +#include "World.h" +#include "Entities/Player.h" @@ -46,6 +46,61 @@ void cAggressiveMonster::EventSeePlayer(cPlayer * a_Player, cChunk & a_Chunk) +cMonster * cAggressiveMonster::GetMonsterOfTypeInSight(eMonsterType a_MobType, unsigned int a_SightDistance) +{ + + cMonster * FoundTarget = nullptr; + auto MinimumDistance = static_cast(a_SightDistance * a_SightDistance); + + class cCallback : public cBlockTracer::cCallbacks + { + public: + bool OnNextBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, eBlockFace a_EntryFace) override + { + return a_BlockType != E_BLOCK_AIR; + } + }; + + auto Callbacks = cCallback(); + auto Tracer = cLineBlockTracer(*GetWorld(), Callbacks); + + cEntityCallback Callback = [&](cEntity & a_Entity) + { + if (!a_Entity.IsMob()) + { + return false; + } + + auto & Other = dynamic_cast(a_Entity); + if (Other.GetMobType() != a_MobType) + { + return false; + } + + Vector3d MyHeadPosition = GetPosition().addedY(GetHeight()); + Vector3d TargetPosition = Other.GetPosition().addedY(Other.GetHeight()); + double TargetDistance = (MyHeadPosition - TargetPosition).SqrLength(); + + if ( + (MinimumDistance > TargetDistance) && + (TargetDistance < (a_SightDistance * a_SightDistance)) + ) + { + FoundTarget = & Other; + return true; + } + return false; + }; + + cBoundingBox CheckZone(GetPosition().addedXZ(-a_SightDistance, -a_SightDistance), GetPosition().addedXZ(a_SightDistance, a_SightDistance)); + m_World->ForEachEntityInBox(CheckZone, Callback); + return FoundTarget; +} + + + + + void cAggressiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { Super::Tick(a_Dt, a_Chunk); -- cgit v1.2.3