Simplified buckets code slightly

This commit is contained in:
Tiger Wang 2014-07-12 22:50:28 +01:00
parent 084dec6ccf
commit 9f4348fb09

View File

@ -196,54 +196,37 @@ public:
{ {
public: public:
Vector3i m_Pos; Vector3i m_Pos;
bool m_HasHitLastBlock; BLOCKTYPE m_ReplacedBlock;
BLOCKTYPE m_LastBlock;
cCallbacks(void) :
m_HasHitLastBlock(false)
{
}
virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override
{ {
if (a_BlockType != E_BLOCK_AIR) if (a_BlockType != E_BLOCK_AIR)
{ {
bool CanWashAway = cFluidSimulator::CanWashAway(m_LastBlock); m_ReplacedBlock = a_BlockType;
if ( if (!cFluidSimulator::CanWashAway(a_BlockType))
!CanWashAway &&
(m_LastBlock != E_BLOCK_AIR) &&
!IsBlockWater(m_LastBlock) &&
!IsBlockLava(m_LastBlock)
)
{ {
return true; AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, (eBlockFace)a_EntryFace); // Was a unwashawayable block, can't overwrite it!
} }
m_Pos.Set(a_BlockX, a_BlockY, a_BlockZ); // (Block could be washed away, replace it)
m_HasHitLastBlock = true; return true; // Abort tracing
return true; }
}
m_Pos.Set(a_BlockX, a_BlockY, a_BlockZ);
m_LastBlock = a_BlockType;
return false; return false;
} }
} Callbacks; } Callbacks;
cLineBlockTracer Tracer(*a_World, Callbacks); cLineBlockTracer Tracer(*a_World, Callbacks);
Vector3d Start(a_Player->GetEyePosition() + a_Player->GetLookVector()); Vector3d Start(a_Player->GetEyePosition() + a_Player->GetLookVector());
Vector3d End(a_Player->GetEyePosition() + a_Player->GetLookVector() * 5); Vector3d End(a_Player->GetEyePosition() + a_Player->GetLookVector() * 5);
Tracer.Trace(Start.x, Start.y, Start.z, End.x, End.y, End.z); // cTracer::Trace returns true when whole line was traversed. By returning true when we hit something, we ensure that this never happens if liquid could be placed
// Use this to judge whether the position is valid
if (!Callbacks.m_HasHitLastBlock) if (!Tracer.Trace(Start.x, Start.y, Start.z, End.x, End.y, End.z))
{ {
return false; a_BlockPos = Callbacks.m_Pos;
a_BlockType = Callbacks.m_ReplacedBlock;
return true;
} }
a_BlockPos = Callbacks.m_Pos; return false;
a_BlockType = Callbacks.m_LastBlock;
return true;
} }
}; };