drawtypes.lua 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. --[[ Drawtype Test: This file tests out and provides examples for
  2. all drawtypes in Minetest. It is attempted to keep the node
  3. definitions as simple and minimal as possible to keep
  4. side-effects to a minimum.
  5. How to read the node definitions:
  6. There are two parts which are separated by 2 newlines:
  7. The first part contains the things that are more or less essential
  8. for defining the drawtype (except description, which is
  9. at the top for readability).
  10. The second part (after the 2 newlines) contains stuff that are
  11. unrelated to the drawtype, stuff that is mostly there to make
  12. testing this node easier and more convenient.
  13. ]]
  14. local S = minetest.get_translator("testnodes")
  15. -- A regular cube
  16. minetest.register_node("testnodes:normal", {
  17. description = S("Normal Drawtype Test Node"),
  18. drawtype = "normal",
  19. tiles = { "testnodes_normal.png" },
  20. groups = { dig_immediate = 3 },
  21. })
  22. -- Standard glasslike node
  23. minetest.register_node("testnodes:glasslike", {
  24. description = S("Glasslike Drawtype Test Node"),
  25. drawtype = "glasslike",
  26. paramtype = "light",
  27. tiles = { "testnodes_glasslike.png" },
  28. groups = { dig_immediate = 3 },
  29. })
  30. -- Glasslike framed with the two textures (normal and "detail")
  31. minetest.register_node("testnodes:glasslike_framed", {
  32. description = S("Glasslike Framed Drawtype Test Node"),
  33. drawtype = "glasslike_framed",
  34. paramtype = "light",
  35. tiles = {
  36. "testnodes_glasslike_framed.png",
  37. "testnodes_glasslike_detail.png",
  38. },
  39. sunlight_propagates = true,
  40. groups = { dig_immediate = 3 },
  41. })
  42. -- Like the one above, but without the "detail" texture (texture 2).
  43. -- This node was added to see how the engine behaves when the "detail" texture
  44. -- is missing.
  45. minetest.register_node("testnodes:glasslike_framed_no_detail", {
  46. description = S("Glasslike Framed without Detail Drawtype Test Node"),
  47. drawtype = "glasslike_framed",
  48. paramtype = "light",
  49. tiles = { "testnodes_glasslike_framed2.png" },
  50. sunlight_propagates = true,
  51. groups = { dig_immediate = 3 },
  52. })
  53. minetest.register_node("testnodes:glasslike_framed_optional", {
  54. description = S("Glasslike Framed Optional Drawtype Test Node"),
  55. drawtype = "glasslike_framed_optional",
  56. paramtype = "light",
  57. tiles = {
  58. "testnodes_glasslike_framed_optional.png",
  59. "testnodes_glasslike_detail.png",
  60. },
  61. sunlight_propagates = true,
  62. groups = { dig_immediate = 3 },
  63. })
  64. minetest.register_node("testnodes:allfaces", {
  65. description = S("Allfaces Drawtype Test Node"),
  66. drawtype = "allfaces",
  67. paramtype = "light",
  68. tiles = { "testnodes_allfaces.png" },
  69. groups = { dig_immediate = 3 },
  70. })
  71. minetest.register_node("testnodes:allfaces_optional", {
  72. description = S("Allfaces Optional Drawtype Test Node"),
  73. drawtype = "allfaces_optional",
  74. paramtype = "light",
  75. tiles = { "testnodes_allfaces_optional.png" },
  76. groups = { dig_immediate = 3 },
  77. })
  78. minetest.register_node("testnodes:allfaces_optional_waving", {
  79. description = S("Waving Allfaces Optional Drawtype Test Node"),
  80. drawtype = "allfaces_optional",
  81. paramtype = "light",
  82. tiles = { "testnodes_allfaces_optional.png^[brighten" },
  83. waving = 2,
  84. groups = { dig_immediate = 3 },
  85. })
  86. minetest.register_node("testnodes:firelike", {
  87. description = S("Firelike Drawtype Test Node"),
  88. drawtype = "firelike",
  89. paramtype = "light",
  90. tiles = { "testnodes_firelike.png" },
  91. walkable = false,
  92. groups = { dig_immediate = 3 },
  93. })
  94. minetest.register_node("testnodes:fencelike", {
  95. description = S("Fencelike Drawtype Test Node"),
  96. drawtype = "fencelike",
  97. paramtype = "light",
  98. tiles = { "testnodes_fencelike.png" },
  99. groups = { dig_immediate = 3 },
  100. })
  101. minetest.register_node("testnodes:torchlike", {
  102. description = S("Torchlike Drawtype Test Node"),
  103. drawtype = "torchlike",
  104. paramtype = "light",
  105. tiles = {
  106. "testnodes_torchlike_floor.png",
  107. "testnodes_torchlike_ceiling.png",
  108. "testnodes_torchlike_wall.png",
  109. },
  110. walkable = false,
  111. sunlight_propagates = true,
  112. groups = { dig_immediate = 3 },
  113. })
  114. minetest.register_node("testnodes:torchlike_wallmounted", {
  115. description = S("Wallmounted Torchlike Drawtype Test Node"),
  116. drawtype = "torchlike",
  117. paramtype = "light",
  118. paramtype2 = "wallmounted",
  119. tiles = {
  120. "testnodes_torchlike_floor.png",
  121. "testnodes_torchlike_ceiling.png",
  122. "testnodes_torchlike_wall.png",
  123. },
  124. walkable = false,
  125. sunlight_propagates = true,
  126. groups = { dig_immediate = 3 },
  127. })
  128. minetest.register_node("testnodes:signlike", {
  129. description = S("Wallmounted Signlike Drawtype Test Node"),
  130. drawtype = "signlike",
  131. paramtype = "light",
  132. paramtype2 = "wallmounted",
  133. tiles = { "testnodes_signlike.png" },
  134. walkable = false,
  135. groups = { dig_immediate = 3 },
  136. sunlight_propagates = true,
  137. })
  138. minetest.register_node("testnodes:plantlike", {
  139. description = S("Plantlike Drawtype Test Node"),
  140. drawtype = "plantlike",
  141. paramtype = "light",
  142. tiles = { "testnodes_plantlike.png" },
  143. walkable = false,
  144. sunlight_propagates = true,
  145. groups = { dig_immediate = 3 },
  146. })
  147. minetest.register_node("testnodes:plantlike_waving", {
  148. description = S("Waving Plantlike Drawtype Test Node"),
  149. drawtype = "plantlike",
  150. paramtype = "light",
  151. tiles = { "testnodes_plantlike_waving.png" },
  152. waving = 1,
  153. walkable = false,
  154. sunlight_propagates = true,
  155. groups = { dig_immediate = 3 },
  156. })
  157. -- param2 will rotate
  158. local function rotate_on_rightclick(pos, node, clicker)
  159. local def = minetest.registered_nodes[node.name]
  160. local aux1 = clicker:get_player_control().aux1
  161. local deg, deg_max
  162. local color, color_mult = 0, 0
  163. if def.paramtype2 == "degrotate" then
  164. deg = node.param2
  165. deg_max = 240
  166. elseif def.paramtype2 == "colordegrotate" then
  167. -- MSB [3x color, 5x rotation] LSB
  168. deg = node.param2 % 2^5
  169. deg_max = 24
  170. color_mult = 2^5
  171. color = math.floor(node.param2 / color_mult)
  172. end
  173. deg = (deg + (aux1 and 10 or 1)) % deg_max
  174. node.param2 = color * color_mult + deg
  175. minetest.swap_node(pos, node)
  176. minetest.chat_send_player(clicker:get_player_name(),
  177. "Rotation is now " .. deg .. " / " .. deg_max)
  178. end
  179. minetest.register_node("testnodes:plantlike_degrotate", {
  180. description = S("Degrotate Plantlike Drawtype Test Node"),
  181. drawtype = "plantlike",
  182. paramtype = "light",
  183. paramtype2 = "degrotate",
  184. tiles = { "testnodes_plantlike_degrotate.png" },
  185. on_rightclick = rotate_on_rightclick,
  186. place_param2 = 7,
  187. walkable = false,
  188. sunlight_propagates = true,
  189. groups = { dig_immediate = 3 },
  190. })
  191. minetest.register_node("testnodes:mesh_degrotate", {
  192. description = S("Degrotate Mesh Drawtype Test Node"),
  193. drawtype = "mesh",
  194. paramtype = "light",
  195. paramtype2 = "degrotate",
  196. mesh = "testnodes_pyramid.obj",
  197. tiles = { "testnodes_mesh_stripes2.png" },
  198. on_rightclick = rotate_on_rightclick,
  199. place_param2 = 7,
  200. sunlight_propagates = true,
  201. groups = { dig_immediate = 3 },
  202. })
  203. minetest.register_node("testnodes:mesh_colordegrotate", {
  204. description = S("Color Degrotate Mesh Drawtype Test Node"),
  205. drawtype = "mesh",
  206. paramtype2 = "colordegrotate",
  207. palette = "testnodes_palette_facedir.png",
  208. mesh = "testnodes_pyramid.obj",
  209. tiles = { "testnodes_mesh_stripes2.png" },
  210. on_rightclick = rotate_on_rightclick,
  211. -- color index 1, 7 steps rotated
  212. place_param2 = 1 * 2^5 + 7,
  213. sunlight_propagates = true,
  214. groups = { dig_immediate = 3 },
  215. })
  216. -- param2 will change height
  217. minetest.register_node("testnodes:plantlike_leveled", {
  218. description = S("Leveled Plantlike Drawtype Test Node"),
  219. drawtype = "plantlike",
  220. paramtype = "light",
  221. paramtype2 = "leveled",
  222. tiles = {
  223. { name = "testnodes_plantlike_leveled.png", tileable_vertical = true },
  224. },
  225. -- We set a default param2 here only for convenience, to make the "plant" visible after placement
  226. place_param2 = 8,
  227. walkable = false,
  228. sunlight_propagates = true,
  229. groups = { dig_immediate = 3 },
  230. })
  231. -- param2 changes shape
  232. minetest.register_node("testnodes:plantlike_meshoptions", {
  233. description = S("Meshoptions Plantlike Drawtype Test Node"),
  234. drawtype = "plantlike",
  235. paramtype = "light",
  236. paramtype2 = "meshoptions",
  237. tiles = { "testnodes_plantlike_meshoptions.png" },
  238. walkable = false,
  239. groups = { dig_immediate = 3 },
  240. })
  241. minetest.register_node("testnodes:plantlike_rooted", {
  242. description = S("Rooted Plantlike Drawtype Test Node"),
  243. drawtype = "plantlike_rooted",
  244. paramtype = "light",
  245. tiles = { "testnodes_plantlike_rooted_base.png" },
  246. special_tiles = { "testnodes_plantlike_rooted.png" },
  247. groups = { dig_immediate = 3 },
  248. })
  249. minetest.register_node("testnodes:plantlike_rooted_waving", {
  250. description = S("Waving Rooted Plantlike Drawtype Test Node"),
  251. drawtype = "plantlike_rooted",
  252. paramtype = "light",
  253. tiles = {
  254. "testnodes_plantlike_rooted_base.png",
  255. "testnodes_plantlike_rooted_base.png",
  256. "testnodes_plantlike_rooted_base_side_waving.png",
  257. },
  258. special_tiles = { "testnodes_plantlike_rooted_waving.png" },
  259. waving = 1,
  260. groups = { dig_immediate = 3 },
  261. })
  262. -- param2 changes height
  263. minetest.register_node("testnodes:plantlike_rooted_leveled", {
  264. description = S("Leveled Rooted Plantlike Drawtype Test Node"),
  265. drawtype = "plantlike_rooted",
  266. paramtype = "light",
  267. paramtype2 = "leveled",
  268. tiles = {
  269. "testnodes_plantlike_rooted_base.png",
  270. "testnodes_plantlike_rooted_base.png",
  271. "testnodes_plantlike_rooted_base_side_leveled.png",
  272. },
  273. special_tiles = {
  274. { name = "testnodes_plantlike_rooted_leveled.png", tileable_vertical = true },
  275. },
  276. -- We set a default param2 here only for convenience, to make the "plant" visible after placement
  277. place_param2 = 8,
  278. groups = { dig_immediate = 3 },
  279. })
  280. -- param2 changes shape
  281. minetest.register_node("testnodes:plantlike_rooted_meshoptions", {
  282. description = S("Meshoptions Rooted Plantlike Drawtype Test Node"),
  283. drawtype = "plantlike_rooted",
  284. paramtype = "light",
  285. paramtype2 = "meshoptions",
  286. tiles = {
  287. "testnodes_plantlike_rooted_base.png",
  288. "testnodes_plantlike_rooted_base.png",
  289. "testnodes_plantlike_rooted_base_side_meshoptions.png",
  290. },
  291. special_tiles = {
  292. "testnodes_plantlike_rooted_meshoptions.png",
  293. },
  294. groups = { dig_immediate = 3 },
  295. })
  296. -- param2 changes rotation
  297. minetest.register_node("testnodes:plantlike_rooted_degrotate", {
  298. description = S("Degrotate Rooted Plantlike Drawtype Test Node"),
  299. drawtype = "plantlike_rooted",
  300. paramtype = "light",
  301. paramtype2 = "degrotate",
  302. tiles = {
  303. "testnodes_plantlike_rooted_base.png",
  304. "testnodes_plantlike_rooted_base.png",
  305. "testnodes_plantlike_rooted_base_side_degrotate.png",
  306. },
  307. special_tiles = {
  308. "testnodes_plantlike_rooted_degrotate.png",
  309. },
  310. groups = { dig_immediate = 3 },
  311. })
  312. -- Demonstrative liquid nodes, source and flowing form.
  313. -- DRAWTYPE ONLY, NO LIQUID PHYSICS!
  314. -- Liquid ranges 0 to 8
  315. for r = 0, 8 do
  316. minetest.register_node("testnodes:liquid_"..r, {
  317. description = S("Source Liquid Drawtype Test Node, Range @1", r),
  318. drawtype = "liquid",
  319. paramtype = "light",
  320. tiles = {
  321. "testnodes_liquidsource_r"..r..".png^[colorize:#FFFFFF:100",
  322. },
  323. special_tiles = {
  324. {name="testnodes_liquidsource_r"..r..".png^[colorize:#FFFFFF:100", backface_culling=false},
  325. {name="testnodes_liquidsource_r"..r..".png^[colorize:#FFFFFF:100", backface_culling=true},
  326. },
  327. use_texture_alpha = "blend",
  328. walkable = false,
  329. liquid_range = r,
  330. liquid_viscosity = 0,
  331. liquid_alternative_flowing = "testnodes:liquid_flowing_"..r,
  332. liquid_alternative_source = "testnodes:liquid_"..r,
  333. groups = { dig_immediate = 3 },
  334. })
  335. minetest.register_node("testnodes:liquid_flowing_"..r, {
  336. description = S("Flowing Liquid Drawtype Test Node, Range @1", r),
  337. drawtype = "flowingliquid",
  338. paramtype = "light",
  339. paramtype2 = "flowingliquid",
  340. tiles = {
  341. "testnodes_liquidflowing_r"..r..".png^[colorize:#FFFFFF:100",
  342. },
  343. special_tiles = {
  344. {name="testnodes_liquidflowing_r"..r..".png^[colorize:#FFFFFF:100", backface_culling=false},
  345. {name="testnodes_liquidflowing_r"..r..".png^[colorize:#FFFFFF:100", backface_culling=false},
  346. },
  347. use_texture_alpha = "blend",
  348. walkable = false,
  349. liquid_range = r,
  350. liquid_viscosity = 0,
  351. liquid_alternative_flowing = "testnodes:liquid_flowing_"..r,
  352. liquid_alternative_source = "testnodes:liquid_"..r,
  353. groups = { dig_immediate = 3 },
  354. })
  355. end
  356. -- Waving liquid test (drawtype only)
  357. minetest.register_node("testnodes:liquid_waving", {
  358. description = S("Waving Source Liquid Drawtype Test Node"),
  359. drawtype = "liquid",
  360. paramtype = "light",
  361. tiles = {
  362. "testnodes_liquidsource.png^[colorize:#0000FF:127",
  363. },
  364. special_tiles = {
  365. {name="testnodes_liquidsource.png^[colorize:#0000FF:127", backface_culling=false},
  366. {name="testnodes_liquidsource.png^[colorize:#0000FF:127", backface_culling=true},
  367. },
  368. use_texture_alpha = "blend",
  369. waving = 3,
  370. walkable = false,
  371. liquid_range = 1,
  372. liquid_viscosity = 0,
  373. liquid_alternative_flowing = "testnodes:liquid_flowing_waving",
  374. liquid_alternative_source = "testnodes:liquid_waving",
  375. groups = { dig_immediate = 3 },
  376. })
  377. minetest.register_node("testnodes:liquid_flowing_waving", {
  378. description = S("Waving Flowing Liquid Drawtype Test Node"),
  379. drawtype = "flowingliquid",
  380. paramtype = "light",
  381. paramtype2 = "flowingliquid",
  382. tiles = {
  383. "testnodes_liquidflowing.png^[colorize:#0000FF:127",
  384. },
  385. special_tiles = {
  386. {name="testnodes_liquidflowing.png^[colorize:#0000FF:127", backface_culling=false},
  387. {name="testnodes_liquidflowing.png^[colorize:#0000FF:127", backface_culling=false},
  388. },
  389. use_texture_alpha = "blend",
  390. waving = 3,
  391. walkable = false,
  392. liquid_range = 1,
  393. liquid_viscosity = 0,
  394. liquid_alternative_flowing = "testnodes:liquid_flowing_waving",
  395. liquid_alternative_source = "testnodes:liquid_waving",
  396. groups = { dig_immediate = 3 },
  397. })
  398. -- Invisible node
  399. minetest.register_node("testnodes:airlike", {
  400. description = S("Airlike Drawtype Test Node"),
  401. drawtype = "airlike",
  402. paramtype = "light",
  403. walkable = false,
  404. groups = { dig_immediate = 3 },
  405. sunlight_propagates = true,
  406. })
  407. -- param2 changes liquid height
  408. minetest.register_node("testnodes:glassliquid", {
  409. description = S("Glasslike Liquid Level Drawtype Test Node"),
  410. drawtype = "glasslike_framed",
  411. paramtype = "light",
  412. paramtype2 = "glasslikeliquidlevel",
  413. tiles = {
  414. "testnodes_glasslikeliquid.png",
  415. },
  416. special_tiles = {
  417. "testnodes_liquid.png",
  418. },
  419. groups = { dig_immediate = 3 },
  420. })
  421. -- Adding many raillike examples, primarily to demonstrate the behavior of
  422. -- "raillike groups". Nodes of the same type (rail, groupless, line, street)
  423. -- should connect to nodes of the same "rail type" (=same shape, different
  424. -- color) only.
  425. local rails = {
  426. { "rail", {"testnodes_rail_straight.png", "testnodes_rail_curved.png", "testnodes_rail_t_junction.png", "testnodes_rail_crossing.png"} },
  427. { "line", {"testnodes_line_straight.png", "testnodes_line_curved.png", "testnodes_line_t_junction.png", "testnodes_line_crossing.png"}, },
  428. { "street", {"testnodes_street_straight.png", "testnodes_street_curved.png", "testnodes_street_t_junction.png", "testnodes_street_crossing.png"}, },
  429. -- the "groupless" nodes are nodes in which the "connect_to_raillike" group is not set
  430. { "groupless", {"testnodes_rail2_straight.png", "testnodes_rail2_curved.png", "testnodes_rail2_t_junction.png", "testnodes_rail2_crossing.png"} },
  431. }
  432. local colors = { "", "cyan", "red" }
  433. for r=1, #rails do
  434. local id = rails[r][1]
  435. local tiles = rails[r][2]
  436. local raillike_group
  437. if id ~= "groupless" then
  438. raillike_group = minetest.raillike_group(id)
  439. end
  440. for c=1, #colors do
  441. local color
  442. if colors[c] ~= "" then
  443. color = colors[c]
  444. end
  445. minetest.register_node("testnodes:raillike_"..id..c, {
  446. description = S("Raillike Drawtype Test Node: @1 @2", id, c),
  447. drawtype = "raillike",
  448. paramtype = "light",
  449. tiles = tiles,
  450. groups = { connect_to_raillike = raillike_group, dig_immediate = 3 },
  451. color = color,
  452. selection_box = {
  453. type = "fixed",
  454. fixed = {{-0.5, -0.5, -0.5, 0.5, -0.4, 0.5}},
  455. },
  456. sunlight_propagates = true,
  457. walkable = false,
  458. })
  459. end
  460. end
  461. -- Add visual_scale variants of previous nodes for half and double size
  462. local scale = function(subname, desc_double, desc_half)
  463. local original = "testnodes:"..subname
  464. local def = table.copy(minetest.registered_items[original])
  465. def.visual_scale = 2.0
  466. def.description = desc_double
  467. minetest.register_node("testnodes:"..subname.."_double", def)
  468. def = table.copy(minetest.registered_items[original])
  469. def.visual_scale = 0.5
  470. def.description = desc_half
  471. minetest.register_node("testnodes:"..subname.."_half", def)
  472. end
  473. scale("allfaces",
  474. S("Double-sized Allfaces Drawtype Test Node"),
  475. S("Half-sized Allfaces Drawtype Test Node"))
  476. scale("allfaces_optional",
  477. S("Double-sized Allfaces Optional Drawtype Test Node"),
  478. S("Half-sized Allfaces Optional Drawtype Test Node"))
  479. scale("allfaces_optional_waving",
  480. S("Double-sized Waving Allfaces Optional Drawtype Test Node"),
  481. S("Half-sized Waving Allfaces Optional Drawtype Test Node"))
  482. scale("plantlike",
  483. S("Double-sized Plantlike Drawtype Test Node"),
  484. S("Half-sized Plantlike Drawtype Test Node"))
  485. scale("torchlike_wallmounted",
  486. S("Double-sized Wallmounted Torchlike Drawtype Test Node"),
  487. S("Half-sized Wallmounted Torchlike Drawtype Test Node"))
  488. scale("signlike",
  489. S("Double-sized Wallmounted Signlike Drawtype Test Node"),
  490. S("Half-sized Wallmounted Signlike Drawtype Test Node"))
  491. scale("firelike",
  492. S("Double-sized Firelike Drawtype Test Node"),
  493. S("Half-sized Firelike Drawtype Test Node"))