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