mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Make INodeDefManager::getIds return a vector, not a set
This commit is contained in:
parent
5b3fbf9cf7
commit
17fd5fe935
7 changed files with 64 additions and 83 deletions
|
@ -108,7 +108,7 @@ void ScriptApiEnv::initializeEnvironment(ServerEnvironment *env)
|
|||
int id = lua_tonumber(L, -2);
|
||||
int current_abm = lua_gettop(L);
|
||||
|
||||
std::set<std::string> trigger_contents;
|
||||
std::vector<std::string> trigger_contents;
|
||||
lua_getfield(L, current_abm, "nodenames");
|
||||
if (lua_istable(L, -1)) {
|
||||
int table = lua_gettop(L);
|
||||
|
@ -116,16 +116,16 @@ void ScriptApiEnv::initializeEnvironment(ServerEnvironment *env)
|
|||
while (lua_next(L, table)) {
|
||||
// key at index -2 and value at index -1
|
||||
luaL_checktype(L, -1, LUA_TSTRING);
|
||||
trigger_contents.insert(lua_tostring(L, -1));
|
||||
trigger_contents.push_back(lua_tostring(L, -1));
|
||||
// removes value, keeps key for next iteration
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
} else if (lua_isstring(L, -1)) {
|
||||
trigger_contents.insert(lua_tostring(L, -1));
|
||||
trigger_contents.push_back(lua_tostring(L, -1));
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
|
||||
std::set<std::string> required_neighbors;
|
||||
std::vector<std::string> required_neighbors;
|
||||
lua_getfield(L, current_abm, "neighbors");
|
||||
if (lua_istable(L, -1)) {
|
||||
int table = lua_gettop(L);
|
||||
|
@ -133,12 +133,12 @@ void ScriptApiEnv::initializeEnvironment(ServerEnvironment *env)
|
|||
while (lua_next(L, table)) {
|
||||
// key at index -2 and value at index -1
|
||||
luaL_checktype(L, -1, LUA_TSTRING);
|
||||
required_neighbors.insert(lua_tostring(L, -1));
|
||||
required_neighbors.push_back(lua_tostring(L, -1));
|
||||
// removes value, keeps key for next iteration
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
} else if (lua_isstring(L, -1)) {
|
||||
required_neighbors.insert(lua_tostring(L, -1));
|
||||
required_neighbors.push_back(lua_tostring(L, -1));
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
|
||||
|
|
|
@ -719,7 +719,7 @@ int ModApiEnvMod::l_find_node_near(lua_State *L)
|
|||
INodeDefManager *ndef = getGameDef(L)->ndef();
|
||||
v3s16 pos = read_v3s16(L, 1);
|
||||
int radius = luaL_checkinteger(L, 2);
|
||||
std::set<content_t> filter;
|
||||
std::vector<content_t> filter;
|
||||
if (lua_istable(L, 3)) {
|
||||
lua_pushnil(L);
|
||||
while (lua_next(L, 3) != 0) {
|
||||
|
@ -748,7 +748,7 @@ int ModApiEnvMod::l_find_node_near(lua_State *L)
|
|||
for (const v3s16 &i : list) {
|
||||
v3s16 p = pos + i;
|
||||
content_t c = env->getMap().getNodeNoEx(p).getContent();
|
||||
if (filter.count(c) != 0) {
|
||||
if (CONTAINS(filter, c)) {
|
||||
push_v3s16(L, p);
|
||||
return 1;
|
||||
}
|
||||
|
@ -780,7 +780,7 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
std::set<content_t> filter;
|
||||
std::vector<content_t> filter;
|
||||
if (lua_istable(L, 3)) {
|
||||
lua_pushnil(L);
|
||||
while (lua_next(L, 3) != 0) {
|
||||
|
@ -794,7 +794,8 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L)
|
|||
ndef->getIds(lua_tostring(L, 3), filter);
|
||||
}
|
||||
|
||||
std::unordered_map<content_t, u32> individual_count;
|
||||
std::vector<u32> individual_count;
|
||||
individual_count.resize(filter.size());
|
||||
|
||||
lua_newtable(L);
|
||||
u64 i = 0;
|
||||
|
@ -803,16 +804,20 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L)
|
|||
for (s16 z = minp.Z; z <= maxp.Z; z++) {
|
||||
v3s16 p(x, y, z);
|
||||
content_t c = env->getMap().getNodeNoEx(p).getContent();
|
||||
if (filter.count(c) != 0) {
|
||||
|
||||
std::vector<content_t>::iterator it = std::find(filter.begin(), filter.end(), c);
|
||||
if (it != filter.end()) {
|
||||
push_v3s16(L, p);
|
||||
lua_rawseti(L, -2, ++i);
|
||||
individual_count[c]++;
|
||||
|
||||
u32 filt_index = it - filter.begin();
|
||||
individual_count[filt_index]++;
|
||||
}
|
||||
}
|
||||
lua_newtable(L);
|
||||
for (content_t it : filter) {
|
||||
lua_pushnumber(L, individual_count[it]);
|
||||
lua_setfield(L, -2, ndef->get(it).name.c_str());
|
||||
for (u32 i = 0; i < filter.size(); i++) {
|
||||
lua_pushnumber(L, individual_count[i]);
|
||||
lua_setfield(L, -2, ndef->get(filter[i]).name.c_str());
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
@ -847,7 +852,7 @@ int ModApiEnvMod::l_find_nodes_in_area_under_air(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
std::set<content_t> filter;
|
||||
std::vector<content_t> filter;
|
||||
|
||||
if (lua_istable(L, 3)) {
|
||||
lua_pushnil(L);
|
||||
|
@ -873,7 +878,7 @@ int ModApiEnvMod::l_find_nodes_in_area_under_air(lua_State *L)
|
|||
v3s16 psurf(x, y + 1, z);
|
||||
content_t csurf = env->getMap().getNodeNoEx(psurf).getContent();
|
||||
if (c != CONTENT_AIR && csurf == CONTENT_AIR &&
|
||||
filter.count(c) != 0) {
|
||||
CONTAINS(filter, c)) {
|
||||
push_v3s16(L, v3s16(x, y, z));
|
||||
lua_rawseti(L, -2, ++i);
|
||||
}
|
||||
|
|
|
@ -188,15 +188,15 @@ class LuaABM : public ActiveBlockModifier {
|
|||
private:
|
||||
int m_id;
|
||||
|
||||
std::set<std::string> m_trigger_contents;
|
||||
std::set<std::string> m_required_neighbors;
|
||||
std::vector<std::string> m_trigger_contents;
|
||||
std::vector<std::string> m_required_neighbors;
|
||||
float m_trigger_interval;
|
||||
u32 m_trigger_chance;
|
||||
bool m_simple_catch_up;
|
||||
public:
|
||||
LuaABM(lua_State *L, int id,
|
||||
const std::set<std::string> &trigger_contents,
|
||||
const std::set<std::string> &required_neighbors,
|
||||
const std::vector<std::string> &trigger_contents,
|
||||
const std::vector<std::string> &required_neighbors,
|
||||
float trigger_interval, u32 trigger_chance, bool simple_catch_up):
|
||||
m_id(id),
|
||||
m_trigger_contents(trigger_contents),
|
||||
|
@ -206,11 +206,11 @@ public:
|
|||
m_simple_catch_up(simple_catch_up)
|
||||
{
|
||||
}
|
||||
virtual const std::set<std::string> &getTriggerContents() const
|
||||
virtual const std::vector<std::string> &getTriggerContents() const
|
||||
{
|
||||
return m_trigger_contents;
|
||||
}
|
||||
virtual const std::set<std::string> &getRequiredNeighbors() const
|
||||
virtual const std::vector<std::string> &getRequiredNeighbors() const
|
||||
{
|
||||
return m_required_neighbors;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue