diff options
author | Niels Breuker <niels.breuker@hotmail.nl> | 2023-03-31 14:27:14 +0200 |
---|---|---|
committer | Niels Breuker <niels.breuker@hotmail.nl> | 2023-03-31 14:27:14 +0200 |
commit | c3dfa60882d94bbf5893b5c4e91384ff57a21e8b (patch) | |
tree | 7e9a217cac3425f29f8b2bc4dc664dda8b2bdd73 /src/Generating/PieceGeneratorBFSTree.cpp | |
parent | PieceGenerator: Added functionality to end a structure with a custom prefab. (diff) | |
download | cuberite-PieceGenClosurePieces.tar cuberite-PieceGenClosurePieces.tar.gz cuberite-PieceGenClosurePieces.tar.bz2 cuberite-PieceGenClosurePieces.tar.lz cuberite-PieceGenClosurePieces.tar.xz cuberite-PieceGenClosurePieces.tar.zst cuberite-PieceGenClosurePieces.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Generating/PieceGeneratorBFSTree.cpp | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/src/Generating/PieceGeneratorBFSTree.cpp b/src/Generating/PieceGeneratorBFSTree.cpp index cf6e82ca3..7aaebe75c 100644 --- a/src/Generating/PieceGeneratorBFSTree.cpp +++ b/src/Generating/PieceGeneratorBFSTree.cpp @@ -108,14 +108,33 @@ bool cPieceGeneratorBFSTree::TryPlacePieceAtConnector( // Get a list of available connections: cConnections Connections; int WantedConnectorType = -a_Connector.m_Type; - cPieces AvailablePieces; + cPieces AvailablePieces = m_PiecePool.GetPiecesWithConnector(WantedConnectorType); if (a_OnlyClosurePieces) { - AvailablePieces = m_PiecePool.GetClosurePiecesWithConnector(WantedConnectorType); - } - else - { - AvailablePieces = m_PiecePool.GetPiecesWithConnector(WantedConnectorType); + cPieces closurePieces; + closurePieces.reserve(AvailablePieces.size()); + for (auto & piece : AvailablePieces) + { + auto hitBox = piece->GetHitBox(); + hitBox.Sort(); + auto pieceSize = hitBox.p2 - hitBox.p1; + auto connectors = piece->GetConnectors(); + Vector3i lastCoord = connectors[0].m_Pos; + bool hasMultipleConnectors = false; + for (const auto & connector : connectors) + { + if (connector.m_Pos != lastCoord) + { + hasMultipleConnectors = true; + break; + } + } + if (!hasMultipleConnectors) + { + closurePieces.push_back(piece); + } + } + AvailablePieces = closurePieces; } Connections.reserve(AvailablePieces.size()); Vector3i ConnPos = cPiece::cConnector::AddDirection(a_Connector.m_Pos, a_Connector.m_Direction); // The position at which the new connector should be placed - 1 block away from the current connector @@ -123,14 +142,8 @@ bool cPieceGeneratorBFSTree::TryPlacePieceAtConnector( FindPieceForConnector(AvailablePieces, a_ParentPiece, a_Connector, WantedConnectorType, ConnPos, a_OutPieces, Connections, WeightTotal); if (Connections.empty()) { - // If there are no available connections try to place a closure connector. - AvailablePieces = m_PiecePool.GetClosurePiecesWithConnector(WantedConnectorType); - FindPieceForConnector(AvailablePieces, a_ParentPiece, a_Connector, WantedConnectorType, ConnPos, a_OutPieces, Connections, WeightTotal); - if (Connections.empty()) - { - // No available connections, bail out - return false; - } + // No available connections, bail out + return false; } ASSERT(WeightTotal > 0); |