node.lua 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. ---@meta
  2. ---Nodes
  3. --------
  4. -- `param1` and `param2` are 8-bit integers ranging from 0 to 255. The engine uses
  5. -- them for certain automated functions. If you don't use these functions, you can
  6. -- use them to store arbitrary values.
  7. ---@alias mt.NodeParam integer
  8. ---Nodes are the bulk data of the world: cubes and other things that take the
  9. ---space of a cube. Huge amounts of them are handled efficiently, but they
  10. ---are quite static.
  11. ---
  12. ---The definition of a node is stored and can be accessed by using
  13. ---
  14. --- minetest.registered_nodes[node.name]
  15. ---
  16. ---Nodes are passed by value between Lua and the engine.
  17. ---They are represented by a table:
  18. ---
  19. --- {name="name", param1=num, param2=num}
  20. ---@class mt.Node
  21. ---@field name string
  22. ---@field param1 mt.NodeParam
  23. ---@field param2 mt.NodeParam
  24. local node = {}
  25. ---@class mt.MapNode:mt.Node
  26. -- (alias `param1`): the probability of this node being placed (default: 255).
  27. --
  28. -- * A probability value of `0` or `1` means that node will never appear
  29. -- (0% chance).
  30. -- * A probability value of `254` or `255` means the node will always appear
  31. -- (100% chance).
  32. -- * If the probability value `p` is greater than `1`, then there is a
  33. -- `(p / 256 * 100)` percent chance that node will appear when the schematic is
  34. -- placed on the map.
  35. ---@field prob integer
  36. -- Representing if the node should forcibly overwrite any previous contents (default: false).
  37. ---@field force_place boolean
  38. ---Node paramtypes
  39. ------------------
  40. ---The functions of `param1` and `param2` are determined by certain fields in the
  41. ---node definition.
  42. ---
  43. ---The function of `param1` is determined by `paramtype` in node definition.
  44. ---`param1` is reserved for the engine when `paramtype != "none"`.
  45. ---@alias mt.ParamType
  46. ---* The value stores light with and without sun in its lower and upper 4 bits
  47. --- respectively.
  48. ---* Required by a light source node to enable spreading its light.
  49. ---* Required by the following drawtypes as they determine their visual
  50. --- brightness from their internal light value:
  51. --- * torchlike
  52. --- * signlike
  53. --- * firelike
  54. --- * fencelike
  55. --- * raillike
  56. --- * nodebox
  57. --- * mesh
  58. --- * plantlike
  59. --- * plantlike_rooted
  60. ---|"light"
  61. ---* `param1` will not be used by the engine and can be used to store
  62. --- an arbitrary value
  63. ---|"none"
  64. ---The function of `param2` is determined by `paramtype2` in node definition.
  65. ---`param2` is reserved for the engine when `paramtype2 != "none"`.
  66. ---@alias mt.ParamType2
  67. ---* Used by `drawtype = "flowingliquid"` and `liquidtype = "flowing"`
  68. ---* The liquid level and a flag of the liquid are stored in `param2`
  69. ---* Bits 0-2: Liquid level (0-7). The higher, the more liquid is in this node;
  70. --- see `minetest.get_node_level`, `minetest.set_node_level` and `minetest.add_node_level`
  71. --- to access/manipulate the content of this field
  72. ---* Bit 3: If set, liquid is flowing downwards (no graphical effect)
  73. ---|"flowingliquid"
  74. ---* Supported drawtypes: "torchlike", "signlike", "plantlike",
  75. --- "plantlike_rooted", "normal", "nodebox", "mesh"
  76. ---* The rotation of the node is stored in `param2`
  77. ---* Node is 'mounted'/facing towards one of 6 directions
  78. ---* You can make this value by using `minetest.dir_to_wallmounted()`
  79. ---* Values range 0 - 5
  80. ---* The value denotes at which direction the node is "mounted":
  81. --- `0 = y+, 1 = y-, 2 = x+, 3 = x-, 4 = z+, 5 = z-`
  82. ---* By default, on placement the param2 is automatically set to the
  83. --- appropriate rotation, depending on which side was pointed at
  84. ---|"wallmounted"
  85. ---* Supported drawtypes: "normal", "nodebox", "mesh"
  86. ---* The rotation of the node is stored in `param2`.
  87. ---* Node is rotated around face and axis; 24 rotations in total.
  88. ---* Can be made by using `minetest.dir_to_facedir()`.
  89. ---* Chests and furnaces can be rotated that way, and also 'flipped'
  90. ---* Values range 0 - 23
  91. ---* facedir / 4 = axis direction:
  92. --- 0 = y+, 1 = z+, 2 = z-, 3 = x+, 4 = x-, 5 = y-
  93. ---* The node is rotated 90 degrees around the X or Z axis so that its top face
  94. --- points in the desired direction. For the y- direction, it's rotated 180
  95. --- degrees around the Z axis.
  96. ---* facedir modulo 4 = left-handed rotation around the specified axis, in 90° steps.
  97. ---* By default, on placement the param2 is automatically set to the
  98. --- horizontal direction the player was looking at (values 0-3)
  99. ---* Special case: If the node is a connected nodebox, the nodebox
  100. --- will NOT rotate, only the textures will.
  101. ---|"facedir"
  102. ---* Supported drawtypes: "normal", "nodebox", "mesh"
  103. ---* The rotation of the node is stored in `param2`.
  104. ---* Allows node to be rotated horizontally, 4 rotations in total
  105. ---* Can be made by using `minetest.dir_to_fourdir()`.
  106. ---* Chests and furnaces can be rotated that way, but not flipped
  107. ---* Values range 0 - 3
  108. ---* 4dir modulo 4 = rotation
  109. ---* Otherwise, behavior is identical to facedir
  110. ---|"4dir"
  111. ---* Only valid for "nodebox" with 'type = "leveled"', and "plantlike_rooted".
  112. --- * Leveled nodebox:
  113. --- * The level of the top face of the nodebox is stored in `param2`.
  114. --- * The other faces are defined by 'fixed = {}' like 'type = "fixed"'
  115. --- nodeboxes.
  116. --- * The nodebox height is (`param2` / 64) nodes.
  117. --- * The maximum accepted value of `param2` is 127.
  118. --- * Rooted plantlike:
  119. --- * The height of the 'plantlike' section is stored in `param2`.
  120. --- * The height is (`param2` / 16) nodes.
  121. ---|"leveled"
  122. ---* Valid for `plantlike` and `mesh` drawtypes. The rotation of the node is
  123. --- stored in `param2`.
  124. ---* Values range 0–239. The value stored in `param2` is multiplied by 1.5 to
  125. --- get the actual rotation in degrees of the node.
  126. ---|"degrotate"
  127. ---* Only valid for "plantlike" drawtype. `param2` encodes the shape and
  128. --- optional modifiers of the "plant". `param2` is a bitfield.
  129. ---* Bits 0 to 2 select the shape. Use only one of the values below:
  130. --- * 0 = an "x" shaped plant (ordinary plant)
  131. --- * 1 = a "+" shaped plant (just rotated 45 degrees)
  132. --- * 2 = a "*" shaped plant with 3 faces instead of 2
  133. --- * 3 = a "#" shaped plant with 4 faces instead of 2
  134. --- * 4 = a "#" shaped plant with 4 faces that lean outwards
  135. --- * 5-7 are unused and reserved for future meshes.
  136. ---* Bits 3 to 7 are used to enable any number of optional modifiers.
  137. --- Just add the corresponding value(s) below to `param2`:
  138. --- * 8 - Makes the plant slightly vary placement horizontally
  139. --- * 16 - Makes the plant mesh 1.4x larger
  140. --- * 32 - Moves each face randomly a small bit down (1/8 max)
  141. --- * values 64 and 128 (bits 6-7) are reserved for future use.
  142. ---* Example: `param2 = 0` selects a normal "x" shaped plant
  143. ---* Example: `param2 = 17` selects a "+" shaped plant, 1.4x larger (1+16)
  144. ---|"meshoptions"
  145. ---* `param2` tells which color is picked from the palette.
  146. --- The palette should have 256 pixels.
  147. ---|"color"
  148. ---* Same as `facedir`, but with colors.
  149. ---* The first three bits of `param2` tells which color is picked from the
  150. --- palette. The palette should have 8 pixels.
  151. ---|"colorfacedir"
  152. ---* Same as `facedir`, but with colors.
  153. ---* The first six bits of `param2` tells which color is picked from the
  154. --- palette. The palette should have 64 pixels.
  155. ---|"color4dir"
  156. ---* Same as `wallmounted`, but with colors.
  157. ---* The first five bits of `param2` tells which color is picked from the
  158. --- palette. The palette should have 32 pixels.
  159. ---|"colorwallmounted"
  160. ---* Only valid for "glasslike_framed" or "glasslike_framed_optional"
  161. --- drawtypes. "glasslike_framed_optional" nodes are only affected if the
  162. --- "Connected Glass" setting is enabled.
  163. ---* Bits 0-5 define 64 levels of internal liquid, 0 being empty and 63 being
  164. --- full.
  165. ---* Bits 6 and 7 modify the appearance of the frame and node faces. One or
  166. --- both of these values may be added to `param2`:
  167. --- * 64 - Makes the node not connect with neighbors above or below it.
  168. --- * 128 - Makes the node not connect with neighbors to its sides.
  169. ---* Liquid texture is defined using `special_tiles = {"modname_tilename.png"}`
  170. ---|"glasslikeliquidlevel"
  171. ---* Same as `degrotate`, but with colors.
  172. ---* The first (most-significant) three bits of `param2` tells which color
  173. --- is picked from the palette. The palette should have 8 pixels.
  174. ---* Remaining 5 bits store rotation in range 0–23 (i.e. in 15° steps)
  175. ---|"colordegrotate"
  176. ---* `param2` will not be used by the engine and can be used to store
  177. --- an arbitrary value
  178. ---|"none"
  179. ---Node drawtypes
  180. -----------------
  181. ---There are a bunch of different looking node types.
  182. ---
  183. ---Look for examples in `games/devtest` or `games/minetest_game`.
  184. ---
  185. ---`*_optional` drawtypes need less rendering time if deactivated.
  186. ---(always client-side).
  187. ---@alias mt.DrawType string
  188. ---* A node-sized cube.
  189. ---|"normal"
  190. ---* Invisible, uses no texture.
  191. ---|"airlike"
  192. ---* The cubic source node for a liquid.
  193. ---* Faces bordering to the same node are never rendered.
  194. ---* Connects to node specified in `liquid_alternative_flowing`.
  195. ---* You *must* set `liquid_alternative_source` to the node's own name.
  196. ---* Use `backface_culling = false` for the tiles you want to make
  197. --- visible when inside the node.
  198. ---|"liquid"
  199. ---* The flowing version of a liquid, appears with various heights and slopes.
  200. ---* Faces bordering to the same node are never rendered.
  201. ---* Connects to node specified in `liquid_alternative_source`.
  202. ---* You *must* set `liquid_alternative_flowing` to the node's own name.
  203. ---* Node textures are defined with `special_tiles` where the first tile
  204. --- is for the top and bottom faces and the second tile is for the side
  205. --- faces.
  206. ---* `tiles` is used for the item/inventory/wield image rendering.
  207. ---* Use `backface_culling = false` for the special tiles you want to make
  208. --- visible when inside the node
  209. ---|"flowingliquid"
  210. ---* Often used for partially-transparent nodes.
  211. ---* Only external sides of textures are visible.
  212. ---|"glasslike"
  213. ---* All face-connected nodes are drawn as one volume within a surrounding
  214. --- frame.
  215. ---* The frame appearance is generated from the edges of the first texture
  216. --- specified in `tiles`. The width of the edges used are 1/16th of texture
  217. --- size: 1 pixel for 16x16, 2 pixels for 32x32 etc.
  218. ---* The glass 'shine' (or other desired detail) on each node face is supplied
  219. --- by the second texture specified in `tiles`.
  220. ---|"glasslike_framed"
  221. ---* This switches between the above 2 drawtypes according to the menu setting
  222. --- 'Connected Glass'.
  223. ---|"glasslike_framed_optional"
  224. ---* Often used for partially-transparent nodes.
  225. ---* External and internal sides of textures are visible.
  226. ---|"allfaces"
  227. ---* Often used for leaves nodes.
  228. ---* This switches between `normal`, `glasslike` and `allfaces` according to
  229. --- the menu setting: Opaque Leaves / Simple Leaves / Fancy Leaves.
  230. ---* With 'Simple Leaves' selected, the texture specified in `special_tiles`
  231. --- is used instead, if present. This allows a visually thicker texture to be
  232. --- used to compensate for how `glasslike` reduces visual thickness.
  233. ---|"allfaces_optional"
  234. ---* A single vertical texture.
  235. ---* If `paramtype2="[color]wallmounted"`:
  236. --- * If placed on top of a node, uses the first texture specified in `tiles`.
  237. --- * If placed against the underside of a node, uses the second texture
  238. --- specified in `tiles`.
  239. --- * If placed on the side of a node, uses the third texture specified in
  240. --- `tiles` and is perpendicular to that node.
  241. ---* If `paramtype2="none"`:
  242. --- * Will be rendered as if placed on top of a node (see
  243. --- above) and only the first texture is used.
  244. ---|"torchlike"
  245. ---* A single texture parallel to, and mounted against, the top, underside or
  246. --- side of a node.
  247. ---* If `paramtype2="[color]wallmounted"`, it rotates according to `param2`
  248. ---* If `paramtype2="none"`, it will always be on the floor.
  249. ---|"signlike"
  250. ---* Two vertical and diagonal textures at right-angles to each other.
  251. ---* See `paramtype2 = "meshoptions"` above for other options.
  252. ---|"plantlike"
  253. ---* When above a flat surface, appears as 6 textures, the central 2 as
  254. --- `plantlike` plus 4 more surrounding those.
  255. ---* If not above a surface the central 2 do not appear, but the texture
  256. --- appears against the faces of surrounding nodes if they are present.
  257. ---|"firelike"
  258. ---* A 3D model suitable for a wooden fence.
  259. ---* One placed node appears as a single vertical post.
  260. ---* Adjacently-placed nodes cause horizontal bars to appear between them.
  261. ---|"fencelike"
  262. ---* Often used for tracks for mining carts.
  263. ---* Requires 4 textures to be specified in `tiles`, in order: Straight,
  264. --- curved, t-junction, crossing.
  265. ---* Each placed node automatically switches to a suitable rotated texture
  266. --- determined by the adjacent `raillike` nodes, in order to create a
  267. --- continuous track network.
  268. ---* Becomes a sloping node if placed against stepped nodes.
  269. ---|"raillike"
  270. ---* Often used for stairs and slabs.
  271. ---* Allows defining nodes consisting of an arbitrary number of boxes.
  272. ---* See [Node boxes] below for more information.
  273. ---|"nodebox"
  274. ---* Uses models for nodes.
  275. ---* Tiles should hold model materials textures.
  276. ---* Only static meshes are implemented.
  277. ---* For supported model formats see Irrlicht engine documentation.
  278. ---|"mesh"
  279. ---* Enables underwater `plantlike` without air bubbles around the nodes.
  280. ---* Consists of a base cube at the co-ordinates of the node plus a
  281. --- `plantlike` extension above
  282. ---* If `paramtype2="leveled", the `plantlike` extension has a height
  283. --- of `param2 / 16` nodes, otherwise it's the height of 1 node
  284. ---* If `paramtype2="wallmounted"`, the `plantlike` extension
  285. --- will be at one of the corresponding 6 sides of the base cube.
  286. --- Also, the base cube rotates like a `normal` cube would
  287. ---* The `plantlike` extension visually passes through any nodes above the
  288. --- base cube without affecting them.
  289. ---* The base cube texture tiles are defined as normal, the `plantlike`
  290. --- extension uses the defined special tile, for example:
  291. --- `special_tiles = {{name = "default_papyrus.png"}},`
  292. ---|"plantlike_rooted"
  293. ---Node boxes
  294. -------------
  295. ---Node selection boxes are defined using "node boxes".
  296. ---
  297. ---A nodebox is defined as any of:
  298. ---
  299. --- {
  300. --- -- A normal cube; the default in most things
  301. --- type = "regular"
  302. --- }
  303. --- {
  304. --- -- A fixed box (or boxes) (facedir param2 is used, if applicable)
  305. --- type = "fixed",
  306. --- fixed = box OR {box1, box2, ...}
  307. --- }
  308. --- {
  309. --- -- A variable height box (or boxes) with the top face position defined
  310. --- -- by the node parameter 'leveled = ', or if 'paramtype2 == "leveled"'
  311. --- -- by param2.
  312. --- -- Other faces are defined by 'fixed = {}' as with 'type = "fixed"'.
  313. --- type = "leveled",
  314. --- fixed = box OR {box1, box2, ...}
  315. --- }
  316. --- {
  317. --- -- A box like the selection box for torches
  318. --- -- (wallmounted param2 is used, if applicable)
  319. --- type = "wallmounted",
  320. --- wall_top = box,
  321. --- wall_bottom = box,
  322. --- wall_side = box
  323. --- }
  324. --- {
  325. --- -- A node that has optional boxes depending on neighboring nodes'
  326. --- -- presence and type. See also `connects_to`.
  327. --- type = "connected",
  328. --- fixed = box OR {box1, box2, ...}
  329. --- connect_top = box OR {box1, box2, ...}
  330. --- connect_bottom = box OR {box1, box2, ...}
  331. --- connect_front = box OR {box1, box2, ...}
  332. --- connect_left = box OR {box1, box2, ...}
  333. --- connect_back = box OR {box1, box2, ...}
  334. --- connect_right = box OR {box1, box2, ...}
  335. --- -- The following `disconnected_*` boxes are the opposites of the
  336. --- -- `connect_*` ones above, i.e. when a node has no suitable neighbor
  337. --- -- on the respective side, the corresponding disconnected box is drawn.
  338. --- disconnected_top = box OR {box1, box2, ...}
  339. --- disconnected_bottom = box OR {box1, box2, ...}
  340. --- disconnected_front = box OR {box1, box2, ...}
  341. --- disconnected_left = box OR {box1, box2, ...}
  342. --- disconnected_back = box OR {box1, box2, ...}
  343. --- disconnected_right = box OR {box1, box2, ...}
  344. --- disconnected = box OR {box1, box2, ...} -- when there is *no* neighbor
  345. --- disconnected_sides = box OR {box1, box2, ...} -- when there are *no*
  346. --- -- neighbors to the sides
  347. --- }
  348. ---
  349. ---A `box` is defined as:
  350. ---
  351. --- {x1, y1, z1, x2, y2, z2}
  352. ---
  353. ---A box of a regular node would look like:
  354. ---
  355. --- {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
  356. ---
  357. ---To avoid collision issues, keep each value within the range of +/- 1.45.
  358. ---This also applies to leveled nodeboxes, where the final height shall not
  359. ---exceed this soft limit.
  360. ---@class mt.NodeBox
  361. ---@field type mt.ParamType2|"regular"|"fixed"|"connected"
  362. ---@field fixed mt.NodeBox|mt.NodeBox[]
  363. ---@field wall_top mt.NodeBox
  364. ---@field wall_bottom mt.NodeBox
  365. ---@field wall_side mt.NodeBox
  366. ---@field connect_top mt.NodeBox|mt.NodeBox[]
  367. ---@field connect_bottom mt.NodeBox|mt.NodeBox[]
  368. ---@field connect_front mt.NodeBox|mt.NodeBox[]
  369. ---@field connect_left mt.NodeBox|mt.NodeBox[]
  370. ---@field connect_back mt.NodeBox|mt.NodeBox[]
  371. ---@field connect_right mt.NodeBox|mt.NodeBox[]
  372. ---@field disconnect_top mt.NodeBox|mt.NodeBox[]
  373. ---@field disconnect_bottom mt.NodeBox|mt.NodeBox[]
  374. ---@field disconnect_front mt.NodeBox|mt.NodeBox[]
  375. ---@field disconnect_left mt.NodeBox|mt.NodeBox[]
  376. ---@field disconnect_back mt.NodeBox|mt.NodeBox[]
  377. ---@field disconnect_right mt.NodeBox|mt.NodeBox[]
  378. ---@field disconnected_sides mt.NodeBox|mt.NodeBox[]
  379. ---@field [1] number x1
  380. ---@field [2] number y1
  381. ---@field [3] number z1
  382. ---@field [4] number x2
  383. ---@field [5] number y2
  384. ---@field [6] number z2
  385. local box = {}
  386. ---A 'mapblock' (often abbreviated to 'block') is 16x16x16 nodes and is the
  387. ---fundamental region of a world that is stored in the world database, sent to
  388. ---clients and handled by many parts of the engine.
  389. ---'mapblock' is preferred terminology to 'block' to help avoid confusion with
  390. ---'node', however 'block' often appears in the API.
  391. ---@alias mt.MapBlock table
  392. ---A 'mapchunk' (sometimes abbreviated to 'chunk') is usually 5x5x5 mapblocks
  393. ---(80x80x80 nodes) and is the volume of world generated in one operation by
  394. ---the map generator.
  395. ---The size in mapblocks has been chosen to optimize map generation.
  396. ---@alias mt.MapChunk table