// IWritableNodeDefManager content_t NodeDefManager::set(const std::string &name, const ContentFeatures &def) { // Pre-conditions assert(name != ""); assert(name != "ignore"); assert(name == def.name); content_t id = CONTENT_IGNORE; if (!m_name_id_mapping.getId(name, id)) { // ignore aliases // Get new id id = allocateId(); if (id == CONTENT_IGNORE) { warningstream << "NodeDefManager: Absolute " "limit reached" << std::endl; return CONTENT_IGNORE; } assert(id != CONTENT_IGNORE); addNameIdMapping(id, name); } m_content_features[id] = def; verbosestream << "NodeDefManager: registering content id \"" << id << "\": name=\"" << def.name << "\""<<std::endl; getNodeBoxUnion(def.selection_box, def, &m_selection_box_union); fixSelectionBoxIntUnion(); // Add this content to the list of all groups it belongs to // FIXME: This should remove a node from groups it no longer // belongs to when a node is re-registered for (const auto &group : def.groups) { const std::string &group_name = group.first; m_group_to_items[group_name].push_back(id); } return id; }
void CNodeDefManager::deSerialize(std::istream &is) { clear(); int version = readU8(is); if (version != 1) throw SerializationError("unsupported NodeDefinitionManager version"); u16 count = readU16(is); std::istringstream is2(deSerializeLongString(is), std::ios::binary); ContentFeatures f; for (u16 n = 0; n < count; n++) { u16 i = readU16(is2); // Read it from the string wrapper std::string wrapper = deSerializeString(is2); std::istringstream wrapper_is(wrapper, std::ios::binary); f.deSerialize(wrapper_is); // Check error conditions if (i == CONTENT_IGNORE || i == CONTENT_AIR || i == CONTENT_UNKNOWN) { warningstream << "NodeDefManager::deSerialize(): " "not changing builtin node " << i << std::endl; continue; } if (f.name.empty()) { warningstream << "NodeDefManager::deSerialize(): " "received empty name" << std::endl; continue; } // Ignore aliases u16 existing_id; if (m_name_id_mapping.getId(f.name, existing_id) && i != existing_id) { warningstream << "NodeDefManager::deSerialize(): " "already defined with different ID: " << f.name << std::endl; continue; } // All is ok, add node definition with the requested ID if (i >= m_content_features.size()) m_content_features.resize((u32)(i) + 1); m_content_features[i] = f; addNameIdMapping(i, f.name); verbosestream << "deserialized " << f.name << std::endl; getNodeBoxUnion(f.selection_box, f, &m_selection_box_union); fixSelectionBoxIntUnion(); } }