diff options
author | 12xx12 <44411062+12xx12@users.noreply.github.com> | 2020-10-11 17:27:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-11 17:27:41 +0200 |
commit | c080f819d2af3cc8c71d39c222a249e4df5e6f67 (patch) | |
tree | 94dc27dacbd040be12348150914d0d7ff1d42d91 /src/Mobs | |
parent | Corrected invalid syntax for return types in APIDoc (#4989) (diff) | |
download | cuberite-c080f819d2af3cc8c71d39c222a249e4df5e6f67.tar cuberite-c080f819d2af3cc8c71d39c222a249e4df5e6f67.tar.gz cuberite-c080f819d2af3cc8c71d39c222a249e4df5e6f67.tar.bz2 cuberite-c080f819d2af3cc8c71d39c222a249e4df5e6f67.tar.lz cuberite-c080f819d2af3cc8c71d39c222a249e4df5e6f67.tar.xz cuberite-c080f819d2af3cc8c71d39c222a249e4df5e6f67.tar.zst cuberite-c080f819d2af3cc8c71d39c222a249e4df5e6f67.zip |
Diffstat (limited to 'src/Mobs')
-rw-r--r-- | src/Mobs/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/Mobs/Silverfish.cpp | 60 | ||||
-rw-r--r-- | src/Mobs/Silverfish.h | 3 |
3 files changed, 63 insertions, 1 deletions
diff --git a/src/Mobs/CMakeLists.txt b/src/Mobs/CMakeLists.txt index 6508e1814..932b90b29 100644 --- a/src/Mobs/CMakeLists.txt +++ b/src/Mobs/CMakeLists.txt @@ -26,6 +26,7 @@ target_sources( Pig.cpp Rabbit.cpp Sheep.cpp + Silverfish.cpp Skeleton.cpp Slime.cpp SnowGolem.cpp diff --git a/src/Mobs/Silverfish.cpp b/src/Mobs/Silverfish.cpp new file mode 100644 index 000000000..9fb570341 --- /dev/null +++ b/src/Mobs/Silverfish.cpp @@ -0,0 +1,60 @@ + +#include "Globals.h" + +#include "Silverfish.h" + +#include "../World.h" +#include "../Chunk.h" +#include "../Blocks/BlockHandler.h" +#include "../Blocks/BlockInfested.h" + +bool cSilverfish::DoTakeDamage(TakeDamageInfo &a_TDI) +{ + bool SuperResult = Super::DoTakeDamage(a_TDI); + // Todo: stop this if /gamerule mobGriefing is set to false + + // If the entity didn't take andy damage + if (!SuperResult) + { + return SuperResult; + } + + // Entity does receive lethal damage or Attacker doesn't exist + if ((m_Health < a_TDI.FinalDamage) || + ((a_TDI.Attacker == nullptr) && (a_TDI.DamageType != dtPoison) && (a_TDI.DamageType != dtPotionOfHarming))) + { + return SuperResult; + } + + // If attacker is player or splash potion + bool ShouldSpawn = ( + (a_TDI.DamageType == dtPoison) || (a_TDI.DamageType == dtPotionOfHarming) || + a_TDI.Attacker->IsPlayer() + ); + + if (!ShouldSpawn) + { + return SuperResult; + } + auto Blocks = sSetBlockVector(); + for (int X = static_cast<int>(GetPosX() - 10); X <= static_cast<int>(GetPosX() + 10); X++) + { + for (int Y = static_cast<int>(GetPosY() - 5); Y <= static_cast<int>(GetPosY() + 5); Y++) + { + for (int Z = static_cast<int>(GetPosZ() - 10); Z <= static_cast<int>(GetPosZ() + 10); Z++) + { + Blocks.emplace_back(sSetBlock({X, Y, Z}, 0, 0)); + } + } + } + m_World->GetBlocks(Blocks, true); + for (const auto & BlockInfo : Blocks) + { + if (BlockInfo.m_BlockType == E_BLOCK_SILVERFISH_EGG) + { + m_World->DigBlock(BlockInfo.GetAbsolutePos(), nullptr); + } + } + + return SuperResult; +} diff --git a/src/Mobs/Silverfish.h b/src/Mobs/Silverfish.h index 435061f72..78137701a 100644 --- a/src/Mobs/Silverfish.h +++ b/src/Mobs/Silverfish.h @@ -18,8 +18,9 @@ public: Super("Silverfish", mtSilverfish, "entity.silverfish.hurt", "entity.silverfish.death", "entity.silverfish.ambient", 0.3, 0.4) { } - CLASS_PROTODEF(cSilverfish) + + virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; } ; |