This commit is contained in:
Julian Heinzel 2024-04-17 18:54:57 +10:00 committed by GitHub
commit 91df347723
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 32 additions and 0 deletions

View File

@ -136,6 +136,19 @@ void ObjDefManager::clear()
}
void ObjDefManager::clearByName(const std::string &name)
{
for (auto it = m_objects.begin(); it != m_objects.end(); ++it) {
auto obj = *it;
if (obj && !strcasecmp(name.c_str(), obj->name.c_str())) {
delete obj;
m_objects.erase(it);
break;
}
}
}
u32 ObjDefManager::validateHandle(ObjDefHandle handle) const
{
ObjDefType type;

View File

@ -78,6 +78,7 @@ public:
virtual const char *getObjectTitle() const { return "ObjDef"; }
virtual void clear();
virtual void clearByName(const std::string &name);
virtual ObjDef *getByName(const std::string &name) const;
//// Add new/get/set object definitions by handle

View File

@ -1526,6 +1526,20 @@ int ModApiMapgen::l_clear_registered_decorations(lua_State *L)
}
// clear_decoration(name)
int ModApiMapgen::l_clear_decoration(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
luaL_checktype(L, 1, LUA_TSTRING);
const char *name = lua_tostring(L, 1);
DecorationManager *dmgr =
getServer(L)->getEmergeManager()->getWritableDecorationManager();
dmgr->clearByName(name);
return 0;
}
// clear_registered_ores()
int ModApiMapgen::l_clear_registered_ores(lua_State *L)
{
@ -2027,6 +2041,7 @@ void ModApiMapgen::Initialize(lua_State *L, int top)
API_FCT(clear_registered_biomes);
API_FCT(clear_registered_decorations);
API_FCT(clear_decoration);
API_FCT(clear_registered_ores);
API_FCT(clear_registered_schematics);

View File

@ -123,6 +123,9 @@ private:
// clear_registered_decorations()
static int l_clear_registered_decorations(lua_State *L);
// clear_decoration()
static int l_clear_decoration(lua_State *L);
// clear_registered_schematics()
static int l_clear_registered_schematics(lua_State *L);