Skip to content

Instantly share code, notes, and snippets.

@sofar
Created January 12, 2016 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sofar/2d12d56ef35a1f6c78d0 to your computer and use it in GitHub Desktop.
Save sofar/2d12d56ef35a1f6c78d0 to your computer and use it in GitHub Desktop.
diff --git a/src/nodedef.cpp b/src/nodedef.cpp
index fb90320..70db165 100644
--- a/src/nodedef.cpp
+++ b/src/nodedef.cpp
@@ -389,6 +389,8 @@ void ContentFeatures::reset()
sound_footstep = SimpleSoundSpec();
sound_dig = SimpleSoundSpec("__group");
sound_dug = SimpleSoundSpec();
+ connects_to.clear();
+ connects_to_ids.clear();
}
void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const
@@ -455,6 +457,10 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const
os<<serializeString(mesh);
collision_box.serialize(os, protocol_version);
writeU8(os, floodable);
+ writeU8(os, connects_to_ids.size());
+ for(std::set<content_t>::const_iterator i = connects_to_ids.begin();
+ i != connects_to_ids.end(); i++)
+ writeU16(os, *i);
}
void ContentFeatures::deSerialize(std::istream &is)
@@ -526,6 +532,9 @@ void ContentFeatures::deSerialize(std::istream &is)
mesh = deSerializeString(is);
collision_box.deSerialize(is);
floodable = readU8(is);
+ u32 connects_to_size = readU8(is);
+ for (u32 i = 0; i < connects_to_size; i++)
+ connects_to_ids.insert(readU16(is));
}catch(SerializationError &e) {};
}
@@ -563,6 +572,7 @@ class CNodeDefManager: public IWritableNodeDefManager {
virtual bool cancelNodeResolveCallback(NodeResolver *nr);
virtual void runNodeResolveCallbacks();
virtual void resetNodeResolveState();
+ virtual void mapNodeboxConnections();
private:
void addNameIdMapping(content_t i, std::string name);
@@ -1569,7 +1579,22 @@ void CNodeDefManager::resetNodeResolveState()
m_pending_resolve_callbacks.clear();
}
-
+void CNodeDefManager::mapNodeboxConnections()
+{
+ for (u32 i = 0; i < m_content_features.size(); i++) {
+ ContentFeatures *f = &m_content_features[i];
+ if ((f->drawtype != NDT_NODEBOX) && (f->node_box.type != NODEBOX_CONNECTED))
+ continue;
+ for (std::set<std::string>::iterator it = f->connects_to.begin();
+ it != f->connects_to.end(); it++) {
+ std::set<content_t> ids;
+ getIds(*it, ids);
+ for (std::set<content_t>::iterator k = ids.begin();
+ k != ids.end(); k++)
+ f->connects_to_ids.insert(*k);
+ }
+ }
+}
////
//// NodeResolver
////
diff --git a/src/nodedef.h b/src/nodedef.h
index 9e14c73..e83e297 100644
--- a/src/nodedef.h
+++ b/src/nodedef.h
@@ -277,6 +277,9 @@ struct ContentFeatures
SimpleSoundSpec sound_dig;
SimpleSoundSpec sound_dug;
+ std::vector<std::string> connects_to;
+ std::set<content_t> connects_to_ids;
+
/*
Methods
*/
@@ -375,6 +378,7 @@ class IWritableNodeDefManager : public INodeDefManager {
virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
virtual void runNodeResolveCallbacks()=0;
virtual void resetNodeResolveState()=0;
+ virtual void mapNodeboxConnections()=0;
};
IWritableNodeDefManager *createNodeDefManager();
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index 84b02f8..8f942c9 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -515,6 +515,20 @@ ContentFeatures read_content_features(lua_State *L, int index)
f.node_box = read_nodebox(L, -1);
lua_pop(L, 1);
+ lua_getfield(L, index, "connects_to");
+ if (lua_istable(L, -1)) {
+ int table = lua_gettop(L);
+ lua_pushnil(L);
+ int i = 0;
+ while (lua_next(L, table) != 0) {
+ // Value at -1
+ f.connects_to.push_back(lua_tostring(L, -1));
+ lua_pop(L, 1);
+ i++;
+ }
+ }
+ lua_pop(L, 1);
+
lua_getfield(L, index, "selection_box");
if(lua_istable(L, -1))
f.selection_box = read_nodebox(L, -1);
diff --git a/src/server.cpp b/src/server.cpp
index 8609605..698dab9 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -320,6 +320,9 @@ Server::Server(
// Perform pending node name resolutions
m_nodedef->runNodeResolveCallbacks();
+ // unmap node names for connected nodeboxes
+ m_nodedef->mapNodeboxConnections();
+
// init the recipe hashes to speed up crafting
m_craftdef->initHashes(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment