From a69152669337cd1e35b53c1330a629a553a8eaf9 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Tue, 5 Dec 2023 11:39:59 +0300 Subject: [PATCH] Pane place direction fixed --- src/logic/PlayerController.cpp | 31 +++++++++++++++++++++++-------- src/voxels/Block.cpp | 4 ++-- src/voxels/Block.h | 1 + src/voxels/voxel.h | 5 +++++ 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/logic/PlayerController.cpp b/src/logic/PlayerController.cpp index 46d6675e..fd877b3d 100644 --- a/src/logic/PlayerController.cpp +++ b/src/logic/PlayerController.cpp @@ -27,6 +27,7 @@ const float CROUCH_SHIFT_Y = -0.2f; using glm::vec2; using glm::vec3; +using std::string; CameraControl::CameraControl(Player* player, const CameraSettings& settings) : player(player), @@ -218,14 +219,28 @@ void PlayerController::updateInteraction(){ int z = (int)iend.z; uint8_t states = 0; - if (contentIds->getBlockDef(player->choosenBlock)->rotatable){ - if (abs(norm.x) > abs(norm.z)){ - if (abs(norm.x) > abs(norm.y)) states = BLOCK_DIR_X; - if (abs(norm.x) < abs(norm.y)) states = BLOCK_DIR_Y; - } - if (abs(norm.x) < abs(norm.z)){ - if (abs(norm.z) > abs(norm.y)) states = BLOCK_DIR_Z; - if (abs(norm.z) < abs(norm.y)) states = BLOCK_DIR_Y; + Block* def = contentIds->getBlockDef(player->choosenBlock); + if (def->rotatable){ + const string& name = def->rotations.name; + if (name == "pipe") { + if (abs(norm.x) > abs(norm.z)){ + if (abs(norm.x) > abs(norm.y)) states = BLOCK_DIR_X; + if (abs(norm.x) < abs(norm.y)) states = BLOCK_DIR_Y; + } + if (abs(norm.x) < abs(norm.z)){ + if (abs(norm.z) > abs(norm.y)) states = BLOCK_DIR_Z; + if (abs(norm.z) < abs(norm.y)) states = BLOCK_DIR_Y; + } + } else if (name == "pane") { + vec3 vec = camera->dir; + if (abs(vec.x) > abs(vec.z)){ + if (vec.x > 0.0f) states = BLOCK_DIR_EAST; + if (vec.x < 0.0f) states = BLOCK_DIR_WEST; + } + if (abs(vec.x) < abs(vec.z)){ + if (vec.z > 0.0f) states = BLOCK_DIR_SOUTH; + if (vec.z < 0.0f) states = BLOCK_DIR_NORTH; + } } } diff --git a/src/voxels/Block.cpp b/src/voxels/Block.cpp index f8c6594f..aa9203a7 100644 --- a/src/voxels/Block.cpp +++ b/src/voxels/Block.cpp @@ -12,7 +12,7 @@ void CoordSystem::transform(AABB& aabb) { aabb.b += fix2; } -const BlockRotProfile BlockRotProfile::PIPE {{ +const BlockRotProfile BlockRotProfile::PIPE {"pipe", { // Vertical {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {0, 0, 0}, {0, 0, 0}}, // X-Aligned @@ -21,7 +21,7 @@ const BlockRotProfile BlockRotProfile::PIPE {{ {{1, 0, 0}, {0, 0, 1}, {0, -1, 0}, {0, 0, -1}, {0, 1, 0}}, }}; -const BlockRotProfile BlockRotProfile::PANE {{ +const BlockRotProfile BlockRotProfile::PANE {"pane", { // North {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {0, 0, 0}, {0, 0, 0}}, // East diff --git a/src/voxels/Block.h b/src/voxels/Block.h index c250b89e..565bc43b 100644 --- a/src/voxels/Block.h +++ b/src/voxels/Block.h @@ -29,6 +29,7 @@ struct CoordSystem { struct BlockRotProfile { static const int MAX_COUNT = 16; + std::string name; CoordSystem variants[MAX_COUNT]; /* Wood logs, pillars, pipes */ diff --git a/src/voxels/voxel.h b/src/voxels/voxel.h index 65fe32db..502cfc58 100644 --- a/src/voxels/voxel.h +++ b/src/voxels/voxel.h @@ -7,6 +7,11 @@ const int BLOCK_DIR_X = 0x1; const int BLOCK_DIR_Y = 0x0; const int BLOCK_DIR_Z = 0x2; +const int BLOCK_DIR_NORTH = 0x0; +const int BLOCK_DIR_WEST = 0x1; +const int BLOCK_DIR_SOUTH = 0x2; +const int BLOCK_DIR_EAST = 0x3; + // limited to 16 block orientations const int BLOCK_ROT_MASK = 0xF;