summaryrefslogtreecommitdiffstats
path: root/src/Entities/HangingEntity.cpp
diff options
context:
space:
mode:
authorEthan Jones <ethan@yasfu.net>2021-10-03 22:29:45 +0200
committerGitHub <noreply@github.com>2021-10-03 22:29:45 +0200
commitafe07fe0900e5e03f439656558a953acf16f35b8 (patch)
tree1946a7980c5799bc4e028e78c6747102e4b92fba /src/Entities/HangingEntity.cpp
parentAuthenticator: avoid move assignments to self (#5315) (diff)
downloadcuberite-afe07fe0900e5e03f439656558a953acf16f35b8.tar
cuberite-afe07fe0900e5e03f439656558a953acf16f35b8.tar.gz
cuberite-afe07fe0900e5e03f439656558a953acf16f35b8.tar.bz2
cuberite-afe07fe0900e5e03f439656558a953acf16f35b8.tar.lz
cuberite-afe07fe0900e5e03f439656558a953acf16f35b8.tar.xz
cuberite-afe07fe0900e5e03f439656558a953acf16f35b8.tar.zst
cuberite-afe07fe0900e5e03f439656558a953acf16f35b8.zip
Diffstat (limited to '')
-rw-r--r--src/Entities/HangingEntity.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/Entities/HangingEntity.cpp b/src/Entities/HangingEntity.cpp
index c20415e36..926c45fa1 100644
--- a/src/Entities/HangingEntity.cpp
+++ b/src/Entities/HangingEntity.cpp
@@ -2,7 +2,9 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "HangingEntity.h"
+#include "BlockInfo.h"
#include "Player.h"
+#include "Chunk.h"
#include "../ClientHandle.h"
@@ -21,6 +23,26 @@ cHangingEntity::cHangingEntity(eEntityType a_EntityType, eBlockFace a_Facing, Ve
+bool cHangingEntity::IsValidSupportBlock(const BLOCKTYPE a_BlockType)
+{
+ return cBlockInfo::IsSolid(a_BlockType) && (a_BlockType != E_BLOCK_REDSTONE_REPEATER_OFF) && (a_BlockType != E_BLOCK_REDSTONE_REPEATER_ON);
+}
+
+
+
+
+
+void cHangingEntity::KilledBy(TakeDamageInfo & a_TDI)
+{
+ Super::KilledBy(a_TDI);
+
+ Destroy();
+}
+
+
+
+
+
void cHangingEntity::SpawnOn(cClientHandle & a_ClientHandle)
{
SetYaw(GetProtocolFacing() * 90);
@@ -29,3 +51,24 @@ void cHangingEntity::SpawnOn(cClientHandle & a_ClientHandle)
+
+void cHangingEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
+{
+ UNUSED(a_Dt);
+
+ // Check for a valid support block once every 64 ticks (3.2 seconds):
+ if ((m_World->GetWorldTickAge() % 64_tick) != 0_tick)
+ {
+ return;
+ }
+
+ BLOCKTYPE Block;
+ const auto SupportPosition = AddFaceDirection(cChunkDef::AbsoluteToRelative(GetPosition()), ProtocolFaceToBlockFace(m_Facing), true);
+ if (!a_Chunk.UnboundedRelGetBlockType(SupportPosition, Block) || IsValidSupportBlock(Block))
+ {
+ return;
+ }
+
+ // Take environmental damage, intending to self-destruct, with "take damage" handling done by child classes:
+ TakeDamage(dtEnvironment, nullptr, static_cast<int>(GetMaxHealth()), 0);
+}