mirror of
https://github.com/minetest/minetest.git
synced 2024-12-24 15:12:23 +01:00
Set fallback content if resolving content vector requires everything
This commit is contained in:
parent
b67f37f27e
commit
08d259cf41
@ -248,7 +248,7 @@ bool Schematic::loadSchematicFromFile(const char *filename,
|
||||
nri->nodenames.push_back(name);
|
||||
}
|
||||
|
||||
nri->nodename_sizes.push_back(nidmapcount);
|
||||
nri->nodelistinfo.push_back(NodeListInfo(nidmapcount, CONTENT_AIR));
|
||||
ndef->pendNodeResolve(nri);
|
||||
|
||||
size_t nodecount = size.X * size.Y * size.Z;
|
||||
|
@ -1308,8 +1308,7 @@ bool CNodeDefManager::getIdFromResolveInfo(NodeResolveInfo *nri,
|
||||
{
|
||||
if (nri->nodenames.empty()) {
|
||||
result = c_fallback;
|
||||
errorstream << "CNodeDefManager::getIdFromResolveInfo: empty "
|
||||
"nodenames list" << std::endl;
|
||||
errorstream << "Resolver empty nodename list" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1324,8 +1323,8 @@ bool CNodeDefManager::getIdFromResolveInfo(NodeResolveInfo *nri,
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
errorstream << "CNodeDefManager::getIdFromResolveInfo: Failed to "
|
||||
"resolve node name '" << name << "'." << std::endl;
|
||||
errorstream << "Resolver: Failed to resolve node name '" << name
|
||||
<< "'." << std::endl;
|
||||
c = c_fallback;
|
||||
}
|
||||
|
||||
@ -1337,31 +1336,35 @@ bool CNodeDefManager::getIdFromResolveInfo(NodeResolveInfo *nri,
|
||||
bool CNodeDefManager::getIdsFromResolveInfo(NodeResolveInfo *nri,
|
||||
std::vector<content_t> &result)
|
||||
{
|
||||
if (nri->nodename_sizes.empty()) {
|
||||
errorstream << "CNodeDefManager::getIdsFromResolveInfo: empty "
|
||||
"nodename_sizes list" << std::endl;
|
||||
bool success = true;
|
||||
|
||||
if (nri->nodelistinfo.empty()) {
|
||||
errorstream << "Resolver: Empty nodelistinfo list" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t nitems = nri->nodename_sizes.front();
|
||||
nri->nodename_sizes.pop_front();
|
||||
NodeListInfo listinfo = nri->nodelistinfo.front();
|
||||
nri->nodelistinfo.pop_front();
|
||||
|
||||
while (nitems--) {
|
||||
while (listinfo.length--) {
|
||||
if (nri->nodenames.empty()) {
|
||||
errorstream << "" << std::endl;
|
||||
errorstream << "Resolver: Empty nodename list" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
content_t c;
|
||||
if (getId(nri->nodenames.front(), c)) {
|
||||
result.push_back(c);
|
||||
} else {
|
||||
errorstream << "CNodeDefManager::getIdsFromResolveInfo: empty "
|
||||
"nodenames list" << std::endl;
|
||||
}
|
||||
|
||||
std::string name = nri->nodenames.front();
|
||||
nri->nodenames.pop_front();
|
||||
|
||||
if (getId(name, c)) {
|
||||
result.push_back(c);
|
||||
} else if (listinfo.all_required) {
|
||||
errorstream << "Resolver: Failed to resolve node name '" << name
|
||||
<< "'." << std::endl;
|
||||
result.push_back(listinfo.c_fallback);
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return success;
|
||||
}
|
||||
|
@ -285,6 +285,26 @@ struct ContentFeatures
|
||||
class NodeResolver;
|
||||
class INodeDefManager;
|
||||
|
||||
struct NodeListInfo {
|
||||
NodeListInfo(u32 len)
|
||||
{
|
||||
length = len;
|
||||
all_required = false;
|
||||
c_fallback = CONTENT_IGNORE;
|
||||
}
|
||||
|
||||
NodeListInfo(u32 len, content_t fallback)
|
||||
{
|
||||
length = len;
|
||||
all_required = true;
|
||||
c_fallback = fallback;
|
||||
}
|
||||
|
||||
u32 length;
|
||||
bool all_required;
|
||||
content_t c_fallback;
|
||||
};
|
||||
|
||||
struct NodeResolveInfo {
|
||||
NodeResolveInfo(NodeResolver *nr)
|
||||
{
|
||||
@ -292,7 +312,7 @@ struct NodeResolveInfo {
|
||||
}
|
||||
|
||||
std::list<std::string> nodenames;
|
||||
std::list<size_t> nodename_sizes;
|
||||
std::list<NodeListInfo> nodelistinfo;
|
||||
NodeResolver *resolver;
|
||||
};
|
||||
|
||||
|
@ -508,7 +508,7 @@ int ModApiMapgen::l_register_decoration(lua_State *L)
|
||||
//// Get node name(s) to place decoration on
|
||||
std::vector<const char *> place_on_names;
|
||||
getstringlistfield(L, index, "place_on", place_on_names);
|
||||
nri->nodename_sizes.push_back(place_on_names.size());
|
||||
nri->nodelistinfo.push_back(NodeListInfo(place_on_names.size()));
|
||||
for (size_t i = 0; i != place_on_names.size(); i++)
|
||||
nri->nodenames.push_back(place_on_names[i]);
|
||||
|
||||
@ -585,7 +585,7 @@ bool ModApiMapgen::regDecoSimple(lua_State *L,
|
||||
"defined" << std::endl;
|
||||
return false;
|
||||
}
|
||||
nri->nodename_sizes.push_back(deco_names.size());
|
||||
nri->nodelistinfo.push_back(NodeListInfo(deco_names.size()));
|
||||
for (size_t i = 0; i != deco_names.size(); i++)
|
||||
nri->nodenames.push_back(deco_names[i]);
|
||||
|
||||
@ -596,7 +596,7 @@ bool ModApiMapgen::regDecoSimple(lua_State *L,
|
||||
" but num_spawn_by specified" << std::endl;
|
||||
return false;
|
||||
}
|
||||
nri->nodename_sizes.push_back(spawnby_names.size());
|
||||
nri->nodelistinfo.push_back(NodeListInfo(spawnby_names.size()));
|
||||
for (size_t i = 0; i != spawnby_names.size(); i++)
|
||||
nri->nodenames.push_back(spawnby_names[i]);
|
||||
|
||||
@ -691,7 +691,7 @@ int ModApiMapgen::l_register_ore(lua_State *L)
|
||||
|
||||
std::vector<const char *> wherein_names;
|
||||
getstringlistfield(L, index, "wherein", wherein_names);
|
||||
nri->nodename_sizes.push_back(wherein_names.size());
|
||||
nri->nodelistinfo.push_back(NodeListInfo(wherein_names.size()));
|
||||
for (size_t i = 0; i != wherein_names.size(); i++)
|
||||
nri->nodenames.push_back(wherein_names[i]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user