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