2014-03-15 01:45:25 +00:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
|
|
|
#include "HangingEntity.h"
|
2021-10-03 20:29:45 +00:00
|
|
|
#include "BlockInfo.h"
|
2014-03-15 01:45:25 +00:00
|
|
|
#include "Player.h"
|
2021-10-03 20:29:45 +00:00
|
|
|
#include "Chunk.h"
|
2018-08-29 00:51:25 +00:00
|
|
|
#include "../ClientHandle.h"
|
2014-03-15 01:45:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-09-29 12:59:24 +00:00
|
|
|
cHangingEntity::cHangingEntity(eEntityType a_EntityType, eBlockFace a_Facing, Vector3d a_Pos) :
|
2021-04-06 15:09:16 +00:00
|
|
|
Super(a_EntityType, a_Pos, 0.5f, 0.5f),
|
2015-03-13 22:29:27 +00:00
|
|
|
m_Facing(cHangingEntity::BlockFaceToProtocolFace(a_Facing))
|
2014-03-15 01:45:25 +00:00
|
|
|
{
|
|
|
|
SetMaxHealth(1);
|
|
|
|
SetHealth(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-10-03 20:29:45 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-15 01:45:25 +00:00
|
|
|
void cHangingEntity::SpawnOn(cClientHandle & a_ClientHandle)
|
|
|
|
{
|
2015-03-13 22:29:27 +00:00
|
|
|
SetYaw(GetProtocolFacing() * 90);
|
2014-03-15 01:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-10-03 20:29:45 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|