Merge pull request #592 from MihailRis/fix-custom-model-blocks-particles

Fix custom model blocks particles
This commit is contained in:
MihailRis 2025-08-21 00:16:46 +03:00 committed by GitHub
commit 17f3e03ea9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 2 deletions

View File

@ -1,6 +1,11 @@
function on_block_broken(id, x, y, z, playerid)
if gfx then
gfx.particles.emit({x+0.5, y+0.5, z+0.5}, 64, {
local size = {block.get_size(id)}
gfx.particles.emit({
x + size[1] * 0.5,
y + size[1] * 0.5,
z + size[1] * 0.5
}, 64, {
lifetime=1.0,
spawn_interval=0.0001,
explosion={4, 4, 4},
@ -8,7 +13,7 @@ function on_block_broken(id, x, y, z, playerid)
random_sub_uv=0.1,
size={0.1, 0.1, 0.1},
spawn_shape="box",
spawn_spread={0.4, 0.4, 0.4}
spawn_spread=vec3.mul(size, 0.4)
})
end

View File

@ -6,6 +6,7 @@
#include "voxels/Block.hpp"
#include "content/Content.hpp"
#include "debug/Logger.hpp"
#include "core_defs.hpp"
static debug::Logger logger("models-generator");
@ -67,11 +68,18 @@ void ModelsGenerator::prepareModel(
} else {
auto srcModel = assets.get<model::Model>(blockModel.name);
if (srcModel) {
bool defaultAssigned = variant.textureFaces[0] != TEXTURE_NOTFOUND;
auto model = std::make_unique<model::Model>(*srcModel);
for (auto& mesh : model->meshes) {
if (mesh.texture.length() && mesh.texture[0] == '$') {
int index = std::stoll(mesh.texture.substr(1));
mesh.texture = "blocks:" + variant.textureFaces[index];
} else if (!defaultAssigned && !mesh.texture.empty()) {
size_t sepPos = mesh.texture.find(':');
if (sepPos == std::string::npos)
continue;
variant.textureFaces[0] = mesh.texture.substr(sepPos + 1);
defaultAssigned = true;
}
}
blockModel.name = modelName;