1
0

Horsies: don't always broadcast metadata

This commit is contained in:
Tiger Wang 2020-12-18 20:44:06 +00:00
parent 1c5af8c00d
commit 83e18f6d31

View File

@ -54,12 +54,14 @@ void cHorse::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
return; return;
} }
bool MetadataDirty = false;
auto & Random = GetRandomProvider(); auto & Random = GetRandomProvider();
if (!m_bIsMouthOpen) if (!m_bIsMouthOpen)
{ {
if (Random.RandBool(0.02)) if (Random.RandBool(0.02))
{ {
MetadataDirty = true;
m_bIsMouthOpen = true; m_bIsMouthOpen = true;
} }
} }
@ -67,6 +69,7 @@ void cHorse::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{ {
if (Random.RandBool(0.10)) if (Random.RandBool(0.10))
{ {
MetadataDirty = true;
m_bIsMouthOpen = false; m_bIsMouthOpen = false;
} }
} }
@ -84,12 +87,14 @@ void cHorse::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
m_World->BroadcastSoundEffect("entity.horse.angry", GetPosition(), 1.0f, 1.0f); m_World->BroadcastSoundEffect("entity.horse.angry", GetPosition(), 1.0f, 1.0f);
m_Attachee->Detach(); m_Attachee->Detach();
MetadataDirty = true;
m_bIsRearing = true; m_bIsRearing = true;
} }
} }
else else
{ {
m_World->BroadcastParticleEffect("heart", static_cast<Vector3f>(GetPosition()), Vector3f{}, 0, 5); m_World->BroadcastParticleEffect("heart", static_cast<Vector3f>(GetPosition()), Vector3f{}, 0, 5);
MetadataDirty = true;
m_bIsTame = true; m_bIsTame = true;
} }
} }
@ -98,6 +103,7 @@ void cHorse::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{ {
if (m_RearTickCount == 20) if (m_RearTickCount == 20)
{ {
MetadataDirty = true;
m_bIsRearing = false; m_bIsRearing = false;
m_RearTickCount = 0; m_RearTickCount = 0;
} }
@ -107,7 +113,10 @@ void cHorse::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
} }
} }
m_World->BroadcastEntityMetadata(*this); if (MetadataDirty)
{
m_World->BroadcastEntityMetadata(*this);
}
} }