Line tracer invalid chunk fix
* Fixes #1230 * Additionally improved speed in some scenarios
This commit is contained in:
parent
e8262373e1
commit
ba24f50e5e
@ -33,17 +33,18 @@ public:
|
||||
/** Called by cWorld::ForEachEntity(), adds the stored entity effect to the entity, if it is close enough. */
|
||||
virtual bool Item(cEntity * a_Entity) override
|
||||
{
|
||||
if (!a_Entity->IsPawn())
|
||||
{
|
||||
// Not an entity that can take effects
|
||||
return false;
|
||||
}
|
||||
|
||||
double SplashDistance = (a_Entity->GetPosition() - m_HitPos).Length();
|
||||
if (SplashDistance >= 20)
|
||||
{
|
||||
// Too far away
|
||||
return false;
|
||||
}
|
||||
if (!a_Entity->IsPawn())
|
||||
{
|
||||
// Not an entity that can take effects
|
||||
return false;
|
||||
}
|
||||
|
||||
// y = -0.25x + 1, where x is the distance from the player. Approximation for potion splash.
|
||||
// TODO: better equation
|
||||
@ -114,7 +115,7 @@ void cSplashPotionEntity::Splash(const Vector3d & a_HitPos)
|
||||
cSplashPotionCallback Callback(a_HitPos, m_EntityEffectType, m_EntityEffect);
|
||||
m_World->ForEachEntity(Callback);
|
||||
|
||||
m_World->BroadcastSoundParticleEffect(2002, (int)a_HitPos.x, (int)a_HitPos.y, (int)a_HitPos.z, m_PotionColor);
|
||||
m_World->BroadcastSoundParticleEffect(2002, (int)floor(a_HitPos.x), (int)floor(a_HitPos.y), (int)floor(a_HitPos.z), m_PotionColor);
|
||||
}
|
||||
|
||||
|
||||
|
@ -212,6 +212,26 @@ bool cLineBlockTracer::Item(cChunk * a_Chunk)
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((m_CurrentY < 0) || (m_CurrentY >= cChunkDef::Height))
|
||||
{
|
||||
// We've gone out of the world, that's the end of this trace
|
||||
double IntersectX, IntersectZ;
|
||||
CalcXZIntersection(m_CurrentY, IntersectX, IntersectZ);
|
||||
if (m_Callbacks->OnOutOfWorld(IntersectX, m_CurrentY, IntersectZ))
|
||||
{
|
||||
// The callback terminated the trace
|
||||
return false;
|
||||
}
|
||||
m_Callbacks->OnNoMoreHits();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Update the current chunk
|
||||
if (a_Chunk != NULL)
|
||||
{
|
||||
a_Chunk = a_Chunk->GetNeighborChunk(m_CurrentX, m_CurrentZ);
|
||||
}
|
||||
|
||||
if (a_Chunk->IsValid())
|
||||
{
|
||||
BLOCKTYPE BlockType;
|
||||
@ -233,26 +253,6 @@ bool cLineBlockTracer::Item(cChunk * a_Chunk)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Update the current chunk
|
||||
if (a_Chunk != NULL)
|
||||
{
|
||||
a_Chunk = a_Chunk->GetNeighborChunk(m_CurrentX, m_CurrentZ);
|
||||
}
|
||||
|
||||
if ((m_CurrentY < 0) || (m_CurrentY >= cChunkDef::Height))
|
||||
{
|
||||
// We've gone out of the world, that's the end of this trace
|
||||
double IntersectX, IntersectZ;
|
||||
CalcXZIntersection(m_CurrentY, IntersectX, IntersectZ);
|
||||
if (m_Callbacks->OnOutOfWorld(IntersectX, m_CurrentY, IntersectZ))
|
||||
{
|
||||
// The callback terminated the trace
|
||||
return false;
|
||||
}
|
||||
m_Callbacks->OnNoMoreHits();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user