Skip to content

Commit

Permalink
fix extended blocks solidity & fix extended blocks neighbours update
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Oct 22, 2024
1 parent d943319 commit 6bd6c5f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/content/ContentBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ std::unique_ptr<Content> 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());
Expand Down
35 changes: 33 additions & 2 deletions src/logic/BlocksController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand All @@ -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(
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/logic/BlocksController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class BlocksController {
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);
Expand Down

0 comments on commit 6bd6c5f

Please sign in to comment.