add block.get_textures

This commit is contained in:
MihailRis 2024-07-03 05:15:15 +03:00
parent 8302bfe98e
commit 1c4e13dc67
3 changed files with 24 additions and 1 deletions

View File

@ -12,7 +12,15 @@ mat4.rotate(rotation, {1, 0, 0}, math.random() * 360, rotation)
mat4.rotate(rotation, {0, 0, 1}, math.random() * 360, rotation) mat4.rotate(rotation, {0, 0, 1}, math.random() * 360, rotation)
rig:set_matrix(0, rotation) rig:set_matrix(0, rotation)
local icon = item.icon(dropitem.id) local icon = item.icon(dropitem.id)
rig:set_texture("$0", icon:gsub("block%-previews", "blocks"):gsub("base%:", "")) if icon:find("^block%-previews%:") then
local bid = block.index(icon:sub(16))
local textures = block.get_textures(bid)
for i,t in ipairs(textures) do
rig:set_texture("$"..tostring(i-1), "blocks:"..textures[i])
end
else
rig:set_texture("$0", icon)
end
function on_grounded(force) function on_grounded(force)
rig:set_matrix(0, mat4.rotate({0, 1, 0}, math.random()*360)) rig:set_matrix(0, mat4.rotate({0, 1, 0}, math.random()*360))

View File

@ -139,6 +139,8 @@ void ModelBatch::setTexture(const std::string& name,
setTexture(atlas->getTexture()); setTexture(atlas->getTexture());
if (auto reg = atlas->getIf(name.substr(sep+1))) { if (auto reg = atlas->getIf(name.substr(sep+1))) {
region = *reg; region = *reg;
} else {
setTexture("blocks:notfound", varTextures);
} }
} }
} }

View File

@ -259,6 +259,18 @@ static int l_caption(lua::State* L) {
return 0; return 0;
} }
static int l_get_textures(lua::State* L) {
if (auto def = require_block(L)) {
lua::createtable(L, 6, 0);
for (size_t i = 0; i < 6; i++) {
lua::pushstring(L, def->textureFaces[i]);
lua::rawseti(L, i+1);
}
return 1;
}
return 0;
}
const luaL_Reg blocklib [] = { const luaL_Reg blocklib [] = {
{"index", lua::wrap<l_index>}, {"index", lua::wrap<l_index>},
{"name", lua::wrap<l_name>}, {"name", lua::wrap<l_name>},
@ -282,5 +294,6 @@ const luaL_Reg blocklib [] = {
{"get_size", lua::wrap<l_get_size>}, {"get_size", lua::wrap<l_get_size>},
{"is_segment", lua::wrap<l_is_segment>}, {"is_segment", lua::wrap<l_is_segment>},
{"seek_origin", lua::wrap<l_seek_origin>}, {"seek_origin", lua::wrap<l_seek_origin>},
{"get_textures", lua::wrap<l_get_textures>},
{NULL, NULL} {NULL, NULL}
}; };