diff options
author | paly2 <plangrognet@laposte.net> | 2016-07-10 15:15:43 +0200 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2016-09-08 03:26:52 -0400 |
commit | aa33166386f737f213f1f3005ffd6a6adfd2d97f (patch) | |
tree | 6ddbec97ff34fd231a7cb23e70d1dc7dce6049cb /src/nodedef.cpp | |
parent | 7eacdc7bb8ec8f8b06b5e0b2464af219e623cd56 (diff) | |
download | minetest-aa33166386f737f213f1f3005ffd6a6adfd2d97f.tar.gz minetest-aa33166386f737f213f1f3005ffd6a6adfd2d97f.tar.bz2 minetest-aa33166386f737f213f1f3005ffd6a6adfd2d97f.zip |
Add minetest.unregister_item and minetest.register_alias_force
Diffstat (limited to 'src/nodedef.cpp')
-rw-r--r-- | src/nodedef.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 646375575..bfb2999bd 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -778,6 +778,7 @@ public: content_t allocateId(); virtual content_t set(const std::string &name, const ContentFeatures &def); virtual content_t allocateDummy(const std::string &name); + virtual void removeNode(const std::string &name); virtual void updateAliases(IItemDefManager *idef); virtual void applyTextureOverrides(const std::string &override_filepath); virtual void updateTextures(IGameDef *gamedef, @@ -1072,6 +1073,40 @@ content_t CNodeDefManager::allocateDummy(const std::string &name) } +void CNodeDefManager::removeNode(const std::string &name) +{ + // Pre-condition + assert(name != ""); + + // Erase name from name ID mapping + content_t id = CONTENT_IGNORE; + if (m_name_id_mapping.getId(name, id)) { + m_name_id_mapping.eraseName(name); + m_name_id_mapping_with_aliases.erase(name); + } + + // Erase node content from all groups it belongs to + for (std::map<std::string, GroupItems>::iterator iter_groups = + m_group_to_items.begin(); + iter_groups != m_group_to_items.end();) { + GroupItems &items = iter_groups->second; + for (GroupItems::iterator iter_groupitems = items.begin(); + iter_groupitems != items.end();) { + if (iter_groupitems->first == id) + items.erase(iter_groupitems++); + else + iter_groupitems++; + } + + // Check if group is empty + if (items.size() == 0) + m_group_to_items.erase(iter_groups++); + else + iter_groups++; + } +} + + void CNodeDefManager::updateAliases(IItemDefManager *idef) { std::set<std::string> all = idef->getAll(); |