add block.properties, item.properties (experimental)

This commit is contained in:
MihailRis
2024-11-22 11:08:36 +03:00
parent b40c8c4b4c
commit cd630463b3
4 changed files with 31 additions and 0 deletions
+24
View File
@@ -157,10 +157,26 @@ void scripting::process_post_runnables() {
}
}
template <class T>
static int push_properties_tables(
lua::State* L, const ContentUnitIndices<T>& indices
) {
const auto units = indices.getDefs();
size_t size = indices.count();
lua::createtable(L, size, 0);
for (size_t i = 0; i < size; i++) {
lua::pushvalue(L, units[i]->properties);
lua::rawseti(L, i);
}
return 1;
}
void scripting::on_content_load(Content* content) {
scripting::content = content;
scripting::indices = content->getIndices();
const auto& indices = *content->getIndices();
auto L = lua::get_main_state();
if (lua::getglobal(L, "block")) {
const auto& materials = content->getBlockMaterials();
@@ -170,6 +186,14 @@ void scripting::on_content_load(Content* content) {
lua::setfield(L, name);
}
lua::setfield(L, "materials");
push_properties_tables(L, indices.blocks);
lua::setfield(L, "properties");
lua::pop(L);
}
if (lua::getglobal(L, "item")) {
push_properties_tables(L, indices.blocks);
lua::setfield(L, "properties");
lua::pop(L);
}
}