From b217c902c4e0369ad148ceaf1cffaf95360a1db6 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Tue, 22 Oct 2024 08:06:26 +0300 Subject: [PATCH] fix extended blocks solidity & fix extended blocks neighbours update --- src/content/ContentBuilder.cpp | 5 +++++ src/logic/BlocksController.cpp | 35 ++++++++++++++++++++++++++++++++-- src/logic/BlocksController.hpp | 1 + 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/content/ContentBuilder.cpp b/src/content/ContentBuilder.cpp index 30e65911..4290312d 100644 --- a/src/content/ContentBuilder.cpp +++ b/src/content/ContentBuilder.cpp @@ -31,6 +31,11 @@ std::unique_ptr ContentBuilder::build() { def.rt.solid = def.model == BlockModel::block; def.rt.extended = def.size.x > 1 || def.size.y > 1 || def.size.z > 1; + const float EPSILON = 0.01f; + if (def.rt.extended && glm::i8vec3(def.hitboxes[0].size() + EPSILON) == def.size) { + def.rt.solid = true; + } + if (def.rotatable) { for (uint i = 0; i < BlockRotProfile::MAX_COUNT; i++) { def.rt.hitboxes[i].reserve(def.hitboxes.size()); diff --git a/src/logic/BlocksController.cpp b/src/logic/BlocksController.cpp index f8a716d0..45095fcb 100644 --- a/src/logic/BlocksController.cpp +++ b/src/logic/BlocksController.cpp @@ -33,6 +33,29 @@ void BlocksController::updateSides(int x, int y, int z) { updateBlock(x, y, z + 1); } +void BlocksController::updateSides(int x, int y, int z, int w, int h, int d) { + voxel* vox = chunks->get(x, y, z); + const auto& def = level->content->getIndices()->blocks.require(vox->id); + const auto& rot = def.rotations.variants[vox->state.rotation]; + const auto& xaxis = rot.axisX; + const auto& yaxis = rot.axisY; + const auto& zaxis = rot.axisZ; + for (int ly = -1; ly <= h; ly++) { + for (int lz = -1; lz <= d; lz++) { + for (int lx = -1; lx <= w; lx++) { + if (lx >= 0 && lx < w && ly >= 0 && ly < h && lz >= 0 && lz < d) { + continue; + } + updateBlock( + x + lx * xaxis.x + ly * yaxis.x + lz * zaxis.x, + y + lx * xaxis.y + ly * yaxis.y + lz * zaxis.y, + z + lx * xaxis.z + ly * yaxis.z + lz * zaxis.z + ); + } + } + } +} + void BlocksController::breakBlock( Player* player, const Block& def, int x, int y, int z ) { @@ -42,7 +65,11 @@ void BlocksController::breakBlock( chunks->set(x, y, z, 0, {}); lighting->onBlockSet(x, y, z, 0); scripting::on_block_broken(player, def, x, y, z); - updateSides(x, y, z); + if (def.rt.extended) { + updateSides(x, y, z , def.size.x, def.size.y, def.size.z); + } else { + updateSides(x, y, z); + } } void BlocksController::placeBlock( @@ -56,7 +83,11 @@ void BlocksController::placeBlock( if (def.rt.funcsset.onplaced) { scripting::on_block_placed(player, def, x, y, z); } - updateSides(x, y, z); + if (def.rt.extended) { + updateSides(x, y, z , def.size.x, def.size.y, def.size.z); + } else { + updateSides(x, y, z); + } } void BlocksController::updateBlock(int x, int y, int z) { diff --git a/src/logic/BlocksController.hpp b/src/logic/BlocksController.hpp index 1754ced3..19a270f0 100644 --- a/src/logic/BlocksController.hpp +++ b/src/logic/BlocksController.hpp @@ -37,6 +37,7 @@ public: BlocksController(Level* level, uint padding); void updateSides(int x, int y, int z); + void updateSides(int x, int y, int z, int w, int h, int d); void updateBlock(int x, int y, int z); void breakBlock(Player* player, const Block& def, int x, int y, int z);