summaryrefslogtreecommitdiff
path: root/src/content_mapblock.cpp
diff options
context:
space:
mode:
authorAuke Kok <sofar@foo-projects.org>2016-02-25 00:16:31 -0800
committerShadowNinja <shadowninja@minetest.net>2016-03-12 12:08:17 -0500
commite737b1c271c9d957651ef2201bb820e4465358bf (patch)
tree7779672fec61fe09df3fd5391d64ae84bd8e572a /src/content_mapblock.cpp
parent8c951cae5bcfa715e227d47d122cc2de45d70a63 (diff)
downloadminetest-e737b1c271c9d957651ef2201bb820e4465358bf.tar.gz
minetest-e737b1c271c9d957651ef2201bb820e4465358bf.tar.bz2
minetest-e737b1c271c9d957651ef2201bb820e4465358bf.zip
Nodebox: Allow nodeboxes to "connect"
We introduce a new nodebox type "connected", and allow these nodes to have optional nodeboxes that connect it to other connecting nodeboxes. This is all done at scenedraw time in the client. The client will inspect the surrounding nodes and if they are to be connected to, it will draw the appropriate connecting nodeboxes to make those connections. In the node_box definition, we have to specify separate nodeboxes for each valid connection. This allows us to make nodes that connect only horizontally (the common case) by providing optional nodeboxes for +x, -x, +z, -z directions. Or this allows us to make wires that can connect up and down, by providing nodeboxes that connect it up and down (+y, -y) as well. The optional nodeboxes can be arrays. They are named "connect_top, "connect_bottom", "connect_front", "connect_left", "connect_back" and "connect_right". Here, "front" means the south facing side of the node that has facedir = 0. Additionally, a "fixed" nodebox list present will always be drawn, so one can make a central post, for instance. This "fixed" nodebox can be omitted, or it can be an array of nodeboxes. Collision boxes are also updated in exactly the same fashion, which allows you to walk over the upper extremities of the individual node boxes, or stand really close to them. You can also walk up node noxes that are small in height, all as expected, and unlike the NDT_FENCELIKE nodes. I've posted a screenshot demonstrating the flexibility at http://i.imgur.com/zaJq8jo.png In the screenshot, all connecting nodes are of this new subtype. Transparent textures render incorrectly, Which I don't think is related to this text, as other nodeboxes also have issues with this. A protocol bump is performed in order to be able to send older clients a nodeblock that is usable for them. In order to avoid abuse of users we send older clients a "full-size" node, so that it's impossible for them to try and walk through a fence or wall that's created in this fashion. This was tested with a pre-bump client connected against a server running the new protocol. These nodes connect to other nodes, and you can select which ones those are by specifying node names (or group names) in the connects_to string array: connects_to = { "group:fence", "default:wood" } By default, nodes do not connect to anything, allowing you to create nodes that always have to be paired in order to connect. lua_api.txt is updated to reflect the extension to the node_box API. Example lua code needed to generate these nodes can be found here: https://gist.github.com/sofar/b381c8c192c8e53e6062
Diffstat (limited to 'src/content_mapblock.cpp')
-rw-r--r--src/content_mapblock.cpp41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/content_mapblock.cpp b/src/content_mapblock.cpp
index c15b9c424..c2934f26a 100644
--- a/src/content_mapblock.cpp
+++ b/src/content_mapblock.cpp
@@ -163,6 +163,14 @@ void makeCuboid(MeshCollector *collector, const aabb3f &box,
}
}
+static inline void getNeighborConnectingFace(v3s16 p, INodeDefManager *nodedef,
+ MeshMakeData *data, MapNode n, int v, int *neighbors)
+{
+ MapNode n2 = data->m_vmanip.getNodeNoEx(p);
+ if (nodedef->nodeboxConnects(n, n2))
+ *neighbors |= v;
+}
+
/*
TODO: Fix alpha blending for special nodes
Currently only the last element rendered is blended correct
@@ -1501,7 +1509,38 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
v3f pos = intToFloat(p, BS);
- std::vector<aabb3f> boxes = n.getNodeBoxes(nodedef);
+ int neighbors = 0;
+
+ // locate possible neighboring nodes to connect to
+ if (f.node_box.type == NODEBOX_CONNECTED) {
+ v3s16 p2 = p;
+
+ p2.Y++;
+ getNeighborConnectingFace(blockpos_nodes + p2, nodedef, data, n, 1, &neighbors);
+
+ p2 = p;
+ p2.Y--;
+ getNeighborConnectingFace(blockpos_nodes + p2, nodedef, data, n, 2, &neighbors);
+
+ p2 = p;
+ p2.Z--;
+ getNeighborConnectingFace(blockpos_nodes + p2, nodedef, data, n, 4, &neighbors);
+
+ p2 = p;
+ p2.X--;
+ getNeighborConnectingFace(blockpos_nodes + p2, nodedef, data, n, 8, &neighbors);
+
+ p2 = p;
+ p2.Z++;
+ getNeighborConnectingFace(blockpos_nodes + p2, nodedef, data, n, 16, &neighbors);
+
+ p2 = p;
+ p2.X++;
+ getNeighborConnectingFace(blockpos_nodes + p2, nodedef, data, n, 32, &neighbors);
+ }
+
+ std::vector<aabb3f> boxes;
+ n.getNodeBoxes(nodedef, &boxes, neighbors);
for(std::vector<aabb3f>::iterator
i = boxes.begin();
i != boxes.end(); ++i)