18 Super(a_World, a_Callbacks),
35 return Tracer.
Trace(a_Start, a_End);
44 static class LineOfSightCallbacks:
45 public cLineBlockTracer::cCallbacks
51 LineOfSightCallbacks(
bool a_IsAirOpaque,
bool a_IsWaterOpaque,
bool a_IsLavaOpaque):
52 m_IsAirOpaque(a_IsAirOpaque),
53 m_IsWaterOpaque(a_IsWaterOpaque),
54 m_IsLavaOpaque(a_IsLavaOpaque)
74 return Trace(a_World, callbacks, a_Start, a_End);
88 class cSolidHitCallbacks:
95 m_HitCoords(a_CBHitCoords),
96 m_HitBlockCoords(a_CBHitBlockCoords),
97 m_HitBlockFace(a_CBHitBlockFace)
109 m_HitBlockCoords = a_BlockPos;
110 m_HitBlockFace = a_EntryFace;
112 double LineCoeff = 0;
129 } callbacks(a_Start, a_End, a_HitCoords, a_HitBlockCoords, a_HitBlockFace);
130 return !
Trace(a_World, callbacks, a_Start, a_End);
153 m_Callbacks->OnNoMoreHits();
157 m_Callbacks->OnIntoWorld(
m_Start);
163 m_Callbacks->OnNoMoreHits();
167 m_Callbacks->OnIntoWorld(
m_Start);
179 return m_World->DoWithChunk(ChunkX, ChunkZ, [
this](
cChunk & a_Chunk) {
return ChunkCallback(&a_Chunk); });
223 static const double EPS = 0.00001;
274 case dirNONE:
return false;
291 ASSERT(a_Chunk !=
nullptr);
297 m_Callbacks->OnNoMoreHits();
304 double IntersectX, IntersectZ;
306 if (m_Callbacks->OnOutOfWorld({IntersectX, double(m_Current.y), IntersectZ}))
311 m_Callbacks->OnNoMoreHits();
317 if (a_Chunk ==
nullptr)
319 m_Callbacks->OnNoChunk();
@ E_BLOCK_STATIONARY_LAVA
@ E_BLOCK_STATIONARY_WATER
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
unsigned char BLOCKTYPE
The datatype used by blockdata.
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
std::enable_if< std::is_arithmetic< T >::value, C >::type FloorC(T a_Value)
Floors a value, then casts it to C (an int by default).
static bool IsSolid(BLOCKTYPE Block)
Is this block solid (player cannot walk through)?
Represents two sets of coords, minimum and maximum for each direction.
bool CalcLineIntersection(Vector3d a_LinePoint1, Vector3d a_LinePoint2, double &a_LineCoeff, eBlockFace &a_Face) const
Returns true if this bounding box is intersected by the line specified by its two points Also calcula...
cChunk * GetNeighborChunk(int a_BlockX, int a_BlockZ)
Returns the chunk into which the specified block belongs, by walking the neighbors.
bool IsValid(void) const
Returns true iff the chunk block data is valid (loaded / generated)
void GetBlockTypeMeta(Vector3i a_RelPos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
static void BlockToChunk(int a_X, int a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords to chunk coords:
void FixStartBelowWorld(void)
Adjusts the start point below the world to just at the world's bottom.
void CalcXZIntersection(double a_Y, double &a_IntersectX, double &a_IntersectZ)
Calculates the XZ coords of an intersection with the specified Yconst plane; assumes that such an int...
Vector3i m_Dir
The increment at which the block coords are going from Start to End; either +1 or -1.
static bool LineOfSightTrace(cWorld &a_World, const Vector3d &a_Start, const Vector3d &a_End, int a_Sight)
Returns true if the two positions are within line of sight (not obscured by blocks).
Vector3d m_Diff
The difference in coords, End - Start.
bool Trace(Vector3d a_Start, Vector3d a_End)
Traces one line between Start and End; returns true if the entire line was traced (until OnNoMoreHits...
bool ChunkCallback(cChunk *a_Chunk)
Vector3d m_End
The end point of the trace.
Vector3d m_Start
The start point of the trace.
bool MoveToNextBlock(void)
Moves m_Current to the next block on the line; returns false if no move is possible (reached the end)
static bool FirstSolidHitTrace(cWorld &a_World, const Vector3d &a_Start, const Vector3d &a_End, Vector3d &a_HitCoords, Vector3i &a_HitBlockCoords, eBlockFace &a_HitBlockFace)
Traces until the first solid block is hit (or until end, whichever comes first.
Vector3i m_Current
The current block.
eBlockFace m_CurrentFace
The face through which the current block has been entered.
void FixStartAboveWorld(void)
Adjusts the start point above the world to just at the world's top.
cLineBlockTracer(cWorld &a_World, cCallbacks &a_Callbacks)
Vector3< int > Floor(void) const
Returns a new Vector3i with coords set to std::floor() of this vector's coords.