Hey, people. What about actually explaining nodeboxes instead of pointing to 3rd party tools right from the beginning? ;-)
Okay, I explain nodeboxes (hopefully I do it right!):
The drawtype nodebox is an experimental (=may change in future!) drawtype for nodes.
To use nodeboxes for your node, set drawtype to “nodebox”.
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Then, to actually use a nodebox, you also have to set the parameter “node_box”. This parameter must have a table. The format of the table is a bit tricky.
First, this table has a “type” key. Possible types of nodeboxes are: regular, fixed and leveled and wallmounted.
A regular nodebox is defined as this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
The node will be drawn as a simple 1×1×1 cube, nothing exiting. This is all to say for regular nodeboxes.
Nodeboxes of the “fixed” type are much more interesting. Such a nodebox is defined by one or more little cuboids. You get to define the coordinates of two of the cornes of each cuboid, basically the lower and upper bounds of the cubiod.
The center of the node has the coordinates 0,0,0. And a node has the size of 1×1×1.
So, a regular 1×1×1 cube would have the coordinates from -0.5 to 0.5 for the X, Y and Z axis. The result would be the same as for normal nodes or for regular nodeboxes.
To define the coordinates for a single cuboid, you have to use a “box” table of the format:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
x1, y1, z1 are the lower coordinates, x2, y2, z2 the higher ones.
The set of all cuboids you want to use has to be in assigned to the “fixed” parameter of the node_box definition.
To assign a nodebox the coordinates of a single cuboid, you have to use this node_box definition:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
node_box = { type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5} }
This nodebox is for a simple cube.
Now I give you a more interesting example: slabs. If you think about it, a slab is basically a cube which has been cut. The upper half of it has been removed. So we care about the Y axis.
So we can take the cube definition from about and simple set the upper Y bound to 0, since 0 is where the center is. This is how slabs are defined in minetest_game:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}
}
Now maybe you want to use more than 1 cubiod. In this case, the “fixed” parameter must be a
table of “box” tables.
Now think of stairs. It is impossible to create stairs with just a single cuboid. You need at least two. But think about it: It is not much more complicated than a slab. You can take the slab box and put another slab right above it. And then you just cut the upper slab box in half, along the Z axis.
Minetest_game defines stairs this way:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0, 0.5},
{-0.5, 0, 0, 0.5, 0.5, 0.5},
},
},
Note that the first box is EXACTLY the same as the slab box. The second one is which is interesting here: Look how it starts at Y=0, this is needed to place it on top of the slab. And it starts at Z=0, which is the “cutting it in half”.
Also note the parameter “fixed” here is a table of box tables. If you use more than one box, you have to use this style.
I hope you now got the basic idea. Theoretically, you could put as many boxes into the fixed table as you want but please don’t overdo it, for performance reasons.
Fixed nodeboxes can be much more complex than stairs. There are also fences, tables, stairs, bee hives. All this stuff is made by nodeboxes. You may want to read other people’s code and see how they did it.
But remember, you can only use cuboids. Also keep in mind those cubioids are always aligned to the three axes. You can’t just rotate a box by, let’s say, 30°, for example.
There are also the nodebox types “leveled” and “wallmounted”, but I don’t fully understand those. But I think you now know the most important stuff. :)