From 404ce4f24f05a9550aced342b7a699d54eab92a3 Mon Sep 17 00:00:00 2001 From: Fluffy Loafie <62648027+fluffyloafie@users.noreply.github.com> Date: Tue, 15 Apr 2025 03:45:19 +0200 Subject: [PATCH 01/10] push --- .../player_constructions/NetherPortal.cpp | 125 ------------------ .../player_constructions/NetherPortal.hpp | 67 +++++----- 2 files changed, 35 insertions(+), 157 deletions(-) diff --git a/cubic-server/generation/player_constructions/NetherPortal.cpp b/cubic-server/generation/player_constructions/NetherPortal.cpp index ac17a0872..ae000bd0f 100644 --- a/cubic-server/generation/player_constructions/NetherPortal.cpp +++ b/cubic-server/generation/player_constructions/NetherPortal.cpp @@ -6,128 +6,3 @@ #include "types.hpp" #include -bool NetherPortal::checkLayers(Position pos, int axis) -{ - auto block = _dim->getBlock(pos); - for (int y = 0; y < FRAME_HEIGHT; y++) { - for (int x = 0; x < FRAME_WIDTH; x++) { - if (axis == AXIS_X) { - block = _dim->getBlock({pos.x + x, pos.y + y, pos.z}); - } else if (axis == AXIS_Z) { - block = _dim->getBlock({pos.x, pos.y + y, pos.z + x}); - } else { - return false; - } - if ((y == 0 || y == FRAME_HEIGHT - 1) && (x == 0 || x == FRAME_WIDTH - 1)) { - if (block != Blocks::Obsidian::toProtocol()) { - return false; - } - } else if (x != 0 && x < FRAME_WIDTH - 1 && y == 1) { - if (block == Blocks::Air::toProtocol() || - block == - Blocks::Fire::toProtocol( - Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, - Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE - )) { - continue; - } else { - return false; - } - } else if (x > 1 && x < FRAME_WIDTH - 1 && y != 0 && y < FRAME_HEIGHT - 1) { - if (block != Blocks::Air::toProtocol()) { - return false; - } - } - } - } - return true; -} - -Frame NetherPortal::getFrame(Position pos) -{ - auto nextBlockX = _dim->getBlock({(pos.x + 1), pos.y, pos.z}); - auto nextBlockZ = _dim->getBlock({pos.x, pos.y, (pos.z + 1)}); - auto topNextBlockX = _dim->getBlock({(pos.x + 1), pos.y + 1, pos.z}); - auto topNextBlockZ = _dim->getBlock({pos.x, pos.y + 1, (pos.z + 1)}); - - if (nextBlockX == Blocks::Obsidian::toProtocol() && topNextBlockX == Blocks::Air::toProtocol() && nextBlockZ != Blocks::Obsidian::toProtocol()) { - LDEBUG("Axis X"); - if (checkLayers({pos.x - 1, pos.y, pos.z}, AXIS_X)) - return {AXIS_X, POSITIVE_POS}; - } else if (nextBlockX == Blocks::Obsidian::toProtocol() && topNextBlockX == Blocks::Obsidian::toProtocol() && topNextBlockZ != Blocks::Obsidian::toProtocol()) { - LDEBUG("Axis X"); - if (checkLayers({pos.x - 2, pos.y, pos.z}, AXIS_X)) - return {AXIS_X, NEGATIVE_POS}; - } - if (nextBlockZ == Blocks::Obsidian::toProtocol() && topNextBlockZ == Blocks::Air::toProtocol() && nextBlockX != Blocks::Obsidian::toProtocol()) { - LDEBUG("Axis Z"); - if (checkLayers({pos.x, pos.y, pos.z - 1}, AXIS_Z)) - return {AXIS_Z, POSITIVE_POS}; - } else if (nextBlockZ == Blocks::Obsidian::toProtocol() && topNextBlockZ == Blocks::Obsidian::toProtocol() && topNextBlockX != Blocks::Obsidian::toProtocol()) { - LDEBUG("Axis Z"); - if (checkLayers({pos.x, pos.y, pos.z - 2}, AXIS_Z)) - return {AXIS_Z, NEGATIVE_POS}; - } - LWARN("No frame"); - return {AXIS_UNDEFINED, UNDEFINED_POS}; -} - -void NetherPortal::buildPortal(Position pos) -{ - auto frame = getFrame(pos); - std::vector> blocksArray; - auto block = _dim->getBlock(pos); - for (int y = 0; y < FRAME_HEIGHT - 1; y++) { - for (int x = 0; x < FRAME_WIDTH - 1; x++) { - if (frame.direction == POSITIVE_POS && frame.axis == AXIS_X) { - block = _dim->getBlock({pos.x - 1 + x, pos.y + y, pos.z}); - if (block == Blocks::Air::toProtocol() || - block == - Blocks::Fire::toProtocol( - Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, - Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE - )) { - blocksArray.push_back({{pos.x - 1 + x, pos.y + y, pos.z}, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::X)}); - } - } else if (frame.direction == POSITIVE_POS && frame.axis == AXIS_Z) { - block = _dim->getBlock({pos.x, pos.y + y, pos.z - 1 + x}); - if (block == Blocks::Air::toProtocol() || - block == - Blocks::Fire::toProtocol( - Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, - Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE - )) { - blocksArray.push_back({{pos.x, pos.y + y, pos.z - 1 + x}, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::Z)}); - } - } else if (frame.direction == NEGATIVE_POS && frame.axis == AXIS_X) { - block = _dim->getBlock({pos.x - 2 + x, pos.y + y, pos.z}); - if (block == Blocks::Air::toProtocol() || - block == - Blocks::Fire::toProtocol( - Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, - Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE - )) { - blocksArray.push_back({{pos.x - 2 + x, pos.y + y, pos.z}, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::X)}); - } - } else if (frame.direction == NEGATIVE_POS && frame.axis == AXIS_Z) { - block = _dim->getBlock({pos.x, pos.y + y, pos.z - 2 + x}); - if (block == Blocks::Air::toProtocol() || - block == - Blocks::Fire::toProtocol( - Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, - Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE - )) { - blocksArray.push_back({{pos.x, pos.y + y, pos.z - 2 + x}, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::Z)}); - } - } - } - } - for (auto [position, id] : blocksArray) { - _dim->updateBlock(position, id); - for (auto player : _dim->getPlayers()) { - player->sendBlockUpdate({pos, _dim->getBlock(pos)}); - player->sendBlockUpdate({position, id}); - // player->sendUpdateSectionBlock({position,chunk, true, blocksArray}); - } - } -} diff --git a/cubic-server/generation/player_constructions/NetherPortal.hpp b/cubic-server/generation/player_constructions/NetherPortal.hpp index 11007aedd..c610fb325 100644 --- a/cubic-server/generation/player_constructions/NetherPortal.hpp +++ b/cubic-server/generation/player_constructions/NetherPortal.hpp @@ -1,6 +1,7 @@ #ifndef CUBICSERVER_GENERATION_PLAYER_CONSTRUCTIONS_NETHER_PORTAL_HPP #define CUBICSERVER_GENERATION_PLAYER_CONSTRUCTIONS_NETHER_PORTAL_HPP +#include "math/Vector2.hpp" #include "blocks.hpp" #include "generation/generator.hpp" #include "types.hpp" @@ -8,19 +9,33 @@ #include -#define AXIS_UNDEFINED -1 -#define AXIS_X 0 -#define AXIS_Z 1 -#define UNDEFINED_POS -1 -#define NEGATIVE_POS 0 -#define POSITIVE_POS 1 +/* The minimum & maximum sizes of the portal */ +enum class PortalBoundary { + PORTAL_MIN_WIDTH, + PORTAL_MIN_HEIGHT, + PORTAL_MAX_WIDTH, + PORTAL_MAX_HEIGHT +}; -#define FRAME_WIDTH 4 -#define FRAME_HEIGHT 5 +/* The 2 axes defining the portal */ +enum class PortalAxis { + PORTAL_WIDTH, + PORTAL_HEIGHT +}; -struct Frame { - int axis; - int direction; +/* The horizontal direction of the portal on the X or Z axis */ +enum class PortalDirection { + PORTAL_POS_X, + PORTAL_NEG_X, + PORTAL_POS_Z, + PORTAL_NEG_Z +}; + +/* Error codes */ +enum class PortalError { + PORTAL_SIZE_OVERFLOW = -1, + PORTAL_WRONG_DIRECTION = -2, + PORTAL_WRONG_AXIS = -3 }; /** @@ -46,35 +61,23 @@ class NetherPortal { } /** - * @brief Get the axis on which the frame is built (x or z) - * - * @param pos The position of the frame - * @return Frame The axis and direction of the frame - */ - Frame getFrame(Position pos); - - /** - * @brief Build the portal within the already built frame + * @brief * - * @param pos The position of the frame */ - void buildPortal(Position pos); + Vector2 setSize(Vector2 value); /** - * @brief Checks every layer of the alleged frame + * @brief Sets the direction of the portal * - * @param pos The position of the bottom-left corner of the frame - * @param axis The axis of the frame (x or z) - * @return true There is a frame - * @return false There isn't a frame + * @param value The position of the bottom-left corner of the frame + * @return the value of NetherPortal::dimension (POS_X, NEG_X, POS_Z, NEG_Z) */ - bool checkLayers(Position pos, int axis); + int setDirection(int value); private: - /** - * The dimension where the portal is in - */ - std::shared_ptr _dim; + std::shared_ptr _dim; /**< The dimension where the portal is in */ + Vector2 size; /**< The size of the sides of the portal {WIDTH, HEIGHT} */ + PortalDirection direction; /**< The horizontal direction of the portal */ }; #endif // CUBICSERVER_GENERATION_PLAYER_CONSTRUCTIONS_NETHER_PORTAL_HPP From 181f6aba4c5cf69cfd9902427b3d0be871da1b97 Mon Sep 17 00:00:00 2001 From: Fluffy Loafie <62648027+fluffyloafie@users.noreply.github.com> Date: Tue, 15 Apr 2025 11:50:27 +0200 Subject: [PATCH 02/10] Rework of the Portal - Change the size computation algorithm - Start working on the direction computation --- .../player_constructions/NetherPortal.cpp | 78 +++++++++++++++++++ .../player_constructions/NetherPortal.hpp | 26 +++++-- 2 files changed, 96 insertions(+), 8 deletions(-) diff --git a/cubic-server/generation/player_constructions/NetherPortal.cpp b/cubic-server/generation/player_constructions/NetherPortal.cpp index ae000bd0f..a69131d47 100644 --- a/cubic-server/generation/player_constructions/NetherPortal.cpp +++ b/cubic-server/generation/player_constructions/NetherPortal.cpp @@ -6,3 +6,81 @@ #include "types.hpp" #include +// int getDirection(Position pos) { + +// } + +Vector2 NetherPortal::computeSize(Position pos, PortalDirection direction) { + auto block = _dim->getBlock(pos); // (block{n;0;0} or block{0;0;n}) + int countRight = 1; /**< for the right blocks from block horizontally (set to 1 to take block into account) */ + int countLeft = 1; /**< for the left blocks from block horizontally (set to 1 to take block into account) */ + int totalCountHorizontal = -1; /**< for the total blocks horizontally (set to -1 to address the offset when adding the right & left parts) */ + int totalCountVertical = 1; + Vector2 size = {0, 0}; + + if (direction == PortalDirection::PORTAL_POS_X || direction == PortalDirection::PORTAL_NEG_X) { + while (_dim->getBlock({pos.x + countRight, pos.y, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x + (countRight-1), pos.y, pos.z}) == Blocks::Obsidian::toProtocol()) + countRight++; + while (_dim->getBlock({pos.x - countLeft, pos.y, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x - (countLeft-1), pos.y, pos.z}) == Blocks::Obsidian::toProtocol()) + countLeft++; + while ((_dim->getBlock({pos.x-countLeft-1, pos.y + totalCountVertical, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x-countLeft-1, pos.y + (totalCountVertical-1), pos.z}) == Blocks::Obsidian::toProtocol()) || (_dim->getBlock({pos.x+countRight+1, pos.y + totalCountVertical, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x+countRight+1, pos.y + (totalCountVertical-1), pos.z}) == Blocks::Obsidian::toProtocol())) + totalCountVertical++; + } else if (direction == PortalDirection::PORTAL_POS_Z || direction == PortalDirection::PORTAL_NEG_Z) { + while (_dim->getBlock({pos.x, pos.y, pos.z + countRight}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y, pos.z + (countRight-1)}) == Blocks::Obsidian::toProtocol()) + countRight++; + while (_dim->getBlock({pos.x, pos.y, pos.z - countLeft}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y, pos.z - (countLeft-1)}) == Blocks::Obsidian::toProtocol()) + countLeft++; + while ((_dim->getBlock({pos.x, pos.y + totalCountVertical, pos.z+countRight+1}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y + (totalCountVertical-1), pos.z+countRight+1}) == Blocks::Obsidian::toProtocol()) || (_dim->getBlock({pos.x, pos.y + totalCountVertical, pos.z-countLeft-1}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y + (totalCountVertical-1), pos.z-countLeft-1}) == Blocks::Obsidian::toProtocol())) + totalCountVertical++; + } else + return {PortalError::PORTAL_BAD_PORTAL, PortalError::PORTAL_WRONG_DIRECTION}; + + totalCountHorizontal += countRight + countLeft + PortalBoundary::PORTAL_MIN_WIDTH; + if (totalCountHorizontal > PortalBoundary::PORTAL_MAX_WIDTH) + return {PortalError::PORTAL_BAD_PORTAL, PortalError::PORTAL_SIZE_OVERFLOW}; + + totalCountVertical += PortalBoundary::PORTAL_MIN_HEIGHT; + if (totalCountVertical + PortalBoundary::PORTAL_MIN_HEIGHT > PortalBoundary::PORTAL_MAX_HEIGHT) + return {PortalError::PORTAL_BAD_PORTAL, PortalError::PORTAL_SIZE_OVERFLOW}; + + size = {totalCountHorizontal, totalCountVertical} + + return size; +} + +// int NetherPortal::checkLayers(Position pos, int axis) +// { +// auto block = _dim->getBlock(pos); +// for (int y = 0; y < this->_size.z; y++) { +// for (int x = 0; x < this->_size.x; x++) { +// if (axis == WIDTH) { +// block = _dim->getBlock({pos.x + x, pos.y + y, pos.z}); +// } else if (axis == HEIGHT) { +// block = _dim->getBlock({pos.x, pos.y + y, pos.z + x}); +// } else { +// return WRONG_AXIS; +// } +// if ((y == 0 || y == FRAME_HEIGHT - 1) && (x == 0 || x == FRAME_WIDTH - 1)) { +// if (block != Blocks::Obsidian::toProtocol()) { +// return false; +// } +// } else if (x != 0 && x < FRAME_WIDTH - 1 && y == 1) { +// if (block == Blocks::Air::toProtocol() || +// block == +// Blocks::Fire::toProtocol( +// Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, +// Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE +// )) { +// continue; +// } else { +// return false; +// } +// } else if (x > 1 && x < FRAME_WIDTH - 1 && y != 0 && y < FRAME_HEIGHT - 1) { +// if (block != Blocks::Air::toProtocol()) { +// return false; +// } +// } +// } +// } +// return 1; +// } diff --git a/cubic-server/generation/player_constructions/NetherPortal.hpp b/cubic-server/generation/player_constructions/NetherPortal.hpp index c610fb325..d297ae9da 100644 --- a/cubic-server/generation/player_constructions/NetherPortal.hpp +++ b/cubic-server/generation/player_constructions/NetherPortal.hpp @@ -35,7 +35,8 @@ enum class PortalDirection { enum class PortalError { PORTAL_SIZE_OVERFLOW = -1, PORTAL_WRONG_DIRECTION = -2, - PORTAL_WRONG_AXIS = -3 + PORTAL_WRONG_AXIS = -3, + PORTAL_BAD_PORTAL = -42 }; /** @@ -61,23 +62,32 @@ class NetherPortal { } /** - * @brief + * @brief Computes the two dimentional sizes of the portal (atm, only works when lighting a bottom block) * + * @param pos The position of the ignited block + * @param direction The direction of the alledged portal on the horizontal axis (X or Z) + * @return A Vector2 containing the width & the height of the portal (respectively): {PORTAL_WIDTH, PORTAL_HEIGHT} */ - Vector2 setSize(Vector2 value); + Vector2 computeSize(Position pos, PortalDirection direction); + + /** + * @brief Sets the size of the portal + * + * @param value The computed value of the size of the portal + */ + void setSize(Vector2 size) { _size = size; } /** * @brief Sets the direction of the portal * - * @param value The position of the bottom-left corner of the frame - * @return the value of NetherPortal::dimension (POS_X, NEG_X, POS_Z, NEG_Z) + * @param value The computed value of the direction of the portal */ - int setDirection(int value); + void setDirection(int direction) { _direction = direction; } private: std::shared_ptr _dim; /**< The dimension where the portal is in */ - Vector2 size; /**< The size of the sides of the portal {WIDTH, HEIGHT} */ - PortalDirection direction; /**< The horizontal direction of the portal */ + Vector2 _size; /**< The size of the portal {PORTAL_WIDTH, PORTAL_HEIGHT} */ + PortalDirection _direction; /**< The horizontal direction of the portal (POS_X, NEG_X, POS_Z, NEG_Z) */ }; #endif // CUBICSERVER_GENERATION_PLAYER_CONSTRUCTIONS_NETHER_PORTAL_HPP From 86786923c451932be7477b4be07acc4375d92c95 Mon Sep 17 00:00:00 2001 From: Fluffy Loafie <62648027+fluffyloafie@users.noreply.github.com> Date: Tue, 15 Apr 2025 15:27:47 +0200 Subject: [PATCH 03/10] Add portal direction computation --- .../player_constructions/NetherPortal.cpp | 90 +++++++++---------- .../player_constructions/NetherPortal.hpp | 22 ++++- 2 files changed, 63 insertions(+), 49 deletions(-) diff --git a/cubic-server/generation/player_constructions/NetherPortal.cpp b/cubic-server/generation/player_constructions/NetherPortal.cpp index a69131d47..7ae87a34a 100644 --- a/cubic-server/generation/player_constructions/NetherPortal.cpp +++ b/cubic-server/generation/player_constructions/NetherPortal.cpp @@ -5,13 +5,46 @@ #include "logging/logging.hpp" #include "types.hpp" #include +#include -// int getDirection(Position pos) { +PortalDirection NetherPortal::computeDirection(Position pos) { + int countRightX = 1; + int countLeftX = 1; + int totalCountX = -1; + int countRightZ = 1; + int countLeftZ = 1; + int totalCountZ = -1; -// } + // Count how many aligned obsidian blocks on the X axis + while (_dim->getBlock({pos.x + countRightX, pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x + (countRightX-1), pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN) + countRightX++; + while (_dim->getBlock({pos.x - countLeftX, pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x - (countLeftX-1), pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN) + countLeftX++; + totalCountX += countRightX + countLeftX; + + // Count how many aligned obsidian blocks on the Z axis + while (_dim->getBlock({pos.x, pos.y, pos.z + countRightZ}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x, pos.y, pos.z + (countRightZ-1)}) == PortalBlocks::PORTAL_OBSIDIAN) + countRightZ++; + while (_dim->getBlock({pos.x, pos.y, pos.z - countLeftZ}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x, pos.y, pos.z - (countLeftZ-1)}) == PortalBlocks::PORTAL_OBSIDIAN) + countLeftZ++; + totalCountZ += countRightZ + countLeftZ; + + if (totalCountX > totalCountZ) { + if (countLeftX > countRightX) + return PortalDirection::PORTAL_NEG_X; + else + return PortalDirection::PORTAL_POS_X; + } else { + if (countLeftZ > countRightZ) + return PortalDirection::PORTAL_NEG_Z; + else + return PortalDirection::PORTAL_POS_Z; + } + + return static_cast>(PortalError::PORTAL_BAD_PORTAL); +} Vector2 NetherPortal::computeSize(Position pos, PortalDirection direction) { - auto block = _dim->getBlock(pos); // (block{n;0;0} or block{0;0;n}) int countRight = 1; /**< for the right blocks from block horizontally (set to 1 to take block into account) */ int countLeft = 1; /**< for the left blocks from block horizontally (set to 1 to take block into account) */ int totalCountHorizontal = -1; /**< for the total blocks horizontally (set to -1 to address the offset when adding the right & left parts) */ @@ -19,18 +52,20 @@ Vector2 NetherPortal::computeSize(Position pos, PortalDirection direction) Vector2 size = {0, 0}; if (direction == PortalDirection::PORTAL_POS_X || direction == PortalDirection::PORTAL_NEG_X) { - while (_dim->getBlock({pos.x + countRight, pos.y, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x + (countRight-1), pos.y, pos.z}) == Blocks::Obsidian::toProtocol()) + while (_dim->getBlock({pos.x + countRight, pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x + (countRight-1), pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN) countRight++; - while (_dim->getBlock({pos.x - countLeft, pos.y, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x - (countLeft-1), pos.y, pos.z}) == Blocks::Obsidian::toProtocol()) + while (_dim->getBlock({pos.x - countLeft, pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x - (countLeft-1), pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN) countLeft++; - while ((_dim->getBlock({pos.x-countLeft-1, pos.y + totalCountVertical, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x-countLeft-1, pos.y + (totalCountVertical-1), pos.z}) == Blocks::Obsidian::toProtocol()) || (_dim->getBlock({pos.x+countRight+1, pos.y + totalCountVertical, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x+countRight+1, pos.y + (totalCountVertical-1), pos.z}) == Blocks::Obsidian::toProtocol())) + while ((_dim->getBlock({pos.x-(countLeft-1), pos.y + totalCountVertical, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x-(countLeft-1), pos.y + (totalCountVertical-1), pos.z}) == PortalBlocks::PORTAL_OBSIDIAN) + || (_dim->getBlock({pos.x+(countRight+1), pos.y + totalCountVertical, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x+countRight+1, pos.y + (totalCountVertical-1), pos.z}) == PortalBlocks::PORTAL_OBSIDIAN)) totalCountVertical++; } else if (direction == PortalDirection::PORTAL_POS_Z || direction == PortalDirection::PORTAL_NEG_Z) { - while (_dim->getBlock({pos.x, pos.y, pos.z + countRight}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y, pos.z + (countRight-1)}) == Blocks::Obsidian::toProtocol()) + while (_dim->getBlock({pos.x, pos.y, pos.z + countRight}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x, pos.y, pos.z + (countRight-1)}) == PortalBlocks::PORTAL_OBSIDIAN) countRight++; - while (_dim->getBlock({pos.x, pos.y, pos.z - countLeft}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y, pos.z - (countLeft-1)}) == Blocks::Obsidian::toProtocol()) + while (_dim->getBlock({pos.x, pos.y, pos.z - countLeft}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x, pos.y, pos.z - (countLeft-1)}) == PortalBlocks::PORTAL_OBSIDIAN) countLeft++; - while ((_dim->getBlock({pos.x, pos.y + totalCountVertical, pos.z+countRight+1}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y + (totalCountVertical-1), pos.z+countRight+1}) == Blocks::Obsidian::toProtocol()) || (_dim->getBlock({pos.x, pos.y + totalCountVertical, pos.z-countLeft-1}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y + (totalCountVertical-1), pos.z-countLeft-1}) == Blocks::Obsidian::toProtocol())) + while ((_dim->getBlock({pos.x, pos.y + totalCountVertical, pos.z+(countRight+1)}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x, pos.y + (totalCountVertical-1), pos.z+(countRight+1)}) == PortalBlocks::PORTAL_OBSIDIAN) + || (_dim->getBlock({pos.x, pos.y + totalCountVertical, pos.z-(countLeft-1)}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x, pos.y + (totalCountVertical-1), pos.z-(countLeft-1)}) == PortalBlocks::PORTAL_OBSIDIAN)) totalCountVertical++; } else return {PortalError::PORTAL_BAD_PORTAL, PortalError::PORTAL_WRONG_DIRECTION}; @@ -47,40 +82,3 @@ Vector2 NetherPortal::computeSize(Position pos, PortalDirection direction) return size; } - -// int NetherPortal::checkLayers(Position pos, int axis) -// { -// auto block = _dim->getBlock(pos); -// for (int y = 0; y < this->_size.z; y++) { -// for (int x = 0; x < this->_size.x; x++) { -// if (axis == WIDTH) { -// block = _dim->getBlock({pos.x + x, pos.y + y, pos.z}); -// } else if (axis == HEIGHT) { -// block = _dim->getBlock({pos.x, pos.y + y, pos.z + x}); -// } else { -// return WRONG_AXIS; -// } -// if ((y == 0 || y == FRAME_HEIGHT - 1) && (x == 0 || x == FRAME_WIDTH - 1)) { -// if (block != Blocks::Obsidian::toProtocol()) { -// return false; -// } -// } else if (x != 0 && x < FRAME_WIDTH - 1 && y == 1) { -// if (block == Blocks::Air::toProtocol() || -// block == -// Blocks::Fire::toProtocol( -// Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, -// Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE -// )) { -// continue; -// } else { -// return false; -// } -// } else if (x > 1 && x < FRAME_WIDTH - 1 && y != 0 && y < FRAME_HEIGHT - 1) { -// if (block != Blocks::Air::toProtocol()) { -// return false; -// } -// } -// } -// } -// return 1; -// } diff --git a/cubic-server/generation/player_constructions/NetherPortal.hpp b/cubic-server/generation/player_constructions/NetherPortal.hpp index d297ae9da..dd3f0f893 100644 --- a/cubic-server/generation/player_constructions/NetherPortal.hpp +++ b/cubic-server/generation/player_constructions/NetherPortal.hpp @@ -39,6 +39,14 @@ enum class PortalError { PORTAL_BAD_PORTAL = -42 }; +enum class PortalBlocks { + PORTAL_OBSIDIAN = Blocks::Obsidian::toProtocol(), + PORTAL_NETHER_X = Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::X), + PORTAL_NETHER_Z = Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::Z), + PORTAL_AIR = Blocks::Air::toProtocol(), + PORTAL_FIRE = Blocks::Fire::toProtocol(Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE) +} + /** * @brief A Nether Portal is a player construction that acts as a gateway between the Overworld and the Nether dimensions. It is made of Obsidian and ignited with a Flint&Steel. * The portal is built like this : @@ -61,6 +69,14 @@ class NetherPortal { { } + /** + * @brief Computes the horizontal direction of the portal, meaning if the portal is positionned on the X or Z axis, and whether the coordinates are positives or negatives (POS_X, NEG_X, POS_Z, NEG_Z) (atm, only works when lighting a bottom block) + * + * @param pos The position of the ignited block + * @return A PortalDirection containing the horizontal direction of the portal (POS_X, NEG_X, POS_Z, NEG_Z) + */ + PortalDirection computeDirection(Position pos); + /** * @brief Computes the two dimentional sizes of the portal (atm, only works when lighting a bottom block) * @@ -73,16 +89,16 @@ class NetherPortal { /** * @brief Sets the size of the portal * - * @param value The computed value of the size of the portal + * @param size The computed value of the size of the portal */ void setSize(Vector2 size) { _size = size; } /** * @brief Sets the direction of the portal * - * @param value The computed value of the direction of the portal + * @param direction The computed value of the direction of the portal */ - void setDirection(int direction) { _direction = direction; } + void setDirection(PortalDirection direction) { _direction = direction; } private: std::shared_ptr _dim; /**< The dimension where the portal is in */ From b89229d8d0da9d04724f78f8bc824c1d405e7106 Mon Sep 17 00:00:00 2001 From: Fluffy Loafie <62648027+fluffyloafie@users.noreply.github.com> Date: Tue, 15 Apr 2025 16:15:27 +0200 Subject: [PATCH 04/10] Add portal building (not tested, very high possibility for it not to work properly at all) - Edit error handling values - Add comment on a value for more context --- .../player_constructions/NetherPortal.cpp | 44 ++++++++++++++++- .../player_constructions/NetherPortal.hpp | 49 +++++++++---------- .../items/usable-items/FlintAndSteel.cpp | 2 +- 3 files changed, 68 insertions(+), 27 deletions(-) diff --git a/cubic-server/generation/player_constructions/NetherPortal.cpp b/cubic-server/generation/player_constructions/NetherPortal.cpp index 7ae87a34a..f6b2aa7fd 100644 --- a/cubic-server/generation/player_constructions/NetherPortal.cpp +++ b/cubic-server/generation/player_constructions/NetherPortal.cpp @@ -41,7 +41,7 @@ PortalDirection NetherPortal::computeDirection(Position pos) { return PortalDirection::PORTAL_POS_Z; } - return static_cast>(PortalError::PORTAL_BAD_PORTAL); + return PortalDirection::PORTAL_WRONG_DIRECTION; } Vector2 NetherPortal::computeSize(Position pos, PortalDirection direction) { @@ -82,3 +82,45 @@ Vector2 NetherPortal::computeSize(Position pos, PortalDirection direction) return size; } + +void NetherPortal::buildPortal(Position pos) +{ + std::vector> blocksArray; + PortalDirection direction = NetherPortal::computeDirection(pos); + Vector2 size = NetherPortal::computeSize(pos, direction); + auto block = _dim->getBlock(pos); + + for (int y = 0; y < size.z - 1; y++) { + for (int x = 0; x < size.x - 1; x++) { + if (direction == PortalDirection::PORTAL_POS_X) { + block = _dim->getBlock({pos.x - 1 + x, pos.y + y, pos.z}); + if (block == PortalBlocks::PORTAL_AIR || block == PortalBlocks::PORTAL_FIRE ) { + blocksArray.push_back({{pos.x - 1 + x, pos.y + y, pos.z}, PortalBlocks::PORTAL_NETHER_X}); + } + } else if (PortalDirection::PORTAL_POS_Z) { + block = _dim->getBlock({pos.x, pos.y + y, pos.z - 1 + x}); + if (block == PortalBlocks::PORTAL_AIR || block == PortalBlocks::PORTAL_FIRE ) { + blocksArray.push_back({{pos.x, pos.y + y, pos.z - 1 + x}, PortalBlocks::PORTAL_NETHER_Z}); + } + } else if (PortalDirection::PORTAL_NEG_X) { + block = _dim->getBlock({pos.x - 2 + x, pos.y + y, pos.z}); + if (block == PortalBlocks::PORTAL_AIR || block == PortalBlocks::PORTAL_FIRE ) { + blocksArray.push_back({{pos.x - 2 + x, pos.y + y, pos.z}, PortalBlocks::PORTAL_NETHER_X}); + } + } else if (PortalDirection::PORTAL_NEG_Z) { + block = _dim->getBlock({pos.x, pos.y + y, pos.z - 2 + x}); + if (block == PortalBlocks::PORTAL_AIR || block == PortalBlocks::PORTAL_FIRE ) { + blocksArray.push_back({{pos.x, pos.y + y, pos.z - 2 + x}, PortalBlocks::PORTAL_NETHER_Z}); + } + } + } + } + for (auto [position, id] : blocksArray) { + _dim->updateBlock(position, id); + for (auto player : _dim->getPlayers()) { + player->sendBlockUpdate({pos, _dim->getBlock(pos)}); + player->sendBlockUpdate({position, id}); + // player->sendUpdateSectionBlock({position,chunk, true, blocksArray}); + } + } +} \ No newline at end of file diff --git a/cubic-server/generation/player_constructions/NetherPortal.hpp b/cubic-server/generation/player_constructions/NetherPortal.hpp index dd3f0f893..f0071865a 100644 --- a/cubic-server/generation/player_constructions/NetherPortal.hpp +++ b/cubic-server/generation/player_constructions/NetherPortal.hpp @@ -9,18 +9,29 @@ #include +/* Error codes */ +enum class PortalError { + PORTAL_SIZE_OVERFLOW = -1, + PORTAL_WRONG_DIRECTION = -2, + PORTAL_WRONG_AXIS = -3, + PORTAL_WRONG_BLOCK = -4, + PORTAL_BAD_PORTAL = -42 +}; + /* The minimum & maximum sizes of the portal */ enum class PortalBoundary { - PORTAL_MIN_WIDTH, - PORTAL_MIN_HEIGHT, - PORTAL_MAX_WIDTH, - PORTAL_MAX_HEIGHT + PORTAL_MIN_WIDTH = 4, + PORTAL_MIN_HEIGHT = 5, + PORTAL_MAX_WIDTH = 23, + PORTAL_MAX_HEIGHT = 23, + PORTAL_WRONG_SIZE = static_cast>(PortalError::PORTAL_BAD_PORTAL) }; /* The 2 axes defining the portal */ enum class PortalAxis { PORTAL_WIDTH, - PORTAL_HEIGHT + PORTAL_HEIGHT, + PORTAL_WRONG_AXIS = static_cast>(PortalError::PORTAL_WRONG_AXIS) }; /* The horizontal direction of the portal on the X or Z axis */ @@ -28,23 +39,18 @@ enum class PortalDirection { PORTAL_POS_X, PORTAL_NEG_X, PORTAL_POS_Z, - PORTAL_NEG_Z -}; - -/* Error codes */ -enum class PortalError { - PORTAL_SIZE_OVERFLOW = -1, - PORTAL_WRONG_DIRECTION = -2, - PORTAL_WRONG_AXIS = -3, - PORTAL_BAD_PORTAL = -42 + PORTAL_NEG_Z, + PORTAL_WRONG_DIRECTION = static_cast>(PortalError::PORTAL_WRONG_DIRECTION) }; +/* The blocks involved at some point in the building of the portal */ enum class PortalBlocks { PORTAL_OBSIDIAN = Blocks::Obsidian::toProtocol(), PORTAL_NETHER_X = Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::X), PORTAL_NETHER_Z = Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::Z), PORTAL_AIR = Blocks::Air::toProtocol(), - PORTAL_FIRE = Blocks::Fire::toProtocol(Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE) + PORTAL_FIRE = Blocks::Fire::toProtocol(Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE), + PORTAL_WRONG_BLOCK = static_cast>(PortalError::PORTAL_WRONG_BLOCK) } /** @@ -87,18 +93,11 @@ class NetherPortal { Vector2 computeSize(Position pos, PortalDirection direction); /** - * @brief Sets the size of the portal - * - * @param size The computed value of the size of the portal - */ - void setSize(Vector2 size) { _size = size; } - - /** - * @brief Sets the direction of the portal + * @brief Build the portal within the already built frame * - * @param direction The computed value of the direction of the portal + * @param pos The position of the frame */ - void setDirection(PortalDirection direction) { _direction = direction; } + void buildPortal(Position pos); private: std::shared_ptr _dim; /**< The dimension where the portal is in */ diff --git a/cubic-server/items/usable-items/FlintAndSteel.cpp b/cubic-server/items/usable-items/FlintAndSteel.cpp index 525295dfa..d5380680a 100644 --- a/cubic-server/items/usable-items/FlintAndSteel.cpp +++ b/cubic-server/items/usable-items/FlintAndSteel.cpp @@ -40,5 +40,5 @@ void Items::FlintAndSteel::onUseOn(std::shared_ptr dim, Position &pos )} ); } - portal.buildPortal({pos.x, pos.y - 1, pos.z}); + portal.buildPortal({pos.x, pos.y - 1, pos.z}); /**< Position of the ignited block */ } From 2987de04d3a4ae1d5409962ade0be46406bafadd Mon Sep 17 00:00:00 2001 From: Fluffy Loafie <62648027+fluffyloafie@users.noreply.github.com> Date: Tue, 15 Apr 2025 16:55:39 +0200 Subject: [PATCH 05/10] Edit if branching to switch statements --- .../player_constructions/NetherPortal.cpp | 52 ++++++++++--------- .../player_constructions/NetherPortal.hpp | 1 + 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/cubic-server/generation/player_constructions/NetherPortal.cpp b/cubic-server/generation/player_constructions/NetherPortal.cpp index f6b2aa7fd..ba651825f 100644 --- a/cubic-server/generation/player_constructions/NetherPortal.cpp +++ b/cubic-server/generation/player_constructions/NetherPortal.cpp @@ -52,17 +52,17 @@ Vector2 NetherPortal::computeSize(Position pos, PortalDirection direction) Vector2 size = {0, 0}; if (direction == PortalDirection::PORTAL_POS_X || direction == PortalDirection::PORTAL_NEG_X) { - while (_dim->getBlock({pos.x + countRight, pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x + (countRight-1), pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN) + while (_dim->getBlock({pos.x + countRight, pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x + (countRight-1), pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x + countRight, pos.y + 1, pos.z}) == PortalBlocks::PORTAL_AIR) countRight++; - while (_dim->getBlock({pos.x - countLeft, pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x - (countLeft-1), pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN) + while (_dim->getBlock({pos.x - countLeft, pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x - (countLeft-1), pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x - countLeft, pos.y + 1, pos.z}) == PortalBlocks::PORTAL_AIR) countLeft++; while ((_dim->getBlock({pos.x-(countLeft-1), pos.y + totalCountVertical, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x-(countLeft-1), pos.y + (totalCountVertical-1), pos.z}) == PortalBlocks::PORTAL_OBSIDIAN) || (_dim->getBlock({pos.x+(countRight+1), pos.y + totalCountVertical, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x+countRight+1, pos.y + (totalCountVertical-1), pos.z}) == PortalBlocks::PORTAL_OBSIDIAN)) totalCountVertical++; } else if (direction == PortalDirection::PORTAL_POS_Z || direction == PortalDirection::PORTAL_NEG_Z) { - while (_dim->getBlock({pos.x, pos.y, pos.z + countRight}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x, pos.y, pos.z + (countRight-1)}) == PortalBlocks::PORTAL_OBSIDIAN) + while (_dim->getBlock({pos.x, pos.y, pos.z + countRight}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x, pos.y, pos.z + (countRight-1)}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x, pos.y + 1, pos.z + countRight}) == PortalBlocks::PORTAL_AIR) countRight++; - while (_dim->getBlock({pos.x, pos.y, pos.z - countLeft}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x, pos.y, pos.z - (countLeft-1)}) == PortalBlocks::PORTAL_OBSIDIAN) + while (_dim->getBlock({pos.x, pos.y, pos.z - countLeft}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x, pos.y, pos.z - (countLeft-1)}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x, pos.y + 1, pos.z - countLeft}) == PortalBlocks::PORTAL_AIR) countLeft++; while ((_dim->getBlock({pos.x, pos.y + totalCountVertical, pos.z+(countRight+1)}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x, pos.y + (totalCountVertical-1), pos.z+(countRight+1)}) == PortalBlocks::PORTAL_OBSIDIAN) || (_dim->getBlock({pos.x, pos.y + totalCountVertical, pos.z-(countLeft-1)}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x, pos.y + (totalCountVertical-1), pos.z-(countLeft-1)}) == PortalBlocks::PORTAL_OBSIDIAN)) @@ -92,26 +92,30 @@ void NetherPortal::buildPortal(Position pos) for (int y = 0; y < size.z - 1; y++) { for (int x = 0; x < size.x - 1; x++) { - if (direction == PortalDirection::PORTAL_POS_X) { - block = _dim->getBlock({pos.x - 1 + x, pos.y + y, pos.z}); - if (block == PortalBlocks::PORTAL_AIR || block == PortalBlocks::PORTAL_FIRE ) { - blocksArray.push_back({{pos.x - 1 + x, pos.y + y, pos.z}, PortalBlocks::PORTAL_NETHER_X}); - } - } else if (PortalDirection::PORTAL_POS_Z) { - block = _dim->getBlock({pos.x, pos.y + y, pos.z - 1 + x}); - if (block == PortalBlocks::PORTAL_AIR || block == PortalBlocks::PORTAL_FIRE ) { - blocksArray.push_back({{pos.x, pos.y + y, pos.z - 1 + x}, PortalBlocks::PORTAL_NETHER_Z}); - } - } else if (PortalDirection::PORTAL_NEG_X) { - block = _dim->getBlock({pos.x - 2 + x, pos.y + y, pos.z}); - if (block == PortalBlocks::PORTAL_AIR || block == PortalBlocks::PORTAL_FIRE ) { - blocksArray.push_back({{pos.x - 2 + x, pos.y + y, pos.z}, PortalBlocks::PORTAL_NETHER_X}); - } - } else if (PortalDirection::PORTAL_NEG_Z) { + switch(direction) { + case PortalDirection::PORTAL_POS_X: + block = _dim->getBlock({pos.x - 1 + x, pos.y + y, pos.z}); + if (block == PortalBlocks::PORTAL_AIR || block == PortalBlocks::PORTAL_FIRE ) + blocksArray.push_back({{pos.x - 1 + x, pos.y + y, pos.z}, PortalBlocks::PORTAL_NETHER_X}); + break; + case PortalDirection::PORTAL_NEG_X: + block = _dim->getBlock({pos.x - 2 + x, pos.y + y, pos.z}); + if (block == PortalBlocks::PORTAL_AIR || block == PortalBlocks::PORTAL_FIRE ) + blocksArray.push_back({{pos.x - 2 + x, pos.y + y, pos.z}, PortalBlocks::PORTAL_NETHER_X}); + break; + case PortalDirection::PORTAL_POS_Z: + block = _dim->getBlock({pos.x, pos.y + y, pos.z - 1 + x}); + if (block == PortalBlocks::PORTAL_AIR || block == PortalBlocks::PORTAL_FIRE ) + blocksArray.push_back({{pos.x, pos.y + y, pos.z - 1 + x}, PortalBlocks::PORTAL_NETHER_Z}); + break; + case PortalDirection::PORTAL_NEG_Z: block = _dim->getBlock({pos.x, pos.y + y, pos.z - 2 + x}); - if (block == PortalBlocks::PORTAL_AIR || block == PortalBlocks::PORTAL_FIRE ) { - blocksArray.push_back({{pos.x, pos.y + y, pos.z - 2 + x}, PortalBlocks::PORTAL_NETHER_Z}); - } + if (block == PortalBlocks::PORTAL_AIR || block == PortalBlocks::PORTAL_FIRE ) + blocksArray.push_back({{pos.x, pos.y + y, pos.z - 2 + x}, PortalBlocks::PORTAL_NETHER_Z}); + break; + default: + LDEBUG("Portal error code: PORTAL_NONE ({})", PortalError::PORTAL_NONE); + break; } } } @@ -123,4 +127,4 @@ void NetherPortal::buildPortal(Position pos) // player->sendUpdateSectionBlock({position,chunk, true, blocksArray}); } } -} \ No newline at end of file +} diff --git a/cubic-server/generation/player_constructions/NetherPortal.hpp b/cubic-server/generation/player_constructions/NetherPortal.hpp index f0071865a..87fbf041a 100644 --- a/cubic-server/generation/player_constructions/NetherPortal.hpp +++ b/cubic-server/generation/player_constructions/NetherPortal.hpp @@ -11,6 +11,7 @@ /* Error codes */ enum class PortalError { + PORTAL_NONE = 0, PORTAL_SIZE_OVERFLOW = -1, PORTAL_WRONG_DIRECTION = -2, PORTAL_WRONG_AXIS = -3, From 2ceba75ac5325a75b0a73d02d11f1ddc0cf9c27f Mon Sep 17 00:00:00 2001 From: Fluffy Loafie <62648027+fluffyloafie@users.noreply.github.com> Date: Tue, 15 Apr 2025 18:12:04 +0200 Subject: [PATCH 06/10] Fix errors --- .../player_constructions/NetherPortal.cpp | 43 +++++++++---------- .../player_constructions/NetherPortal.hpp | 19 +++----- 2 files changed, 26 insertions(+), 36 deletions(-) diff --git a/cubic-server/generation/player_constructions/NetherPortal.cpp b/cubic-server/generation/player_constructions/NetherPortal.cpp index ba651825f..6aaefc35c 100644 --- a/cubic-server/generation/player_constructions/NetherPortal.cpp +++ b/cubic-server/generation/player_constructions/NetherPortal.cpp @@ -5,7 +5,6 @@ #include "logging/logging.hpp" #include "types.hpp" #include -#include PortalDirection NetherPortal::computeDirection(Position pos) { int countRightX = 1; @@ -16,16 +15,16 @@ PortalDirection NetherPortal::computeDirection(Position pos) { int totalCountZ = -1; // Count how many aligned obsidian blocks on the X axis - while (_dim->getBlock({pos.x + countRightX, pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x + (countRightX-1), pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN) + while (_dim->getBlock({pos.x + countRightX, pos.y, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x + (countRightX-1), pos.y, pos.z}) == Blocks::Obsidian::toProtocol()) countRightX++; - while (_dim->getBlock({pos.x - countLeftX, pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x - (countLeftX-1), pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN) + while (_dim->getBlock({pos.x - countLeftX, pos.y, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x - (countLeftX-1), pos.y, pos.z}) == Blocks::Obsidian::toProtocol()) countLeftX++; totalCountX += countRightX + countLeftX; // Count how many aligned obsidian blocks on the Z axis - while (_dim->getBlock({pos.x, pos.y, pos.z + countRightZ}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x, pos.y, pos.z + (countRightZ-1)}) == PortalBlocks::PORTAL_OBSIDIAN) + while (_dim->getBlock({pos.x, pos.y, pos.z + countRightZ}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y, pos.z + (countRightZ-1)}) == Blocks::Obsidian::toProtocol()) countRightZ++; - while (_dim->getBlock({pos.x, pos.y, pos.z - countLeftZ}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x, pos.y, pos.z - (countLeftZ-1)}) == PortalBlocks::PORTAL_OBSIDIAN) + while (_dim->getBlock({pos.x, pos.y, pos.z - countLeftZ}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y, pos.z - (countLeftZ-1)}) == Blocks::Obsidian::toProtocol()) countLeftZ++; totalCountZ += countRightZ + countLeftZ; @@ -52,20 +51,20 @@ Vector2 NetherPortal::computeSize(Position pos, PortalDirection direction) Vector2 size = {0, 0}; if (direction == PortalDirection::PORTAL_POS_X || direction == PortalDirection::PORTAL_NEG_X) { - while (_dim->getBlock({pos.x + countRight, pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x + (countRight-1), pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x + countRight, pos.y + 1, pos.z}) == PortalBlocks::PORTAL_AIR) + while (_dim->getBlock({pos.x + countRight, pos.y, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x + (countRight-1), pos.y, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x + countRight, pos.y + 1, pos.z}) == Blocks::Air::toProtocol()) countRight++; - while (_dim->getBlock({pos.x - countLeft, pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x - (countLeft-1), pos.y, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x - countLeft, pos.y + 1, pos.z}) == PortalBlocks::PORTAL_AIR) + while (_dim->getBlock({pos.x - countLeft, pos.y, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x - (countLeft-1), pos.y, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x - countLeft, pos.y + 1, pos.z}) == Blocks::Air::toProtocol()) countLeft++; - while ((_dim->getBlock({pos.x-(countLeft-1), pos.y + totalCountVertical, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x-(countLeft-1), pos.y + (totalCountVertical-1), pos.z}) == PortalBlocks::PORTAL_OBSIDIAN) - || (_dim->getBlock({pos.x+(countRight+1), pos.y + totalCountVertical, pos.z}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x+countRight+1, pos.y + (totalCountVertical-1), pos.z}) == PortalBlocks::PORTAL_OBSIDIAN)) + while ((_dim->getBlock({pos.x-(countLeft-1), pos.y + totalCountVertical, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x-(countLeft-1), pos.y + (totalCountVertical-1), pos.z}) == Blocks::Obsidian::toProtocol()) + || (_dim->getBlock({pos.x+(countRight+1), pos.y + totalCountVertical, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x+countRight+1, pos.y + (totalCountVertical-1), pos.z}) == Blocks::Obsidian::toProtocol())) totalCountVertical++; } else if (direction == PortalDirection::PORTAL_POS_Z || direction == PortalDirection::PORTAL_NEG_Z) { - while (_dim->getBlock({pos.x, pos.y, pos.z + countRight}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x, pos.y, pos.z + (countRight-1)}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x, pos.y + 1, pos.z + countRight}) == PortalBlocks::PORTAL_AIR) + while (_dim->getBlock({pos.x, pos.y, pos.z + countRight}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y, pos.z + (countRight-1)}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y + 1, pos.z + countRight}) == Blocks::Air::toProtocol()) countRight++; - while (_dim->getBlock({pos.x, pos.y, pos.z - countLeft}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x, pos.y, pos.z - (countLeft-1)}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x, pos.y + 1, pos.z - countLeft}) == PortalBlocks::PORTAL_AIR) + while (_dim->getBlock({pos.x, pos.y, pos.z - countLeft}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y, pos.z - (countLeft-1)}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y + 1, pos.z - countLeft}) == Blocks::Air::toProtocol()) countLeft++; - while ((_dim->getBlock({pos.x, pos.y + totalCountVertical, pos.z+(countRight+1)}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x, pos.y + (totalCountVertical-1), pos.z+(countRight+1)}) == PortalBlocks::PORTAL_OBSIDIAN) - || (_dim->getBlock({pos.x, pos.y + totalCountVertical, pos.z-(countLeft-1)}) == PortalBlocks::PORTAL_OBSIDIAN && _dim->getBlock({pos.x, pos.y + (totalCountVertical-1), pos.z-(countLeft-1)}) == PortalBlocks::PORTAL_OBSIDIAN)) + while ((_dim->getBlock({pos.x, pos.y + totalCountVertical, pos.z+(countRight+1)}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y + (totalCountVertical-1), pos.z+(countRight+1)}) == Blocks::Obsidian::toProtocol()) + || (_dim->getBlock({pos.x, pos.y + totalCountVertical, pos.z-(countLeft-1)}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y + (totalCountVertical-1), pos.z-(countLeft-1)}) == Blocks::Obsidian::toProtocol())) totalCountVertical++; } else return {PortalError::PORTAL_BAD_PORTAL, PortalError::PORTAL_WRONG_DIRECTION}; @@ -78,7 +77,7 @@ Vector2 NetherPortal::computeSize(Position pos, PortalDirection direction) if (totalCountVertical + PortalBoundary::PORTAL_MIN_HEIGHT > PortalBoundary::PORTAL_MAX_HEIGHT) return {PortalError::PORTAL_BAD_PORTAL, PortalError::PORTAL_SIZE_OVERFLOW}; - size = {totalCountHorizontal, totalCountVertical} + size = {totalCountHorizontal, totalCountVertical}; return size; } @@ -95,23 +94,23 @@ void NetherPortal::buildPortal(Position pos) switch(direction) { case PortalDirection::PORTAL_POS_X: block = _dim->getBlock({pos.x - 1 + x, pos.y + y, pos.z}); - if (block == PortalBlocks::PORTAL_AIR || block == PortalBlocks::PORTAL_FIRE ) - blocksArray.push_back({{pos.x - 1 + x, pos.y + y, pos.z}, PortalBlocks::PORTAL_NETHER_X}); + if (block == Blocks::Air::toProtocol() || block == Blocks::Fire::toProtocol(Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE)) + blocksArray.push_back({{pos.x - 1 + x, pos.y + y, pos.z}, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::X)}); break; case PortalDirection::PORTAL_NEG_X: block = _dim->getBlock({pos.x - 2 + x, pos.y + y, pos.z}); - if (block == PortalBlocks::PORTAL_AIR || block == PortalBlocks::PORTAL_FIRE ) - blocksArray.push_back({{pos.x - 2 + x, pos.y + y, pos.z}, PortalBlocks::PORTAL_NETHER_X}); + if (block == Blocks::Air::toProtocol() || block == Blocks::Fire::toProtocol(Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE)) + blocksArray.push_back({{pos.x - 2 + x, pos.y + y, pos.z}, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::X)}); break; case PortalDirection::PORTAL_POS_Z: block = _dim->getBlock({pos.x, pos.y + y, pos.z - 1 + x}); - if (block == PortalBlocks::PORTAL_AIR || block == PortalBlocks::PORTAL_FIRE ) - blocksArray.push_back({{pos.x, pos.y + y, pos.z - 1 + x}, PortalBlocks::PORTAL_NETHER_Z}); + if (block == Blocks::Air::toProtocol() || block == Blocks::Fire::toProtocol(Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE)) + blocksArray.push_back({{pos.x, pos.y + y, pos.z - 1 + x}, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::Z)}); break; case PortalDirection::PORTAL_NEG_Z: block = _dim->getBlock({pos.x, pos.y + y, pos.z - 2 + x}); - if (block == PortalBlocks::PORTAL_AIR || block == PortalBlocks::PORTAL_FIRE ) - blocksArray.push_back({{pos.x, pos.y + y, pos.z - 2 + x}, PortalBlocks::PORTAL_NETHER_Z}); + if (block == Blocks::Air::toProtocol() || block == Blocks::Fire::toProtocol(Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE)) + blocksArray.push_back({{pos.x, pos.y + y, pos.z - 2 + x}, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::Z)}); break; default: LDEBUG("Portal error code: PORTAL_NONE ({})", PortalError::PORTAL_NONE); diff --git a/cubic-server/generation/player_constructions/NetherPortal.hpp b/cubic-server/generation/player_constructions/NetherPortal.hpp index 87fbf041a..9b604e483 100644 --- a/cubic-server/generation/player_constructions/NetherPortal.hpp +++ b/cubic-server/generation/player_constructions/NetherPortal.hpp @@ -1,13 +1,14 @@ #ifndef CUBICSERVER_GENERATION_PLAYER_CONSTRUCTIONS_NETHER_PORTAL_HPP #define CUBICSERVER_GENERATION_PLAYER_CONSTRUCTIONS_NETHER_PORTAL_HPP -#include "math/Vector2.hpp" +#include "Vector2.hpp" #include "blocks.hpp" #include "generation/generator.hpp" #include "types.hpp" #include "world_storage/ChunkColumn.hpp" #include +#include /* Error codes */ enum class PortalError { @@ -25,14 +26,14 @@ enum class PortalBoundary { PORTAL_MIN_HEIGHT = 5, PORTAL_MAX_WIDTH = 23, PORTAL_MAX_HEIGHT = 23, - PORTAL_WRONG_SIZE = static_cast>(PortalError::PORTAL_BAD_PORTAL) + PORTAL_WRONG_SIZE = static_cast(PortalError::PORTAL_BAD_PORTAL) }; /* The 2 axes defining the portal */ enum class PortalAxis { PORTAL_WIDTH, PORTAL_HEIGHT, - PORTAL_WRONG_AXIS = static_cast>(PortalError::PORTAL_WRONG_AXIS) + PORTAL_WRONG_AXIS = static_cast(PortalError::PORTAL_WRONG_AXIS) }; /* The horizontal direction of the portal on the X or Z axis */ @@ -41,19 +42,9 @@ enum class PortalDirection { PORTAL_NEG_X, PORTAL_POS_Z, PORTAL_NEG_Z, - PORTAL_WRONG_DIRECTION = static_cast>(PortalError::PORTAL_WRONG_DIRECTION) + PORTAL_WRONG_DIRECTION = static_cast(PortalError::PORTAL_WRONG_DIRECTION) }; -/* The blocks involved at some point in the building of the portal */ -enum class PortalBlocks { - PORTAL_OBSIDIAN = Blocks::Obsidian::toProtocol(), - PORTAL_NETHER_X = Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::X), - PORTAL_NETHER_Z = Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::Z), - PORTAL_AIR = Blocks::Air::toProtocol(), - PORTAL_FIRE = Blocks::Fire::toProtocol(Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE), - PORTAL_WRONG_BLOCK = static_cast>(PortalError::PORTAL_WRONG_BLOCK) -} - /** * @brief A Nether Portal is a player construction that acts as a gateway between the Overworld and the Nether dimensions. It is made of Obsidian and ignited with a Flint&Steel. * The portal is built like this : From 277c821b89f852fe693935bbe14f2f6454727a4f Mon Sep 17 00:00:00 2001 From: Fluffy Loafie <62648027+fluffyloafie@users.noreply.github.com> Date: Wed, 16 Apr 2025 18:03:34 +0200 Subject: [PATCH 07/10] Add portal ignition side recognition --- .../player_constructions/NetherPortal.cpp | 173 ++++++++++++------ .../player_constructions/NetherPortal.hpp | 64 +++++-- .../items/usable-items/FlintAndSteel.cpp | 4 +- 3 files changed, 170 insertions(+), 71 deletions(-) diff --git a/cubic-server/generation/player_constructions/NetherPortal.cpp b/cubic-server/generation/player_constructions/NetherPortal.cpp index 6aaefc35c..e4d868e9b 100644 --- a/cubic-server/generation/player_constructions/NetherPortal.cpp +++ b/cubic-server/generation/player_constructions/NetherPortal.cpp @@ -6,7 +6,74 @@ #include "types.hpp" #include -PortalDirection NetherPortal::computeDirection(Position pos) { +void NetherPortal::setIgnitedBlock() { + std::vector> blocksArray; + + // blockArray[0] & blockArray[1] - {-1;0;0}, {1;0;0} - LEFT or RIGHT + for (int x = -1; x <= 1; x++) { + if (x != 0) + continue; + auto lateralBlock = {_pos.x + x, _pos.y, _pos.z}; + blocksArray.push_back({lateralBlock, _dim->getBlock(lateralBlock)}); + } + // blockArray[2] & blockArray[3] - {0;-1;0}, {0;1;0} - TOP or BOTTOM + for (int y = -1; y <= 1; y++) { + if (y != 0) + continue; + auto lateralBlock = {_pos.x, _pos.y + y, _pos.z}; + blocksArray.push_back({lateralBlock, _dim->getBlock(lateralBlock)}); + } + // blockArray[4] & blockArray[5] - {0;0;-1}, {0;0;1} - LEFT or RIGHT + for (int z = -1; z <= 1; z++) { + if (z != 0) + continue; + auto lateralBlock = {_pos.x, _pos.y, _pos.z + z}; + blocksArray.push_back({lateralBlock, _dim->getBlock(lateralBlock)}); + } + + if (blocksArray[4].second == Blocks::Obsidian::toProtocol() && blocksArray[5].second != Blocks::Obsidian::toProtocol()) { + if ((blocksArray[0].second == Blocks::Obsidian::toProtocol() && blocksArray[1].second != Blocks::Obsidian::toProtocol()) || (blocksArray[2].second == Blocks::Obsidian::toProtocol() && blocksArray[3].second != Blocks::Obsidian::toProtocol())) { + _ignitedBlock = PortalIgnition::PORTAL_TOP_LEFT_CORNER; + return; + } else if ((blocksArray[1].second == Blocks::Obsidian::toProtocol() && blocksArray[0].second != Blocks::Obsidian::toProtocol()) || (blocksArray[3].second == Blocks::Obsidian::toProtocol() && blocksArray[2].second != Blocks::Obsidian::toProtocol())) { + _ignitedBlock = PortalIgnition::PORTAL_TOP_RIGHT_CORNER; + return; + } else { + _ignitedBlock = PortalIgnition::PORTAL_TOP_CENTER; + return; + } + } else if (blocksArray[4].second != Blocks::Obsidian::toProtocol() && blocksArray[5].second == Blocks::Obsidian::toProtocol()) { + if ((blocksArray[0].second == Blocks::Obsidian::toProtocol() && blocksArray[1].second != Blocks::Obsidian::toProtocol()) || (blocksArray[2].second == Blocks::Obsidian::toProtocol() && blocksArray[3].second != Blocks::Obsidian::toProtocol())) { + _ignitedBlock = PortalIgnition::PORTAL_BOTTOM_LEFT_CORNER; + return; + } else if ((blocksArray[1].second == Blocks::Obsidian::toProtocol() && blocksArray[0].second != Blocks::Obsidian::toProtocol()) || (blocksArray[3].second == Blocks::Obsidian::toProtocol() && blocksArray[2].second != Blocks::Obsidian::toProtocol())) { + _ignitedBlock = PortalIgnition::PORTAL_BOTTOM_RIGHT_CORNER; + return; + } else { + _ignitedBlock = PortalIgnition::PORTAL_BOTTOM_CENTER; + return; + } + } else { + if ((blocksArray[0].second == Blocks::Obsidian::toProtocol() && blocksArray[1].second != Blocks::Obsidian::toProtocol()) || (blocksArray[2].second == Blocks::Obsidian::toProtocol() && blocksArray[3].second != Blocks::Obsidian::toProtocol())) { + _ignitedBlock = PortalIgnition::PORTAL_LEFT_CENTER; + return; + } else if ((blocksArray[1].second == Blocks::Obsidian::toProtocol() && blocksArray[0].second != Blocks::Obsidian::toProtocol()) || (blocksArray[3].second == Blocks::Obsidian::toProtocol() && blocksArray[2].second != Blocks::Obsidian::toProtocol())) { + _ignitedBlock = PortalIgnition::PORTAL_RIGHT_CENTER; + return; + } else { + _ignitedBlock = PortalIgnition::PORTAL_NONE; + return; + } + } + + _ignitedBlock = PortalIgnition::PORTAL_NONE; +} + +void NetherPortal::setBottomLeftCorner() { + _bottomLeftCorner = _pos; +} + +void NetherPortal::setDirection() { int countRightX = 1; int countLeftX = 1; int totalCountX = -1; @@ -15,102 +82,106 @@ PortalDirection NetherPortal::computeDirection(Position pos) { int totalCountZ = -1; // Count how many aligned obsidian blocks on the X axis - while (_dim->getBlock({pos.x + countRightX, pos.y, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x + (countRightX-1), pos.y, pos.z}) == Blocks::Obsidian::toProtocol()) + while (_dim->getBlock({_pos.x + countRightX, _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x + (countRightX-1), _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol()) countRightX++; - while (_dim->getBlock({pos.x - countLeftX, pos.y, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x - (countLeftX-1), pos.y, pos.z}) == Blocks::Obsidian::toProtocol()) + while (_dim->getBlock({_pos.x - countLeftX, _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x - (countLeftX-1), _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol()) countLeftX++; totalCountX += countRightX + countLeftX; // Count how many aligned obsidian blocks on the Z axis - while (_dim->getBlock({pos.x, pos.y, pos.z + countRightZ}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y, pos.z + (countRightZ-1)}) == Blocks::Obsidian::toProtocol()) + while (_dim->getBlock({_pos.x, _pos.y, _pos.z + countRightZ}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x, _pos.y, _pos.z + (countRightZ-1)}) == Blocks::Obsidian::toProtocol()) countRightZ++; - while (_dim->getBlock({pos.x, pos.y, pos.z - countLeftZ}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y, pos.z - (countLeftZ-1)}) == Blocks::Obsidian::toProtocol()) + while (_dim->getBlock({_pos.x, _pos.y, _pos.z - countLeftZ}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x, _pos.y, _pos.z - (countLeftZ-1)}) == Blocks::Obsidian::toProtocol()) countLeftZ++; totalCountZ += countRightZ + countLeftZ; if (totalCountX > totalCountZ) { - if (countLeftX > countRightX) - return PortalDirection::PORTAL_NEG_X; - else - return PortalDirection::PORTAL_POS_X; + if (countLeftX > countRightX) { + _direction = PortalDirection::PORTAL_NEG_X; + return; + } else { + _direction = PortalDirection::PORTAL_POS_X; + return; + } } else { - if (countLeftZ > countRightZ) - return PortalDirection::PORTAL_NEG_Z; - else - return PortalDirection::PORTAL_POS_Z; + if (countLeftZ > countRightZ) { + _direction = PortalDirection::PORTAL_NEG_Z; + return; + } else { + _direction = PortalDirection::PORTAL_POS_Z; + return; + } } - return PortalDirection::PORTAL_WRONG_DIRECTION; + _direction = PortalDirection::PORTAL_WRONG_DIRECTION; } -Vector2 NetherPortal::computeSize(Position pos, PortalDirection direction) { +void NetherPortal::setSize() { int countRight = 1; /**< for the right blocks from block horizontally (set to 1 to take block into account) */ int countLeft = 1; /**< for the left blocks from block horizontally (set to 1 to take block into account) */ int totalCountHorizontal = -1; /**< for the total blocks horizontally (set to -1 to address the offset when adding the right & left parts) */ int totalCountVertical = 1; - Vector2 size = {0, 0}; - if (direction == PortalDirection::PORTAL_POS_X || direction == PortalDirection::PORTAL_NEG_X) { - while (_dim->getBlock({pos.x + countRight, pos.y, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x + (countRight-1), pos.y, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x + countRight, pos.y + 1, pos.z}) == Blocks::Air::toProtocol()) + if (_direction == PortalDirection::PORTAL_POS_X || _direction == PortalDirection::PORTAL_NEG_X) { + while (_dim->getBlock({_pos.x + countRight, _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x + (countRight-1), _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x + countRight, _pos.y + 1, _pos.z}) == Blocks::Air::toProtocol()) countRight++; - while (_dim->getBlock({pos.x - countLeft, pos.y, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x - (countLeft-1), pos.y, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x - countLeft, pos.y + 1, pos.z}) == Blocks::Air::toProtocol()) + while (_dim->getBlock({_pos.x - countLeft, _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x - (countLeft-1), _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x - countLeft, _pos.y + 1, _pos.z}) == Blocks::Air::toProtocol()) countLeft++; - while ((_dim->getBlock({pos.x-(countLeft-1), pos.y + totalCountVertical, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x-(countLeft-1), pos.y + (totalCountVertical-1), pos.z}) == Blocks::Obsidian::toProtocol()) - || (_dim->getBlock({pos.x+(countRight+1), pos.y + totalCountVertical, pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x+countRight+1, pos.y + (totalCountVertical-1), pos.z}) == Blocks::Obsidian::toProtocol())) + while ((_dim->getBlock({_pos.x-(countLeft-1), _pos.y + totalCountVertical, _pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x-(countLeft-1), _pos.y + (totalCountVertical-1), _pos.z}) == Blocks::Obsidian::toProtocol()) + || (_dim->getBlock({_pos.x+(countRight+1), _pos.y + totalCountVertical, _pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x+countRight+1, _pos.y + (totalCountVertical-1), _pos.z}) == Blocks::Obsidian::toProtocol())) totalCountVertical++; - } else if (direction == PortalDirection::PORTAL_POS_Z || direction == PortalDirection::PORTAL_NEG_Z) { - while (_dim->getBlock({pos.x, pos.y, pos.z + countRight}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y, pos.z + (countRight-1)}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y + 1, pos.z + countRight}) == Blocks::Air::toProtocol()) + } else if (_direction == PortalDirection::PORTAL_POS_Z || _direction == PortalDirection::PORTAL_NEG_Z) { + while (_dim->getBlock({_pos.x, _pos.y, _pos.z + countRight}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x, _pos.y, _pos.z + (countRight-1)}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x, _pos.y + 1, _pos.z + countRight}) == Blocks::Air::toProtocol()) countRight++; - while (_dim->getBlock({pos.x, pos.y, pos.z - countLeft}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y, pos.z - (countLeft-1)}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y + 1, pos.z - countLeft}) == Blocks::Air::toProtocol()) + while (_dim->getBlock({_pos.x, _pos.y, _pos.z - countLeft}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x, _pos.y, _pos.z - (countLeft-1)}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x, _pos.y + 1, _pos.z - countLeft}) == Blocks::Air::toProtocol()) countLeft++; - while ((_dim->getBlock({pos.x, pos.y + totalCountVertical, pos.z+(countRight+1)}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y + (totalCountVertical-1), pos.z+(countRight+1)}) == Blocks::Obsidian::toProtocol()) - || (_dim->getBlock({pos.x, pos.y + totalCountVertical, pos.z-(countLeft-1)}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({pos.x, pos.y + (totalCountVertical-1), pos.z-(countLeft-1)}) == Blocks::Obsidian::toProtocol())) + while ((_dim->getBlock({_pos.x, _pos.y + totalCountVertical, _pos.z+(countRight+1)}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x, _pos.y + (totalCountVertical-1), _pos.z+(countRight+1)}) == Blocks::Obsidian::toProtocol()) + || (_dim->getBlock({_pos.x, _pos.y + totalCountVertical, _pos.z-(countLeft-1)}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x, _pos.y + (totalCountVertical-1), _pos.z-(countLeft-1)}) == Blocks::Obsidian::toProtocol())) totalCountVertical++; } else - return {PortalError::PORTAL_BAD_PORTAL, PortalError::PORTAL_WRONG_DIRECTION}; + _size = {PortalError::PORTAL_BAD_PORTAL, PortalError::PORTAL_WRONG_DIRECTION}; totalCountHorizontal += countRight + countLeft + PortalBoundary::PORTAL_MIN_WIDTH; - if (totalCountHorizontal > PortalBoundary::PORTAL_MAX_WIDTH) - return {PortalError::PORTAL_BAD_PORTAL, PortalError::PORTAL_SIZE_OVERFLOW}; + if (totalCountHorizontal > PortalBoundary::PORTAL_MAX_WIDTH) { + _size = {PortalError::PORTAL_BAD_PORTAL, PortalError::PORTAL_SIZE_OVERFLOW}; + return; + } totalCountVertical += PortalBoundary::PORTAL_MIN_HEIGHT; - if (totalCountVertical + PortalBoundary::PORTAL_MIN_HEIGHT > PortalBoundary::PORTAL_MAX_HEIGHT) - return {PortalError::PORTAL_BAD_PORTAL, PortalError::PORTAL_SIZE_OVERFLOW}; - - size = {totalCountHorizontal, totalCountVertical}; + if (totalCountVertical + PortalBoundary::PORTAL_MIN_HEIGHT > PortalBoundary::PORTAL_MAX_HEIGHT) { + _size = {PortalError::PORTAL_BAD_PORTAL, PortalError::PORTAL_SIZE_OVERFLOW}; + return; + } - return size; + _size = {totalCountHorizontal, totalCountVertical}; } -void NetherPortal::buildPortal(Position pos) -{ +void NetherPortal::openPortal() { std::vector> blocksArray; - PortalDirection direction = NetherPortal::computeDirection(pos); - Vector2 size = NetherPortal::computeSize(pos, direction); - auto block = _dim->getBlock(pos); + auto block = _dim->getBlock(_pos); - for (int y = 0; y < size.z - 1; y++) { - for (int x = 0; x < size.x - 1; x++) { - switch(direction) { + for (int y = 0; y < _size.z - 1; y++) { + for (int x = 0; x < _size.x - 1; x++) { + switch (_direction) { case PortalDirection::PORTAL_POS_X: - block = _dim->getBlock({pos.x - 1 + x, pos.y + y, pos.z}); + block = _dim->getBlock({_pos.x - 1 + x, _pos.y + y, _pos.z}); if (block == Blocks::Air::toProtocol() || block == Blocks::Fire::toProtocol(Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE)) - blocksArray.push_back({{pos.x - 1 + x, pos.y + y, pos.z}, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::X)}); + blocksArray.push_back({{_pos.x - 1 + x, _pos.y + y, _pos.z}, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::X)}); break; case PortalDirection::PORTAL_NEG_X: - block = _dim->getBlock({pos.x - 2 + x, pos.y + y, pos.z}); + block = _dim->getBlock({_pos.x - 2 + x, _pos.y + y, _pos.z}); if (block == Blocks::Air::toProtocol() || block == Blocks::Fire::toProtocol(Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE)) - blocksArray.push_back({{pos.x - 2 + x, pos.y + y, pos.z}, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::X)}); + blocksArray.push_back({{_pos.x - 2 + x, _pos.y + y, _pos.z}, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::X)}); break; case PortalDirection::PORTAL_POS_Z: - block = _dim->getBlock({pos.x, pos.y + y, pos.z - 1 + x}); + block = _dim->getBlock({_pos.x, _pos.y + y, _pos.z - 1 + x}); if (block == Blocks::Air::toProtocol() || block == Blocks::Fire::toProtocol(Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE)) - blocksArray.push_back({{pos.x, pos.y + y, pos.z - 1 + x}, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::Z)}); + blocksArray.push_back({{_pos.x, _pos.y + y, _pos.z - 1 + x}, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::Z)}); break; case PortalDirection::PORTAL_NEG_Z: - block = _dim->getBlock({pos.x, pos.y + y, pos.z - 2 + x}); + block = _dim->getBlock({_pos.x, _pos.y + y, _pos.z - 2 + x}); if (block == Blocks::Air::toProtocol() || block == Blocks::Fire::toProtocol(Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE)) - blocksArray.push_back({{pos.x, pos.y + y, pos.z - 2 + x}, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::Z)}); + blocksArray.push_back({{_pos.x, _pos.y + y, _pos.z - 2 + x}, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::Z)}); break; default: LDEBUG("Portal error code: PORTAL_NONE ({})", PortalError::PORTAL_NONE); @@ -121,7 +192,7 @@ void NetherPortal::buildPortal(Position pos) for (auto [position, id] : blocksArray) { _dim->updateBlock(position, id); for (auto player : _dim->getPlayers()) { - player->sendBlockUpdate({pos, _dim->getBlock(pos)}); + player->sendBlockUpdate({_pos, _dim->getBlock(_pos)}); player->sendBlockUpdate({position, id}); // player->sendUpdateSectionBlock({position,chunk, true, blocksArray}); } diff --git a/cubic-server/generation/player_constructions/NetherPortal.hpp b/cubic-server/generation/player_constructions/NetherPortal.hpp index 9b604e483..f636a761b 100644 --- a/cubic-server/generation/player_constructions/NetherPortal.hpp +++ b/cubic-server/generation/player_constructions/NetherPortal.hpp @@ -1,7 +1,7 @@ #ifndef CUBICSERVER_GENERATION_PLAYER_CONSTRUCTIONS_NETHER_PORTAL_HPP #define CUBICSERVER_GENERATION_PLAYER_CONSTRUCTIONS_NETHER_PORTAL_HPP -#include "Vector2.hpp" +#include "math/Vector2.hpp" #include "blocks.hpp" #include "generation/generator.hpp" #include "types.hpp" @@ -12,12 +12,12 @@ /* Error codes */ enum class PortalError { - PORTAL_NONE = 0, PORTAL_SIZE_OVERFLOW = -1, PORTAL_WRONG_DIRECTION = -2, PORTAL_WRONG_AXIS = -3, PORTAL_WRONG_BLOCK = -4, - PORTAL_BAD_PORTAL = -42 + PORTAL_BAD_PORTAL = -42, + PORTAL_NONE = -84 }; /* The minimum & maximum sizes of the portal */ @@ -45,6 +45,19 @@ enum class PortalDirection { PORTAL_WRONG_DIRECTION = static_cast(PortalError::PORTAL_WRONG_DIRECTION) }; +/* The location of ignition of the portal (see schema on PR) */ +enum class PortalIgnition { + PORTAL_TOP_CENTER, + PORTAL_LEFT_CENTER, + PORTAL_RIGHT_CENTER, + PORTAL_BOTTOM_CENTER, + PORTAL_TOP_RIGHT_CORNER, + PORTAL_TOP_LEFT_CORNER, + PORTAL_BOTTOM_RIGHT_CORNER, + PORTAL_BOTTOM_LEFT_CORNER, + PORTAL_NONE = static_cast(PortalError::PORTAL_NONE) +}; + /** * @brief A Nether Portal is a player construction that acts as a gateway between the Overworld and the Nether dimensions. It is made of Obsidian and ignited with a Flint&Steel. * The portal is built like this : @@ -62,39 +75,54 @@ enum class PortalDirection { */ class NetherPortal { public: - NetherPortal(std::shared_ptr dim): - _dim(dim) + NetherPortal(std::shared_ptr dim, Position pos): + _dim(dim), + _pos(pos) { + setIgnitedBlock(); + setLeftCornerPosition(); + setDirection(); + setSize(); } /** - * @brief Computes the horizontal direction of the portal, meaning if the portal is positionned on the X or Z axis, and whether the coordinates are positives or negatives (POS_X, NEG_X, POS_Z, NEG_Z) (atm, only works when lighting a bottom block) + * @brief Sets _ignitedBlock to (TOP_CENTER, LEFT_CENTER, RIGHT_CENTER, BOTTOM_CENTER, TOP_RIGHT_CORNER, TOP_LEFT_CORNER, BOTTOM_RIGHT_CORNER, BOTTOM_LEFT_CORNER, NONE) depending on which side of the alleged frame the ignited block is located + * + */ + void setIgnitedBlock(); + + /** + * @brief Sets _bottomLeftCorner to the position of the leftmost obsidian block on the bottom side of the portal, from the inner part of the portal (the corner block, if obsidian, isn't taken into account) * - * @param pos The position of the ignited block - * @return A PortalDirection containing the horizontal direction of the portal (POS_X, NEG_X, POS_Z, NEG_Z) */ - PortalDirection computeDirection(Position pos); + void setBottomLeftCorner(); /** - * @brief Computes the two dimentional sizes of the portal (atm, only works when lighting a bottom block) + * @brief Sets _direction to the horizontal direction of the portal, meaning if the portal is positionned on the X or Z axis, and whether the coordinates are positives or negatives (POS_X, NEG_X, POS_Z, NEG_Z) (atm, only works when lighting a bottom block) * - * @param pos The position of the ignited block - * @param direction The direction of the alledged portal on the horizontal axis (X or Z) - * @return A Vector2 containing the width & the height of the portal (respectively): {PORTAL_WIDTH, PORTAL_HEIGHT} */ - Vector2 computeSize(Position pos, PortalDirection direction); + void setDirection(); /** - * @brief Build the portal within the already built frame + * @brief Sets _size to the two dimentional sizes of the portal (atm, only works when lighting a bottom block) * - * @param pos The position of the frame */ - void buildPortal(Position pos); + void setSize(); + + /** + * @brief Open the portal within the frame + * + * @param pos The position of the fire block created by the Flint&Steel + */ + void openPortal(); private: std::shared_ptr _dim; /**< The dimension where the portal is in */ - Vector2 _size; /**< The size of the portal {PORTAL_WIDTH, PORTAL_HEIGHT} */ + Position _pos; /**< The position of the fire block created by the Flint&Steel */ + PortalIgnition _ignitedBlock; /**< The side of the alleged frame the ignited block is located */ + Position _bottomLeftCorner; /**< The position of the bottom-left block under the inner frame (used for calculations) */ PortalDirection _direction; /**< The horizontal direction of the portal (POS_X, NEG_X, POS_Z, NEG_Z) */ + Vector2 _size; /**< The size of the portal {PORTAL_WIDTH, PORTAL_HEIGHT} */ }; #endif // CUBICSERVER_GENERATION_PLAYER_CONSTRUCTIONS_NETHER_PORTAL_HPP diff --git a/cubic-server/items/usable-items/FlintAndSteel.cpp b/cubic-server/items/usable-items/FlintAndSteel.cpp index d5380680a..1f8eda34c 100644 --- a/cubic-server/items/usable-items/FlintAndSteel.cpp +++ b/cubic-server/items/usable-items/FlintAndSteel.cpp @@ -23,7 +23,7 @@ nbt_tag_t *Items::FlintAndSteel::setNbtTag() void Items::FlintAndSteel::onUseOn(std::shared_ptr dim, Position &pos, UNUSED UsabilityType usage, UNUSED int32_t face, UNUSED Entity &user) { - auto portal = NetherPortal(dim); + auto portal = NetherPortal(dim, pos); dim->updateBlock( pos, Blocks::Fire::toProtocol( @@ -40,5 +40,5 @@ void Items::FlintAndSteel::onUseOn(std::shared_ptr dim, Position &pos )} ); } - portal.buildPortal({pos.x, pos.y - 1, pos.z}); /**< Position of the ignited block */ + portal.openPortal(); } From d131a1a1c949f72edc1137a6225cbee6320a32d3 Mon Sep 17 00:00:00 2001 From: Fluffy Loafie <62648027+fluffyloafie@users.noreply.github.com> Date: Wed, 16 Apr 2025 18:33:50 +0200 Subject: [PATCH 08/10] Add beginning of setting the bottom-left corner --- .../player_constructions/NetherPortal.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cubic-server/generation/player_constructions/NetherPortal.cpp b/cubic-server/generation/player_constructions/NetherPortal.cpp index e4d868e9b..338ca9544 100644 --- a/cubic-server/generation/player_constructions/NetherPortal.cpp +++ b/cubic-server/generation/player_constructions/NetherPortal.cpp @@ -70,7 +70,19 @@ void NetherPortal::setIgnitedBlock() { } void NetherPortal::setBottomLeftCorner() { - _bottomLeftCorner = _pos; + auto block = _dim->getBlock(_pos); + + if (_ignitedBlock == PortalIgnition::PORTAL_BOTTOM_LEFT_CORNER) { + _bottomLeftCorner = {_pos.x, pos.y - 1, pos.z}; + return; + } else if (_ignitedBlock == PortalIgnition::PORTAL_TOP_LEFT_CORNER || _ignitedBlock == PortalIgnition::PORTAL_LEFT_CENTER) { + for (int count = 0; count < PortalBoundary::PORTAL_MAX_HEIGHT - PortalBoundary::PORTAL_MIN_HEIGHT; count++) { + if (_dim->getBlock({_pos.x, pos.y - count, pos.z}) != Blocks::Obsidian::toProtocol()) + continue; + _bottomLeftCorner = {_pos.x, pos.y - count, pos.z}; + return; + } + } } void NetherPortal::setDirection() { @@ -148,7 +160,7 @@ void NetherPortal::setSize() { } totalCountVertical += PortalBoundary::PORTAL_MIN_HEIGHT; - if (totalCountVertical + PortalBoundary::PORTAL_MIN_HEIGHT > PortalBoundary::PORTAL_MAX_HEIGHT) { + if (totalCountVertical > PortalBoundary::PORTAL_MAX_HEIGHT) { _size = {PortalError::PORTAL_BAD_PORTAL, PortalError::PORTAL_SIZE_OVERFLOW}; return; } From 27f2b8fc571ec5bbe43f3b6e6768958de02a15b4 Mon Sep 17 00:00:00 2001 From: Fluffy Loafie <62648027+fluffyloafie@users.noreply.github.com> Date: Thu, 17 Apr 2025 15:30:02 +0200 Subject: [PATCH 09/10] Add openning of the portal - Add detection of the bottom-left corner of the inner frame - Add direction computation - Add size of the inner frame computation - Add openning of the portal if no obstruction within the frame * None of these additions were tested yet, WIP --- .../player_constructions/NetherPortal.cpp | 246 +++++++++--------- .../player_constructions/NetherPortal.hpp | 24 +- 2 files changed, 134 insertions(+), 136 deletions(-) diff --git a/cubic-server/generation/player_constructions/NetherPortal.cpp b/cubic-server/generation/player_constructions/NetherPortal.cpp index 338ca9544..5c9b55229 100644 --- a/cubic-server/generation/player_constructions/NetherPortal.cpp +++ b/cubic-server/generation/player_constructions/NetherPortal.cpp @@ -7,46 +7,46 @@ #include void NetherPortal::setIgnitedBlock() { - std::vector> blocksArray; + std::vector blocksArray; // blockArray[0] & blockArray[1] - {-1;0;0}, {1;0;0} - LEFT or RIGHT for (int x = -1; x <= 1; x++) { if (x != 0) continue; auto lateralBlock = {_pos.x + x, _pos.y, _pos.z}; - blocksArray.push_back({lateralBlock, _dim->getBlock(lateralBlock)}); + blocksArray.push_back(_dim->getBlock(lateralBlock)); } // blockArray[2] & blockArray[3] - {0;-1;0}, {0;1;0} - TOP or BOTTOM for (int y = -1; y <= 1; y++) { if (y != 0) continue; auto lateralBlock = {_pos.x, _pos.y + y, _pos.z}; - blocksArray.push_back({lateralBlock, _dim->getBlock(lateralBlock)}); + blocksArray.push_back(_dim->getBlock(lateralBlock)); } // blockArray[4] & blockArray[5] - {0;0;-1}, {0;0;1} - LEFT or RIGHT for (int z = -1; z <= 1; z++) { if (z != 0) continue; auto lateralBlock = {_pos.x, _pos.y, _pos.z + z}; - blocksArray.push_back({lateralBlock, _dim->getBlock(lateralBlock)}); + blocksArray.push_back(_dim->getBlock(lateralBlock)); } - if (blocksArray[4].second == Blocks::Obsidian::toProtocol() && blocksArray[5].second != Blocks::Obsidian::toProtocol()) { - if ((blocksArray[0].second == Blocks::Obsidian::toProtocol() && blocksArray[1].second != Blocks::Obsidian::toProtocol()) || (blocksArray[2].second == Blocks::Obsidian::toProtocol() && blocksArray[3].second != Blocks::Obsidian::toProtocol())) { + if (blocksArray[4] == Blocks::Obsidian::toProtocol() && blocksArray[5] != Blocks::Obsidian::toProtocol()) { + if ((blocksArray[0] == Blocks::Obsidian::toProtocol() && blocksArray[1] != Blocks::Obsidian::toProtocol()) || (blocksArray[2] == Blocks::Obsidian::toProtocol() && blocksArray[3] != Blocks::Obsidian::toProtocol())) { _ignitedBlock = PortalIgnition::PORTAL_TOP_LEFT_CORNER; return; - } else if ((blocksArray[1].second == Blocks::Obsidian::toProtocol() && blocksArray[0].second != Blocks::Obsidian::toProtocol()) || (blocksArray[3].second == Blocks::Obsidian::toProtocol() && blocksArray[2].second != Blocks::Obsidian::toProtocol())) { + } else if ((blocksArray[1] == Blocks::Obsidian::toProtocol() && blocksArray[0] != Blocks::Obsidian::toProtocol()) || (blocksArray[3] == Blocks::Obsidian::toProtocol() && blocksArray[2] != Blocks::Obsidian::toProtocol())) { _ignitedBlock = PortalIgnition::PORTAL_TOP_RIGHT_CORNER; return; } else { _ignitedBlock = PortalIgnition::PORTAL_TOP_CENTER; return; } - } else if (blocksArray[4].second != Blocks::Obsidian::toProtocol() && blocksArray[5].second == Blocks::Obsidian::toProtocol()) { - if ((blocksArray[0].second == Blocks::Obsidian::toProtocol() && blocksArray[1].second != Blocks::Obsidian::toProtocol()) || (blocksArray[2].second == Blocks::Obsidian::toProtocol() && blocksArray[3].second != Blocks::Obsidian::toProtocol())) { + } else if (blocksArray[4] != Blocks::Obsidian::toProtocol() && blocksArray[5] == Blocks::Obsidian::toProtocol()) { + if ((blocksArray[0] == Blocks::Obsidian::toProtocol() && blocksArray[1] != Blocks::Obsidian::toProtocol()) || (blocksArray[2] == Blocks::Obsidian::toProtocol() && blocksArray[3] != Blocks::Obsidian::toProtocol())) { _ignitedBlock = PortalIgnition::PORTAL_BOTTOM_LEFT_CORNER; return; - } else if ((blocksArray[1].second == Blocks::Obsidian::toProtocol() && blocksArray[0].second != Blocks::Obsidian::toProtocol()) || (blocksArray[3].second == Blocks::Obsidian::toProtocol() && blocksArray[2].second != Blocks::Obsidian::toProtocol())) { + } else if ((blocksArray[1] == Blocks::Obsidian::toProtocol() && blocksArray[0] != Blocks::Obsidian::toProtocol()) || (blocksArray[3] == Blocks::Obsidian::toProtocol() && blocksArray[2] != Blocks::Obsidian::toProtocol())) { _ignitedBlock = PortalIgnition::PORTAL_BOTTOM_RIGHT_CORNER; return; } else { @@ -54,10 +54,10 @@ void NetherPortal::setIgnitedBlock() { return; } } else { - if ((blocksArray[0].second == Blocks::Obsidian::toProtocol() && blocksArray[1].second != Blocks::Obsidian::toProtocol()) || (blocksArray[2].second == Blocks::Obsidian::toProtocol() && blocksArray[3].second != Blocks::Obsidian::toProtocol())) { + if ((blocksArray[0] == Blocks::Obsidian::toProtocol() && blocksArray[1] != Blocks::Obsidian::toProtocol()) || (blocksArray[2] == Blocks::Obsidian::toProtocol() && blocksArray[3] != Blocks::Obsidian::toProtocol())) { _ignitedBlock = PortalIgnition::PORTAL_LEFT_CENTER; return; - } else if ((blocksArray[1].second == Blocks::Obsidian::toProtocol() && blocksArray[0].second != Blocks::Obsidian::toProtocol()) || (blocksArray[3].second == Blocks::Obsidian::toProtocol() && blocksArray[2].second != Blocks::Obsidian::toProtocol())) { + } else if ((blocksArray[1] == Blocks::Obsidian::toProtocol() && blocksArray[0] != Blocks::Obsidian::toProtocol()) || (blocksArray[3] == Blocks::Obsidian::toProtocol() && blocksArray[2] != Blocks::Obsidian::toProtocol())) { _ignitedBlock = PortalIgnition::PORTAL_RIGHT_CENTER; return; } else { @@ -70,143 +70,143 @@ void NetherPortal::setIgnitedBlock() { } void NetherPortal::setBottomLeftCorner() { - auto block = _dim->getBlock(_pos); - if (_ignitedBlock == PortalIgnition::PORTAL_BOTTOM_LEFT_CORNER) { - _bottomLeftCorner = {_pos.x, pos.y - 1, pos.z}; + _bottomLeftCorner = {_pos.x, _pos.y - 1, _pos.z}; + return; + } else if (_ignitedBlock == PortalIgnition::PORTAL_NONE) { return; } else if (_ignitedBlock == PortalIgnition::PORTAL_TOP_LEFT_CORNER || _ignitedBlock == PortalIgnition::PORTAL_LEFT_CENTER) { - for (int count = 0; count < PortalBoundary::PORTAL_MAX_HEIGHT - PortalBoundary::PORTAL_MIN_HEIGHT; count++) { - if (_dim->getBlock({_pos.x, pos.y - count, pos.z}) != Blocks::Obsidian::toProtocol()) - continue; - _bottomLeftCorner = {_pos.x, pos.y - count, pos.z}; - return; + for (int count = 1; count < PortalBoundary::PORTAL_MAX_HEIGHT - PortalBoundary::PORTAL_MIN_HEIGHT - PortalBoundary::PORTAL_NO_CORNERS; count++) { + if (_dim->getBlock({_pos.x, _pos.y - count, _pos.z}) == Blocks::Obsidian::toProtocol()) { + _bottomLeftCorner = {_pos.x, _pos.y - count, _pos.z}; + return; + } + } + } else if (_ignitedBlock == PortalIgnition::PORTAL_BOTTOM_RIGHT_CORNER || _ignitedBlock == PortalIgnition::PORTAL_BOTTOM_CENTER) { + for (int count = 1; count < PortalBoundary::PORTAL_MAX_WIDTH - PortalBoundary::PORTAL_MIN_WIDTH - PortalBoundary::PORTAL_NO_CORNERS; count++) { + if (_dim->getBlock({_pos.x - count, _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol() && count > 1) { + _bottomLeftCorner = {_pos.x - count, _pos.y - 1, _pos.z}; + _direction = PortalDirection::PORTAL_X_AXIS; + return; + } else if (_dim->getBlock({_pos.x, _pos.y, _pos.z - count}) == Blocks::Obsidian::toProtocol() && count > 1) { + _bottomLeftCorner = {_pos.x, _pos.y - 1, _pos.z - count}; + _direction = PortalDirection::PORTAL_Z_AXIS; + return; + } + } + } else { + for (int countY = 1; countY < PortalBoundary::PORTAL_MAX_HEIGHT - PortalBoundary::PORTAL_MIN_HEIGHT - PortalBoundary::PORTAL_NO_CORNERS; countY++) { + for (int count = 1; count < PortalBoundary::PORTAL_MAX_WIDTH - PortalBoundary::PORTAL_MIN_WIDTH - PortalBoundary::PORTAL_NO_CORNERS; count++) { + if (_dim->getBlock({_pos.x, _pos.y - countY, _pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x - count, _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol() && count > 1) { + _bottomLeftCorner = {_pos.x - count, _pos.y - countY, _pos.z}; + _direction = PortalDirection::PORTAL_X_AXIS; + return; + } else if (_dim->getBlock({_pos.x, _pos.y - countY, _pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x, _pos.y, _pos.z - count}) == Blocks::Obsidian::toProtocol() && count > 1) { + _bottomLeftCorner = {_pos.x, _pos.y - countY, _pos.z - count}; + _direction = PortalDirection::PORTAL_Z_AXIS; + return; + } + } } } + _bottomLeftCorner = _pos; + _direction = PortalDirection::PORTAL_WRONG_DIRECTION; } void NetherPortal::setDirection() { - int countRightX = 1; - int countLeftX = 1; - int totalCountX = -1; - int countRightZ = 1; - int countLeftZ = 1; - int totalCountZ = -1; - - // Count how many aligned obsidian blocks on the X axis - while (_dim->getBlock({_pos.x + countRightX, _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x + (countRightX-1), _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol()) - countRightX++; - while (_dim->getBlock({_pos.x - countLeftX, _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x - (countLeftX-1), _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol()) - countLeftX++; - totalCountX += countRightX + countLeftX; - - // Count how many aligned obsidian blocks on the Z axis - while (_dim->getBlock({_pos.x, _pos.y, _pos.z + countRightZ}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x, _pos.y, _pos.z + (countRightZ-1)}) == Blocks::Obsidian::toProtocol()) - countRightZ++; - while (_dim->getBlock({_pos.x, _pos.y, _pos.z - countLeftZ}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x, _pos.y, _pos.z - (countLeftZ-1)}) == Blocks::Obsidian::toProtocol()) - countLeftZ++; - totalCountZ += countRightZ + countLeftZ; + if (_ignitedBlock == PortalIgnition::PORTAL_NONE || _direction == PortalDirection::PORTAL_WRONG_DIRECTION || _direction == PortalDirection::PORTAL_X_AXIS || _direction == PortalDirection::PORTAL_Z_AXIS) + return; - if (totalCountX > totalCountZ) { - if (countLeftX > countRightX) { - _direction = PortalDirection::PORTAL_NEG_X; - return; - } else { - _direction = PortalDirection::PORTAL_POS_X; - return; - } - } else { - if (countLeftZ > countRightZ) { - _direction = PortalDirection::PORTAL_NEG_Z; - return; - } else { - _direction = PortalDirection::PORTAL_POS_Z; - return; - } + if (_dim->getBlock({_pos.x - 1, _pos.y + 1, _pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x + 1, _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol() && (_dim->getBlock({_pos.x + 2, _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol() || _dim->getBlock({_pos.x + 2, _pos.y + 1, _pos.z}) == Blocks::Obsidian::toProtocol())) { + _direction = PortalDirection::PORTAL_X_AXIS; + return; + } else if (_dim->getBlock({_pos.x, _pos.y + 1, _pos.z - 1}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x, _pos.y, _pos.z + 1}) == Blocks::Obsidian::toProtocol() && (_dim->getBlock({_pos.x, _pos.y, _pos.z + 2}) == Blocks::Obsidian::toProtocol() || _dim->getBlock({_pos.x, _pos.y + 1, _pos.z + 2}) == Blocks::Obsidian::toProtocol())) { + _direction = PortalDirection::PORTAL_Z_AXIS; + return; } _direction = PortalDirection::PORTAL_WRONG_DIRECTION; } void NetherPortal::setSize() { - int countRight = 1; /**< for the right blocks from block horizontally (set to 1 to take block into account) */ - int countLeft = 1; /**< for the left blocks from block horizontally (set to 1 to take block into account) */ - int totalCountHorizontal = -1; /**< for the total blocks horizontally (set to -1 to address the offset when adding the right & left parts) */ - int totalCountVertical = 1; + if (_ignitedBlock == PortalIgnition::PORTAL_NONE) + return; - if (_direction == PortalDirection::PORTAL_POS_X || _direction == PortalDirection::PORTAL_NEG_X) { - while (_dim->getBlock({_pos.x + countRight, _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x + (countRight-1), _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x + countRight, _pos.y + 1, _pos.z}) == Blocks::Air::toProtocol()) - countRight++; - while (_dim->getBlock({_pos.x - countLeft, _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x - (countLeft-1), _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x - countLeft, _pos.y + 1, _pos.z}) == Blocks::Air::toProtocol()) - countLeft++; - while ((_dim->getBlock({_pos.x-(countLeft-1), _pos.y + totalCountVertical, _pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x-(countLeft-1), _pos.y + (totalCountVertical-1), _pos.z}) == Blocks::Obsidian::toProtocol()) - || (_dim->getBlock({_pos.x+(countRight+1), _pos.y + totalCountVertical, _pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x+countRight+1, _pos.y + (totalCountVertical-1), _pos.z}) == Blocks::Obsidian::toProtocol())) - totalCountVertical++; - } else if (_direction == PortalDirection::PORTAL_POS_Z || _direction == PortalDirection::PORTAL_NEG_Z) { - while (_dim->getBlock({_pos.x, _pos.y, _pos.z + countRight}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x, _pos.y, _pos.z + (countRight-1)}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x, _pos.y + 1, _pos.z + countRight}) == Blocks::Air::toProtocol()) - countRight++; - while (_dim->getBlock({_pos.x, _pos.y, _pos.z - countLeft}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x, _pos.y, _pos.z - (countLeft-1)}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x, _pos.y + 1, _pos.z - countLeft}) == Blocks::Air::toProtocol()) - countLeft++; - while ((_dim->getBlock({_pos.x, _pos.y + totalCountVertical, _pos.z+(countRight+1)}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x, _pos.y + (totalCountVertical-1), _pos.z+(countRight+1)}) == Blocks::Obsidian::toProtocol()) - || (_dim->getBlock({_pos.x, _pos.y + totalCountVertical, _pos.z-(countLeft-1)}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x, _pos.y + (totalCountVertical-1), _pos.z-(countLeft-1)}) == Blocks::Obsidian::toProtocol())) - totalCountVertical++; + if (_direction == PortalDirection::PORTAL_X_AXIS) { + for (int countWidth = 1; countWidth < (PortalBoundary::PORTAL_MAX_WIDTH - PortalBoundary::PORTAL_NO_CORNERS); countWidth++) { + if (_dim->getBlock({_bottomLeftCorner.x + (countWidth - 1), _bottomLeftCorner.y, _bottomLeftCorner.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_bottomLeftCorner.x + countWidth, _bottomLeftCorner.y + 1, _bottomLeftCorner.z}) == Blocks::Obsidian::toProtocol() && countWidth >= (PortalBoundary::PORTAL_MIN_WIDTH - PortalBoundary::PORTAL_NO_CORNERS)) { + _size.x = countWidth - 1; + } + } + for (int countHeight = 1; countHeight < (PortalBoundary::PORTAL_MAX_HEIGHT - PortalBoundary::PORTAL_NO_CORNERS); countHeight++) { + if (_dim->getBlock({_bottomLeftCorner.x - 1, _bottomLeftCorner.y + (countHeight - 1), _bottomLeftCorner.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_bottomLeftCorner.x, _bottomLeftCorner.y + countHeight, _bottomLeftCorner.z}) == Blocks::Obsidian::toProtocol() && countHeight > (PortalBoundary::PORTAL_MIN_HEIGHT - PortalBoundary::PORTAL_NO_CORNERS)) { + _size.z = countHeight - 1; + } + } + } else if (_direction == PortalDirection::PORTAL_Z_AXIS) { + for (int countWidth = 1; countWidth < (PortalBoundary::PORTAL_MAX_WIDTH - PortalBoundary::PORTAL_NO_CORNERS); countWidth++) { + if (_dim->getBlock({_bottomLeftCorner.x, _bottomLeftCorner.y, _bottomLeftCorner.z + (countWidth - 1)}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_bottomLeftCorner.x, _bottomLeftCorner.y + 1, _bottomLeftCorner.z + countWidth}) == Blocks::Obsidian::toProtocol() && countWidth >= (PortalBoundary::PORTAL_MIN_WIDTH - PortalBoundary::PORTAL_NO_CORNERS)) { + _size.x = countWidth - 1; + } + } + for (int countHeight = 1; countHeight < (PortalBoundary::PORTAL_MAX_HEIGHT - PortalBoundary::PORTAL_NO_CORNERS); countHeight++) { + if (_dim->getBlock({_bottomLeftCorner.x, _bottomLeftCorner.y + (countHeight - 1), _bottomLeftCorner.z - 1}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_bottomLeftCorner.x, _bottomLeftCorner.y + countHeight, _bottomLeftCorner.z}) == Blocks::Obsidian::toProtocol() && countHeight > (PortalBoundary::PORTAL_MIN_HEIGHT - PortalBoundary::PORTAL_NO_CORNERS)) { + _size.z = countHeight - 1; + } + } } else - _size = {PortalError::PORTAL_BAD_PORTAL, PortalError::PORTAL_WRONG_DIRECTION}; - - totalCountHorizontal += countRight + countLeft + PortalBoundary::PORTAL_MIN_WIDTH; - if (totalCountHorizontal > PortalBoundary::PORTAL_MAX_WIDTH) { - _size = {PortalError::PORTAL_BAD_PORTAL, PortalError::PORTAL_SIZE_OVERFLOW}; - return; - } + _size = {PortalError::PORTAL_BAD_PORTAL, _direction}; - totalCountVertical += PortalBoundary::PORTAL_MIN_HEIGHT; - if (totalCountVertical > PortalBoundary::PORTAL_MAX_HEIGHT) { - _size = {PortalError::PORTAL_BAD_PORTAL, PortalError::PORTAL_SIZE_OVERFLOW}; - return; - } - _size = {totalCountHorizontal, totalCountVertical}; + _size = {PortalError::PORTAL_BAD_PORTAL, PortalError::PORTAL_WRONG_SIZE}; } void NetherPortal::openPortal() { std::vector> blocksArray; - auto block = _dim->getBlock(_pos); - for (int y = 0; y < _size.z - 1; y++) { - for (int x = 0; x < _size.x - 1; x++) { - switch (_direction) { - case PortalDirection::PORTAL_POS_X: - block = _dim->getBlock({_pos.x - 1 + x, _pos.y + y, _pos.z}); - if (block == Blocks::Air::toProtocol() || block == Blocks::Fire::toProtocol(Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE)) - blocksArray.push_back({{_pos.x - 1 + x, _pos.y + y, _pos.z}, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::X)}); - break; - case PortalDirection::PORTAL_NEG_X: - block = _dim->getBlock({_pos.x - 2 + x, _pos.y + y, _pos.z}); - if (block == Blocks::Air::toProtocol() || block == Blocks::Fire::toProtocol(Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE)) - blocksArray.push_back({{_pos.x - 2 + x, _pos.y + y, _pos.z}, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::X)}); - break; - case PortalDirection::PORTAL_POS_Z: - block = _dim->getBlock({_pos.x, _pos.y + y, _pos.z - 1 + x}); - if (block == Blocks::Air::toProtocol() || block == Blocks::Fire::toProtocol(Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE)) - blocksArray.push_back({{_pos.x, _pos.y + y, _pos.z - 1 + x}, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::Z)}); - break; - case PortalDirection::PORTAL_NEG_Z: - block = _dim->getBlock({_pos.x, _pos.y + y, _pos.z - 2 + x}); - if (block == Blocks::Air::toProtocol() || block == Blocks::Fire::toProtocol(Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE)) - blocksArray.push_back({{_pos.x, _pos.y + y, _pos.z - 2 + x}, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::Z)}); - break; - default: - LDEBUG("Portal error code: PORTAL_NONE ({})", PortalError::PORTAL_NONE); - break; + if (_ignitedBlock == PortalIgnition::PORTAL_NONE) + return; + + if (_direction == PortalDirection::PORTAL_X_AXIS) { + for (int x = 0; x <= _size.x ; x++) { + for (int y = 1; y <= _size.z ; y++) { + auto position = {_bottomLeftCorner.x + x, _bottomLeftCorner.y + y, _bottomLeftCorner.z}; + auto blockId = _dim->getBlock(position); + blocksArray.push_back({position, blockId}); } } - } - for (auto [position, id] : blocksArray) { - _dim->updateBlock(position, id); - for (auto player : _dim->getPlayers()) { - player->sendBlockUpdate({_pos, _dim->getBlock(_pos)}); - player->sendBlockUpdate({position, id}); - // player->sendUpdateSectionBlock({position,chunk, true, blocksArray}); + for (auto [position, id] : blocksArray) { + if (id != Blocks::Air::toProtocol() && id != Blocks::Fire::toProtocol(Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE)) { + LDEBUG("Obstruction within the frame at position {}: PORTAL_BAD_PORTAL ({})", position, PortalError::PORTAL_BAD_PORTAL); + return; + } else { + _dim->updateBlock(position, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::X)); + for (auto player : _dim->getPlayers()) { + player->sendBlockUpdate({position, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::X}); + } + } } + } else if (_direction == PortalDirection::PORTAL_Z_AXIS) { + for (int z = 0; z <= _size.x ; z++) { + for (int y = 1; y <= _size.z ; y++) { + auto position = {_bottomLeftCorner.x, _bottomLeftCorner.y + y, _bottomLeftCorner.z + z}; + auto blockId = _dim->getBlock(position); + blocksArray.push_back({position, blockId}); + } + } + for (auto [position, id] : blocksArray) { + if (id != Blocks::Air::toProtocol() && id != Blocks::Fire::toProtocol(Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE)) { + LDEBUG("Obstruction within the frame at position {}: PORTAL_BAD_PORTAL ({})", position, PortalError::PORTAL_BAD_PORTAL); + return; + } else { + _dim->updateBlock(position, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::Z)); + for (auto player : _dim->getPlayers()) { + player->sendBlockUpdate({position, Blocks::NetherPortal::toProtocol(Blocks::NetherPortal::Properties::Axis::Z}); + } + } + } + } else { + LDEBUG("No portal at pos {}: PORTAL_NONE ({})", _pos, PortalError::PORTAL_NONE); + return; } } diff --git a/cubic-server/generation/player_constructions/NetherPortal.hpp b/cubic-server/generation/player_constructions/NetherPortal.hpp index f636a761b..3ac3abc07 100644 --- a/cubic-server/generation/player_constructions/NetherPortal.hpp +++ b/cubic-server/generation/player_constructions/NetherPortal.hpp @@ -12,9 +12,9 @@ /* Error codes */ enum class PortalError { - PORTAL_SIZE_OVERFLOW = -1, + PORTAL_OUT_OF_BOUNDARIES = -1, PORTAL_WRONG_DIRECTION = -2, - PORTAL_WRONG_AXIS = -3, + PORTAL_WRONG_SIZE = -3, PORTAL_WRONG_BLOCK = -4, PORTAL_BAD_PORTAL = -42, PORTAL_NONE = -84 @@ -26,22 +26,20 @@ enum class PortalBoundary { PORTAL_MIN_HEIGHT = 5, PORTAL_MAX_WIDTH = 23, PORTAL_MAX_HEIGHT = 23, - PORTAL_WRONG_SIZE = static_cast(PortalError::PORTAL_BAD_PORTAL) + PORTAL_OUT_OF_BOUNDARIES = static_cast(PortalError::PORTAL_OUT_OF_BOUNDARIES) }; -/* The 2 axes defining the portal */ -enum class PortalAxis { +/* The 2 dimensions defining the portal */ +enum class PortalSize { PORTAL_WIDTH, PORTAL_HEIGHT, - PORTAL_WRONG_AXIS = static_cast(PortalError::PORTAL_WRONG_AXIS) + PORTAL_WRONG_SIZE = static_cast(PortalError::PORTAL_WRONG_SIZE) }; -/* The horizontal direction of the portal on the X or Z axis */ +/* The horizontal direction of the portal (on the X or Z axis) */ enum class PortalDirection { - PORTAL_POS_X, - PORTAL_NEG_X, - PORTAL_POS_Z, - PORTAL_NEG_Z, + PORTAL_X_AXIS, + PORTAL_Z_AXIS, PORTAL_WRONG_DIRECTION = static_cast(PortalError::PORTAL_WRONG_DIRECTION) }; @@ -121,8 +119,8 @@ class NetherPortal { Position _pos; /**< The position of the fire block created by the Flint&Steel */ PortalIgnition _ignitedBlock; /**< The side of the alleged frame the ignited block is located */ Position _bottomLeftCorner; /**< The position of the bottom-left block under the inner frame (used for calculations) */ - PortalDirection _direction; /**< The horizontal direction of the portal (POS_X, NEG_X, POS_Z, NEG_Z) */ - Vector2 _size; /**< The size of the portal {PORTAL_WIDTH, PORTAL_HEIGHT} */ + PortalDirection _direction; /**< The horizontal direction of the portal (X or Z) */ + Vector2 _size; /**< The size of the inner part of the portal {PORTAL_WIDTH, PORTAL_HEIGHT} */ }; #endif // CUBICSERVER_GENERATION_PLAYER_CONSTRUCTIONS_NETHER_PORTAL_HPP From 7a5b602848a11c7f945b28212ae5124f68566eb5 Mon Sep 17 00:00:00 2001 From: Fluffy Loafie <62648027+fluffyloafie@users.noreply.github.com> Date: Thu, 17 Apr 2025 16:14:38 +0200 Subject: [PATCH 10/10] Fix most of clang-format errors - Fixed by hand, some might be missing --- .../player_constructions/NetherPortal.cpp | 91 +++++++++++++------ .../player_constructions/NetherPortal.hpp | 14 +-- 2 files changed, 72 insertions(+), 33 deletions(-) diff --git a/cubic-server/generation/player_constructions/NetherPortal.cpp b/cubic-server/generation/player_constructions/NetherPortal.cpp index 5c9b55229..52bfbf6ef 100644 --- a/cubic-server/generation/player_constructions/NetherPortal.cpp +++ b/cubic-server/generation/player_constructions/NetherPortal.cpp @@ -6,7 +6,8 @@ #include "types.hpp" #include -void NetherPortal::setIgnitedBlock() { +void NetherPortal::setIgnitedBlock() +{ std::vector blocksArray; // blockArray[0] & blockArray[1] - {-1;0;0}, {1;0;0} - LEFT or RIGHT @@ -32,10 +33,12 @@ void NetherPortal::setIgnitedBlock() { } if (blocksArray[4] == Blocks::Obsidian::toProtocol() && blocksArray[5] != Blocks::Obsidian::toProtocol()) { - if ((blocksArray[0] == Blocks::Obsidian::toProtocol() && blocksArray[1] != Blocks::Obsidian::toProtocol()) || (blocksArray[2] == Blocks::Obsidian::toProtocol() && blocksArray[3] != Blocks::Obsidian::toProtocol())) { + if ((blocksArray[0] == Blocks::Obsidian::toProtocol() && blocksArray[1] != Blocks::Obsidian::toProtocol()) || + (blocksArray[2] == Blocks::Obsidian::toProtocol() && blocksArray[3] != Blocks::Obsidian::toProtocol())) { _ignitedBlock = PortalIgnition::PORTAL_TOP_LEFT_CORNER; return; - } else if ((blocksArray[1] == Blocks::Obsidian::toProtocol() && blocksArray[0] != Blocks::Obsidian::toProtocol()) || (blocksArray[3] == Blocks::Obsidian::toProtocol() && blocksArray[2] != Blocks::Obsidian::toProtocol())) { + } else if ((blocksArray[1] == Blocks::Obsidian::toProtocol() && blocksArray[0] != Blocks::Obsidian::toProtocol()) || (blocksArray[3] == Blocks::Obsidian::toProtocol() && + blocksArray[2] != Blocks::Obsidian::toProtocol())) { _ignitedBlock = PortalIgnition::PORTAL_TOP_RIGHT_CORNER; return; } else { @@ -43,10 +46,12 @@ void NetherPortal::setIgnitedBlock() { return; } } else if (blocksArray[4] != Blocks::Obsidian::toProtocol() && blocksArray[5] == Blocks::Obsidian::toProtocol()) { - if ((blocksArray[0] == Blocks::Obsidian::toProtocol() && blocksArray[1] != Blocks::Obsidian::toProtocol()) || (blocksArray[2] == Blocks::Obsidian::toProtocol() && blocksArray[3] != Blocks::Obsidian::toProtocol())) { + if ((blocksArray[0] == Blocks::Obsidian::toProtocol() && blocksArray[1] != Blocks::Obsidian::toProtocol()) || + (blocksArray[2] == Blocks::Obsidian::toProtocol() && blocksArray[3] != Blocks::Obsidian::toProtocol())) { _ignitedBlock = PortalIgnition::PORTAL_BOTTOM_LEFT_CORNER; return; - } else if ((blocksArray[1] == Blocks::Obsidian::toProtocol() && blocksArray[0] != Blocks::Obsidian::toProtocol()) || (blocksArray[3] == Blocks::Obsidian::toProtocol() && blocksArray[2] != Blocks::Obsidian::toProtocol())) { + } else if ((blocksArray[1] == Blocks::Obsidian::toProtocol() && blocksArray[0] != Blocks::Obsidian::toProtocol()) || (blocksArray[3] == Blocks::Obsidian::toProtocol() && + blocksArray[2] != Blocks::Obsidian::toProtocol())) { _ignitedBlock = PortalIgnition::PORTAL_BOTTOM_RIGHT_CORNER; return; } else { @@ -54,10 +59,12 @@ void NetherPortal::setIgnitedBlock() { return; } } else { - if ((blocksArray[0] == Blocks::Obsidian::toProtocol() && blocksArray[1] != Blocks::Obsidian::toProtocol()) || (blocksArray[2] == Blocks::Obsidian::toProtocol() && blocksArray[3] != Blocks::Obsidian::toProtocol())) { + if ((blocksArray[0] == Blocks::Obsidian::toProtocol() && blocksArray[1] != Blocks::Obsidian::toProtocol()) || + (blocksArray[2] == Blocks::Obsidian::toProtocol() && blocksArray[3] != Blocks::Obsidian::toProtocol())) { _ignitedBlock = PortalIgnition::PORTAL_LEFT_CENTER; return; - } else if ((blocksArray[1] == Blocks::Obsidian::toProtocol() && blocksArray[0] != Blocks::Obsidian::toProtocol()) || (blocksArray[3] == Blocks::Obsidian::toProtocol() && blocksArray[2] != Blocks::Obsidian::toProtocol())) { + } else if ((blocksArray[1] == Blocks::Obsidian::toProtocol() && blocksArray[0] != Blocks::Obsidian::toProtocol()) || (blocksArray[3] == Blocks::Obsidian::toProtocol() && + blocksArray[2] != Blocks::Obsidian::toProtocol())) { _ignitedBlock = PortalIgnition::PORTAL_RIGHT_CENTER; return; } else { @@ -69,7 +76,8 @@ void NetherPortal::setIgnitedBlock() { _ignitedBlock = PortalIgnition::PORTAL_NONE; } -void NetherPortal::setBottomLeftCorner() { +void NetherPortal::setBottomLeftCorner() +{ if (_ignitedBlock == PortalIgnition::PORTAL_BOTTOM_LEFT_CORNER) { _bottomLeftCorner = {_pos.x, _pos.y - 1, _pos.z}; return; @@ -97,11 +105,13 @@ void NetherPortal::setBottomLeftCorner() { } else { for (int countY = 1; countY < PortalBoundary::PORTAL_MAX_HEIGHT - PortalBoundary::PORTAL_MIN_HEIGHT - PortalBoundary::PORTAL_NO_CORNERS; countY++) { for (int count = 1; count < PortalBoundary::PORTAL_MAX_WIDTH - PortalBoundary::PORTAL_MIN_WIDTH - PortalBoundary::PORTAL_NO_CORNERS; count++) { - if (_dim->getBlock({_pos.x, _pos.y - countY, _pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x - count, _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol() && count > 1) { + if (_dim->getBlock({_pos.x, _pos.y - countY, _pos.z}) == Blocks::Obsidian::toProtocol() && + _dim->getBlock({_pos.x - count, _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol() && count > 1) { _bottomLeftCorner = {_pos.x - count, _pos.y - countY, _pos.z}; _direction = PortalDirection::PORTAL_X_AXIS; return; - } else if (_dim->getBlock({_pos.x, _pos.y - countY, _pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x, _pos.y, _pos.z - count}) == Blocks::Obsidian::toProtocol() && count > 1) { + } else if (_dim->getBlock({_pos.x, _pos.y - countY, _pos.z}) == Blocks::Obsidian::toProtocol() && + _dim->getBlock({_pos.x, _pos.y, _pos.z - count}) == Blocks::Obsidian::toProtocol() && count > 1) { _bottomLeftCorner = {_pos.x, _pos.y - countY, _pos.z - count}; _direction = PortalDirection::PORTAL_Z_AXIS; return; @@ -113,14 +123,22 @@ void NetherPortal::setBottomLeftCorner() { _direction = PortalDirection::PORTAL_WRONG_DIRECTION; } -void NetherPortal::setDirection() { - if (_ignitedBlock == PortalIgnition::PORTAL_NONE || _direction == PortalDirection::PORTAL_WRONG_DIRECTION || _direction == PortalDirection::PORTAL_X_AXIS || _direction == PortalDirection::PORTAL_Z_AXIS) +void NetherPortal::setDirection() +{ + if (_ignitedBlock == PortalIgnition::PORTAL_NONE || _direction == PortalDirection::PORTAL_WRONG_DIRECTION || _direction == PortalDirection::PORTAL_X_AXIS || + _direction == PortalDirection::PORTAL_Z_AXIS) return; - if (_dim->getBlock({_pos.x - 1, _pos.y + 1, _pos.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x + 1, _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol() && (_dim->getBlock({_pos.x + 2, _pos.y, _pos.z}) == Blocks::Obsidian::toProtocol() || _dim->getBlock({_pos.x + 2, _pos.y + 1, _pos.z}) == Blocks::Obsidian::toProtocol())) { + if (_dim->getBlock({_bottomLeftCorner.x - 1, _bottomLeftCorner.y + 1, _bottomLeftCorner.z}) == Blocks::Obsidian::toProtocol() && + _dim->getBlock({_bottomLeftCorner.x + 1, _bottomLeftCorner.y, _bottomLeftCorner.z}) == Blocks::Obsidian::toProtocol() && + (_dim->getBlock({_bottomLeftCorner.x + 2, _bottomLeftCorner.y, _bottomLeftCorner.z}) == Blocks::Obsidian::toProtocol() || + _dim->getBlock({_bottomLeftCorner.x + 2, _bottomLeftCorner.y + 1, _bottomLeftCorner.z}) == Blocks::Obsidian::toProtocol())) { _direction = PortalDirection::PORTAL_X_AXIS; return; - } else if (_dim->getBlock({_pos.x, _pos.y + 1, _pos.z - 1}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_pos.x, _pos.y, _pos.z + 1}) == Blocks::Obsidian::toProtocol() && (_dim->getBlock({_pos.x, _pos.y, _pos.z + 2}) == Blocks::Obsidian::toProtocol() || _dim->getBlock({_pos.x, _pos.y + 1, _pos.z + 2}) == Blocks::Obsidian::toProtocol())) { + } else if (_dim->getBlock({_bottomLeftCorner.x, _bottomLeftCorner.y + 1, _bottomLeftCorner.z - 1}) == Blocks::Obsidian::toProtocol() && + _dim->getBlock({_bottomLeftCorner.x, _bottomLeftCorner.y, _bottomLeftCorner.z + 1}) == Blocks::Obsidian::toProtocol() && + (_dim->getBlock({_bottomLeftCorner.x, _bottomLeftCorner.y, _bottomLeftCorner.z + 2}) == Blocks::Obsidian::toProtocol() || + _dim->getBlock({_bottomLeftCorner.x, _bottomLeftCorner.y + 1, _bottomLeftCorner.z + 2}) == Blocks::Obsidian::toProtocol())) { _direction = PortalDirection::PORTAL_Z_AXIS; return; } @@ -128,55 +146,69 @@ void NetherPortal::setDirection() { _direction = PortalDirection::PORTAL_WRONG_DIRECTION; } -void NetherPortal::setSize() { +void NetherPortal::setSize() +{ if (_ignitedBlock == PortalIgnition::PORTAL_NONE) return; if (_direction == PortalDirection::PORTAL_X_AXIS) { for (int countWidth = 1; countWidth < (PortalBoundary::PORTAL_MAX_WIDTH - PortalBoundary::PORTAL_NO_CORNERS); countWidth++) { - if (_dim->getBlock({_bottomLeftCorner.x + (countWidth - 1), _bottomLeftCorner.y, _bottomLeftCorner.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_bottomLeftCorner.x + countWidth, _bottomLeftCorner.y + 1, _bottomLeftCorner.z}) == Blocks::Obsidian::toProtocol() && countWidth >= (PortalBoundary::PORTAL_MIN_WIDTH - PortalBoundary::PORTAL_NO_CORNERS)) { + if (_dim->getBlock({_bottomLeftCorner.x + (countWidth - 1), _bottomLeftCorner.y, _bottomLeftCorner.z}) == Blocks::Obsidian::toProtocol() && + _dim->getBlock({_bottomLeftCorner.x + countWidth, _bottomLeftCorner.y + 1, _bottomLeftCorner.z}) == Blocks::Obsidian::toProtocol() && + countWidth >= (PortalBoundary::PORTAL_MIN_WIDTH - PortalBoundary::PORTAL_NO_CORNERS)) { _size.x = countWidth - 1; } } for (int countHeight = 1; countHeight < (PortalBoundary::PORTAL_MAX_HEIGHT - PortalBoundary::PORTAL_NO_CORNERS); countHeight++) { - if (_dim->getBlock({_bottomLeftCorner.x - 1, _bottomLeftCorner.y + (countHeight - 1), _bottomLeftCorner.z}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_bottomLeftCorner.x, _bottomLeftCorner.y + countHeight, _bottomLeftCorner.z}) == Blocks::Obsidian::toProtocol() && countHeight > (PortalBoundary::PORTAL_MIN_HEIGHT - PortalBoundary::PORTAL_NO_CORNERS)) { + if (_dim->getBlock({_bottomLeftCorner.x - 1, _bottomLeftCorner.y + (countHeight - 1), _bottomLeftCorner.z}) == Blocks::Obsidian::toProtocol() && + _dim->getBlock({_bottomLeftCorner.x, _bottomLeftCorner.y + countHeight, _bottomLeftCorner.z}) == Blocks::Obsidian::toProtocol() && + countHeight > (PortalBoundary::PORTAL_MIN_HEIGHT - PortalBoundary::PORTAL_NO_CORNERS)) { _size.z = countHeight - 1; } } } else if (_direction == PortalDirection::PORTAL_Z_AXIS) { for (int countWidth = 1; countWidth < (PortalBoundary::PORTAL_MAX_WIDTH - PortalBoundary::PORTAL_NO_CORNERS); countWidth++) { - if (_dim->getBlock({_bottomLeftCorner.x, _bottomLeftCorner.y, _bottomLeftCorner.z + (countWidth - 1)}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_bottomLeftCorner.x, _bottomLeftCorner.y + 1, _bottomLeftCorner.z + countWidth}) == Blocks::Obsidian::toProtocol() && countWidth >= (PortalBoundary::PORTAL_MIN_WIDTH - PortalBoundary::PORTAL_NO_CORNERS)) { + if (_dim->getBlock({_bottomLeftCorner.x, _bottomLeftCorner.y, _bottomLeftCorner.z + (countWidth - 1)}) == Blocks::Obsidian::toProtocol() && + _dim->getBlock({_bottomLeftCorner.x, _bottomLeftCorner.y + 1, _bottomLeftCorner.z + countWidth}) == Blocks::Obsidian::toProtocol() && + countWidth >= (PortalBoundary::PORTAL_MIN_WIDTH - PortalBoundary::PORTAL_NO_CORNERS)) { _size.x = countWidth - 1; } } for (int countHeight = 1; countHeight < (PortalBoundary::PORTAL_MAX_HEIGHT - PortalBoundary::PORTAL_NO_CORNERS); countHeight++) { - if (_dim->getBlock({_bottomLeftCorner.x, _bottomLeftCorner.y + (countHeight - 1), _bottomLeftCorner.z - 1}) == Blocks::Obsidian::toProtocol() && _dim->getBlock({_bottomLeftCorner.x, _bottomLeftCorner.y + countHeight, _bottomLeftCorner.z}) == Blocks::Obsidian::toProtocol() && countHeight > (PortalBoundary::PORTAL_MIN_HEIGHT - PortalBoundary::PORTAL_NO_CORNERS)) { + if (_dim->getBlock({_bottomLeftCorner.x, _bottomLeftCorner.y + (countHeight - 1), _bottomLeftCorner.z - 1}) == Blocks::Obsidian::toProtocol() && + _dim->getBlock({_bottomLeftCorner.x, _bottomLeftCorner.y + countHeight, _bottomLeftCorner.z}) == Blocks::Obsidian::toProtocol() && + countHeight > (PortalBoundary::PORTAL_MIN_HEIGHT - PortalBoundary::PORTAL_NO_CORNERS)) { _size.z = countHeight - 1; } } } else _size = {PortalError::PORTAL_BAD_PORTAL, _direction}; - _size = {PortalError::PORTAL_BAD_PORTAL, PortalError::PORTAL_WRONG_SIZE}; } -void NetherPortal::openPortal() { +void NetherPortal::openPortal() +{ std::vector> blocksArray; if (_ignitedBlock == PortalIgnition::PORTAL_NONE) return; if (_direction == PortalDirection::PORTAL_X_AXIS) { - for (int x = 0; x <= _size.x ; x++) { - for (int y = 1; y <= _size.z ; y++) { + for (int x = 0; x <= _size.x; x++) { + for (int y = 1; y <= _size.z; y++) { auto position = {_bottomLeftCorner.x + x, _bottomLeftCorner.y + y, _bottomLeftCorner.z}; auto blockId = _dim->getBlock(position); blocksArray.push_back({position, blockId}); } } for (auto [position, id] : blocksArray) { - if (id != Blocks::Air::toProtocol() && id != Blocks::Fire::toProtocol(Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE)) { + if (id != Blocks::Air::toProtocol() && + id != + Blocks::Fire::toProtocol( + Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, Blocks::Fire::Properties::South::FALSE, + Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE + )) { LDEBUG("Obstruction within the frame at position {}: PORTAL_BAD_PORTAL ({})", position, PortalError::PORTAL_BAD_PORTAL); return; } else { @@ -187,15 +219,20 @@ void NetherPortal::openPortal() { } } } else if (_direction == PortalDirection::PORTAL_Z_AXIS) { - for (int z = 0; z <= _size.x ; z++) { - for (int y = 1; y <= _size.z ; y++) { + for (int z = 0; z <= _size.x; z++) { + for (int y = 1; y <= _size.z; y++) { auto position = {_bottomLeftCorner.x, _bottomLeftCorner.y + y, _bottomLeftCorner.z + z}; auto blockId = _dim->getBlock(position); blocksArray.push_back({position, blockId}); } } for (auto [position, id] : blocksArray) { - if (id != Blocks::Air::toProtocol() && id != Blocks::Fire::toProtocol(Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, Blocks::Fire::Properties::South::FALSE, Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE)) { + if (id != Blocks::Air::toProtocol() && + id != + Blocks::Fire::toProtocol( + Blocks::Fire::Properties::Age::ZERO, Blocks::Fire::Properties::East::FALSE, Blocks::Fire::Properties::North::FALSE, Blocks::Fire::Properties::South::FALSE, + Blocks::Fire::Properties::Up::FALSE, Blocks::Fire::Properties::West::FALSE + )) { LDEBUG("Obstruction within the frame at position {}: PORTAL_BAD_PORTAL ({})", position, PortalError::PORTAL_BAD_PORTAL); return; } else { diff --git a/cubic-server/generation/player_constructions/NetherPortal.hpp b/cubic-server/generation/player_constructions/NetherPortal.hpp index 3ac3abc07..d72d7d1e5 100644 --- a/cubic-server/generation/player_constructions/NetherPortal.hpp +++ b/cubic-server/generation/player_constructions/NetherPortal.hpp @@ -1,9 +1,9 @@ #ifndef CUBICSERVER_GENERATION_PLAYER_CONSTRUCTIONS_NETHER_PORTAL_HPP #define CUBICSERVER_GENERATION_PLAYER_CONSTRUCTIONS_NETHER_PORTAL_HPP -#include "math/Vector2.hpp" #include "blocks.hpp" #include "generation/generator.hpp" +#include "math/Vector2.hpp" #include "types.hpp" #include "world_storage/ChunkColumn.hpp" @@ -78,25 +78,27 @@ class NetherPortal { _pos(pos) { setIgnitedBlock(); - setLeftCornerPosition(); + setBottomLeftCorner(); setDirection(); setSize(); } /** - * @brief Sets _ignitedBlock to (TOP_CENTER, LEFT_CENTER, RIGHT_CENTER, BOTTOM_CENTER, TOP_RIGHT_CORNER, TOP_LEFT_CORNER, BOTTOM_RIGHT_CORNER, BOTTOM_LEFT_CORNER, NONE) depending on which side of the alleged frame the ignited block is located + * @brief Sets _ignitedBlock to (TOP_CENTER, LEFT_CENTER, RIGHT_CENTER, BOTTOM_CENTER, TOP_RIGHT_CORNER, TOP_LEFT_CORNER, BOTTOM_RIGHT_CORNER, BOTTOM_LEFT_CORNER, NONE) + * depending on which side of the alleged frame the ignited block is located * */ void setIgnitedBlock(); - + /** - * @brief Sets _bottomLeftCorner to the position of the leftmost obsidian block on the bottom side of the portal, from the inner part of the portal (the corner block, if obsidian, isn't taken into account) + * @brief Sets _bottomLeftCorner to the position of the leftmost obsidian block on the bottom side of the portal, from the inner part of the portal + * (the corner block, if obsidian, isn't taken into account) * */ void setBottomLeftCorner(); /** - * @brief Sets _direction to the horizontal direction of the portal, meaning if the portal is positionned on the X or Z axis, and whether the coordinates are positives or negatives (POS_X, NEG_X, POS_Z, NEG_Z) (atm, only works when lighting a bottom block) + * @brief Sets _direction to the horizontal direction of the portal, meaning if the portal is positionned on the X or Z axis * */ void setDirection();