From 4c8ae465c78367e6ce05c870994b17c354fc16a7 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 10 Jul 2024 09:14:24 +0300 Subject: [PATCH] add 'grounded' support for 'pipe' rotation profile --- res/content/base/blocks/torch.json | 1 + src/logic/BlocksController.cpp | 9 ++++++--- src/logic/PlayerController.cpp | 7 +++++-- src/voxels/Block.hpp | 9 +++++++++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/res/content/base/blocks/torch.json b/res/content/base/blocks/torch.json index 2a914a94..7b0605b7 100644 --- a/res/content/base/blocks/torch.json +++ b/res/content/base/blocks/torch.json @@ -13,5 +13,6 @@ "light-passing": true, "shadeless": true, "obstacle": false, + "grounded": true, "rotation": "pipe" } diff --git a/src/logic/BlocksController.cpp b/src/logic/BlocksController.cpp index 4748e7e3..d517ff44 100644 --- a/src/logic/BlocksController.cpp +++ b/src/logic/BlocksController.cpp @@ -84,9 +84,12 @@ void BlocksController::updateBlock(int x, int y, int z) { if (vox == nullptr) return; const Block* def = level->content->getIndices()->getBlockDef(vox->id); - if (def->grounded && !chunks->isSolidBlock(x, y-1, z)) { - breakBlock(nullptr, def, x, y, z); - return; + if (def->grounded) { + const auto& vec = get_ground_direction(def, vox->state.rotation); + if (!chunks->isSolidBlock(x+vec.x, y+vec.y, z+vec.z)) { + breakBlock(nullptr, def, x, y, z); + return; + } } if (def->rt.funcsset.update) { scripting::update_block(def, x, y, z); diff --git a/src/logic/PlayerController.cpp b/src/logic/PlayerController.cpp index baa8748e..f630e0de 100644 --- a/src/logic/PlayerController.cpp +++ b/src/logic/PlayerController.cpp @@ -404,8 +404,11 @@ void PlayerController::processRightClick(Block* def, Block* target) { if (!chunks->checkReplaceability(def, state, coord)) { return; } - if (def->grounded && !chunks->isSolidBlock(coord.x, coord.y-1, coord.z)) { - return; + if (def->grounded) { + const auto& vec = get_ground_direction(def, state.rotation); + if (!chunks->isSolidBlock(coord.x+vec.x, coord.y+vec.y, coord.z+vec.z)) { + return; + } } if (chosenBlock != vox->id && chosenBlock) { onBlockInteraction(coord, def, BlockInteraction::placing); diff --git a/src/voxels/Block.hpp b/src/voxels/Block.hpp index 90ae2f6a..89b905d1 100644 --- a/src/voxels/Block.hpp +++ b/src/voxels/Block.hpp @@ -202,4 +202,13 @@ public: Block(const Block&) = delete; }; +inline glm::ivec3 get_ground_direction(const Block* def, int rotation) { + const auto& profileName = def->rotations.name; + if (profileName == BlockRotProfile::PIPE_NAME) { + return -def->rotations.variants[rotation].axisY; + } else { + return glm::ivec3(0, -1, 0); + } +} + #endif // VOXELS_BLOCK_HPP_