21 m_EntityID(a_MovingEntity.GetUniqueID()),
22 m_SourceWorld(*a_MovingEntity.GetWorld()),
23 m_World(a_DestinationWorld),
25 m_BuildPlatform(true),
27 m_PortalLoc(a_DestPosition.Floor()),
28 m_Position(a_DestPosition),
35 for (
int x = MinX; x < MaxX; x++)
37 for (
int z = MinZ; z < MaxZ; z++)
51 class PortalSearchCallback :
public cChunkDataCallback
55 PortalSearchCallback(
const int a_ChunkX,
const int a_ChunkZ,
bool & a_FoundPortal,
Vector3i & a_PortalLoc,
const Vector3d a_Position,
const int a_MaxY) :
72 if (Blocks ==
nullptr)
107 int m_ChunkX, m_ChunkZ;
116 [[maybe_unused]]
const bool Result =
m_World.
GetChunkData({ a_ChunkX, a_ChunkZ }, Callback);
188 std::vector<Vector3i> Possibilities;
199 Possibilities.emplace_back(x, y, z);
205 if (Possibilities.size() > 0)
210 double DistanceToClosest = (Possibilities[0] -
m_Position).SqrLength();
211 Vector3i Closest = Possibilities[0];
212 for (
const auto & itr : Possibilities)
234 int x = a_Location.
x;
235 int y = a_Location.
y;
236 int z = a_Location.
z;
258 if (a_IncludePlatform)
337 auto & DestinationWorld =
m_World;
338 auto DestinationPosition = Position;
344 [EntityID, &DestinationWorld, DestinationPosition](
cWorld & a_World)
348 [&DestinationWorld, &DestinationPosition](
cEntity & a_Entity)
350 FLOGD(
"Placing player at {0}", DestinationPosition);
351 a_Entity.
MoveToWorld(DestinationWorld, DestinationPosition,
true,
false);
unsigned char BLOCKTYPE
The datatype used by blockdata.
std::enable_if< std::is_arithmetic< T >::value, C >::type CeilC(T a_Value)
Ceils a value, then casts it to C (an int by default).
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).
Vector3< double > Vector3d
unsigned char Distance(const BlockState Block)
static bool IsSolid(BLOCKTYPE Block)
Is this block solid (player cannot walk through)?
static constexpr size_t SectionBlockCount
BlockArray * GetSection(size_t a_Y) const
static const size_t NumSections
static Vector3i IndexToCoordinate(size_t index)
void Add(int a_ChunkX, int a_ChunkZ)
Adds a chunk to be locked from unloading.
void Enable(cChunkMap &a_ChunkMap)
Enables the ChunkStay on the specified chunkmap, causing it to load and generate chunks.
bool MoveToWorld(cWorld &a_World, Vector3d a_NewPosition, bool a_ShouldSetPortalCooldown=false, bool a_ShouldSendRespawn=true)
Direction m_Dir
The direction of the portal.
UInt32 m_EntityID
The ID of the entity that's being moved.
int m_MaxY
The maximum Y to scan to.
cWorld & m_SourceWorld
The world we're moving the entity from, used to query the entity ID.
bool IsValidBuildLocation(Vector3i a_BlockPosition)
Whether the given location is a valid location to build a portal.
static const double OutOffset
Where to place the player out from the face and across the face.
static const int SearchSolidBaseWidth
The width of a solid base to search for when building.
virtual void OnChunkAvailable(int a_ChunkX, int a_ChunkY) override
Called when a specific chunk become available.
virtual void OnDisabled(void) override
Called by the ChunkMap when the ChunkStay is disabled.
bool m_BuildPlatform
Whether to build a platform.
Vector3d m_Position
The center of the search area.
static const int PortalHeight
static const int PortalLength
Length and height, including the obsidian.
cWorld & m_World
The world we're moving the entity to.
static const int SearchRadius
static const double AcrossOffset
static const int BuildSearchRadius
void BuildNetherPortal(Vector3i a_Location, Direction a_Direction, bool a_IncludePlatform)
Builds a portal.
cNetherPortalScanner(cEntity &a_MovingEntity, cWorld &a_DestinationWorld, Vector3d a_DestPosition, int a_MaxY)
virtual bool OnAllChunksAvailable(void) override
Called once all of the contained chunks are available.
bool m_FoundPortal
Whether we found a portal during the loading of the chunks.
Vector3i m_PortalLoc
The position of the pre-existing portal.
Vector3< T > addedXZ(T a_AddX, T a_AddZ) const
Returns a copy of this vector moved by the specified amount on the X and Z axes.
Vector3< T > addedX(T a_AddX) const
Returns a copy of this vector moved by the specified amount on the X axis.
BLOCKTYPE GetBlock(Vector3i a_BlockPos) const
Returns the block type at the specified position.
bool GetChunkData(cChunkCoords a_Coords, cChunkDataCallback &a_Callback) const
Calls the callback with the chunk's data, if available (with ChunkCS locked).
bool DoWithEntityByID(UInt32 a_UniqueID, cEntityCallback a_Callback)
Calls the callback if the entity with the specified ID is found, with the entity object as the callba...
void QueueTask(std::function< void(cWorld &)> a_Task)
Queues a task onto the tick thread.
void PlaceBlock(const Vector3i a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta)
Replaces the specified block with another, and calls the OnPlaced block handler.
cChunkMap * GetChunkMap(void)
void SetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Sets the block at the specified coords to the specified value.