From c080f819d2af3cc8c71d39c222a249e4df5e6f67 Mon Sep 17 00:00:00 2001 From: 12xx12 <44411062+12xx12@users.noreply.github.com> Date: Sun, 11 Oct 2020 17:27:41 +0200 Subject: Adding Silverfish Spawning Blocks (#4946) * added breaking, spawning, animation * checkstyle * added undocumented API symbols * added changes suggested by @peterbell10 * added natural ore like generation * fixed spawning two silverfishes * fixed clang * fixed clang try 2 * updated comment unified offset * final clang fix * added spawning for more silverfishes if one was damaged * fixed spawning on one hit kill * fixed spawning on one hit kill fixed spawning by potion damage * fixed clang * fixed broken build * fixed broken build * I should read the error message properly fixed build now? * added small changes suggested by @peterbell10 Co-authored-by: 12xx12 <12xx12100@gmail.com> --- src/Mobs/Silverfish.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/Mobs/Silverfish.cpp (limited to 'src/Mobs/Silverfish.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(GetPosX() - 10); X <= static_cast(GetPosX() + 10); X++) + { + for (int Y = static_cast(GetPosY() - 5); Y <= static_cast(GetPosY() + 5); Y++) + { + for (int Z = static_cast(GetPosZ() - 10); Z <= static_cast(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; +} -- cgit v1.2.3