]> git.lizzy.rs Git - dragonfireclient.git/blob - games/devtest/mods/testnodes/drawtypes.lua
2bc7ec2e3d5e5a29e8b2fa5f23e84fd822309cf4
[dragonfireclient.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
212
213 -- param2 will rotate
214 local function rotate_on_rightclick(pos, node, clicker)
215         local def = minetest.registered_nodes[node.name]
216         local aux1 = clicker:get_player_control().aux1
217
218         local deg, deg_max
219         local color, color_mult = 0, 0
220         if def.paramtype2 == "degrotate" then
221                 deg = node.param2
222                 deg_max = 240
223         elseif def.paramtype2 == "colordegrotate" then
224                 -- MSB [3x color, 5x rotation] LSB
225                 deg = node.param2 % 2^5
226                 deg_max = 24
227                 color_mult = 2^5
228                 color = math.floor(node.param2 / color_mult)
229         end
230
231         deg = (deg + (aux1 and 10 or 1)) % deg_max
232         node.param2 = color * color_mult + deg
233         minetest.swap_node(pos, node)
234         minetest.chat_send_player(clicker:get_player_name(),
235                 "Rotation is now " .. deg .. " / " .. deg_max)
236 end
237
238 minetest.register_node("testnodes:plantlike_degrotate", {
239         description = S("Degrotate Plantlike Drawtype Test Node"),
240         drawtype = "plantlike",
241         paramtype = "light",
242         paramtype2 = "degrotate",
243         tiles = { "testnodes_plantlike_degrotate.png" },
244
245         on_rightclick = rotate_on_rightclick,
246         place_param2 = 7,
247         walkable = false,
248         sunlight_propagates = true,
249         groups = { dig_immediate = 3 },
250 })
251
252 minetest.register_node("testnodes:mesh_degrotate", {
253         description = S("Degrotate Mesh Drawtype Test Node"),
254         drawtype = "mesh",
255         paramtype = "light",
256         paramtype2 = "degrotate",
257         mesh = "testnodes_ocorner.obj",
258         tiles = { "testnodes_mesh_stripes2.png" },
259
260         on_rightclick = rotate_on_rightclick,
261         place_param2 = 10, -- 15°
262         sunlight_propagates = true,
263         groups = { dig_immediate = 3 },
264 })
265
266 minetest.register_node("testnodes:mesh_colordegrotate", {
267         description = S("Color Degrotate Mesh Drawtype Test Node"),
268         drawtype = "mesh",
269         paramtype = "light",
270         paramtype2 = "colordegrotate",
271         palette = "testnodes_palette_facedir.png",
272         mesh = "testnodes_ocorner.obj",
273         tiles = { "testnodes_mesh_stripes3.png" },
274
275         on_rightclick = rotate_on_rightclick,
276         -- color index 1, 1 step (=15°) rotated
277         place_param2 = 1 * 2^5 + 1,
278         sunlight_propagates = true,
279         groups = { dig_immediate = 3 },
280 })
281
282 -- param2 will change height
283 minetest.register_node("testnodes:plantlike_leveled", {
284         description = S("Leveled Plantlike Drawtype Test Node"),
285         drawtype = "plantlike",
286         paramtype = "light",
287         paramtype2 = "leveled",
288         tiles = {
289                 { name = "testnodes_plantlike_leveled.png", tileable_vertical = true },
290         },
291
292
293         -- We set a default param2 here only for convenience, to make the "plant" visible after placement
294         place_param2 = 8,
295         walkable = false,
296         sunlight_propagates = true,
297         groups = { dig_immediate = 3 },
298 })
299
300 -- param2 changes shape
301 minetest.register_node("testnodes:plantlike_meshoptions", {
302         description = S("Meshoptions Plantlike Drawtype Test Node"),
303         drawtype = "plantlike",
304         paramtype = "light",
305         paramtype2 = "meshoptions",
306         tiles = { "testnodes_plantlike_meshoptions.png" },
307
308
309         walkable = false,
310         groups = { dig_immediate = 3 },
311 })
312
313 minetest.register_node("testnodes:plantlike_rooted", {
314         description = S("Rooted Plantlike Drawtype Test Node"),
315         drawtype = "plantlike_rooted",
316         paramtype = "light",
317         tiles = { "testnodes_plantlike_rooted_base.png" },
318         special_tiles = { "testnodes_plantlike_rooted.png" },
319
320         groups = { dig_immediate = 3 },
321 })
322
323 minetest.register_node("testnodes:plantlike_rooted_waving", {
324         description = S("Waving Rooted Plantlike Drawtype Test Node"),
325         drawtype = "plantlike_rooted",
326         paramtype = "light",
327         tiles = {
328                 "testnodes_plantlike_rooted_base.png",
329                 "testnodes_plantlike_rooted_base.png",
330                 "testnodes_plantlike_rooted_base_side_waving.png",
331         },
332         special_tiles = { "testnodes_plantlike_rooted_waving.png" },
333         waving = 1,
334
335         groups = { dig_immediate = 3 },
336 })
337
338 -- param2 changes height
339 minetest.register_node("testnodes:plantlike_rooted_leveled", {
340         description = S("Leveled Rooted Plantlike Drawtype Test Node"),
341         drawtype = "plantlike_rooted",
342         paramtype = "light",
343         paramtype2 = "leveled",
344         tiles = {
345                 "testnodes_plantlike_rooted_base.png",
346                 "testnodes_plantlike_rooted_base.png",
347                 "testnodes_plantlike_rooted_base_side_leveled.png",
348         },
349         special_tiles = {
350                 { name = "testnodes_plantlike_rooted_leveled.png", tileable_vertical = true },
351         },
352
353
354         -- We set a default param2 here only for convenience, to make the "plant" visible after placement
355         place_param2 = 8,
356         groups = { dig_immediate = 3 },
357 })
358
359 -- param2 changes shape
360 minetest.register_node("testnodes:plantlike_rooted_meshoptions", {
361         description = S("Meshoptions Rooted Plantlike Drawtype Test Node"),
362         drawtype = "plantlike_rooted",
363         paramtype = "light",
364         paramtype2 = "meshoptions",
365         tiles = {
366                 "testnodes_plantlike_rooted_base.png",
367                 "testnodes_plantlike_rooted_base.png",
368                 "testnodes_plantlike_rooted_base_side_meshoptions.png",
369         },
370         special_tiles = {
371                 "testnodes_plantlike_rooted_meshoptions.png",
372         },
373
374         groups = { dig_immediate = 3 },
375 })
376
377 -- param2 changes rotation
378 minetest.register_node("testnodes:plantlike_rooted_degrotate", {
379         description = S("Degrotate Rooted Plantlike Drawtype Test Node"),
380         drawtype = "plantlike_rooted",
381         paramtype = "light",
382         paramtype2 = "degrotate",
383         tiles = {
384                 "testnodes_plantlike_rooted_base.png",
385                 "testnodes_plantlike_rooted_base.png",
386                 "testnodes_plantlike_rooted_base_side_degrotate.png",
387         },
388         special_tiles = {
389                 "testnodes_plantlike_rooted_degrotate.png",
390         },
391
392         groups = { dig_immediate = 3 },
393 })
394
395 -- Demonstrative liquid nodes, source and flowing form.
396 -- DRAWTYPE ONLY, NO LIQUID PHYSICS!
397 -- Liquid ranges 0 to 8
398 for r = 0, 8 do
399         minetest.register_node("testnodes:liquid_"..r, {
400                 description = S("Source Liquid Drawtype Test Node, Range @1", r),
401                 drawtype = "liquid",
402                 paramtype = "light",
403                 tiles = {
404                         "testnodes_liquidsource_r"..r..".png^[colorize:#FFFFFF:100",
405                 },
406                 special_tiles = {
407                         {name="testnodes_liquidsource_r"..r..".png^[colorize:#FFFFFF:100", backface_culling=false},
408                         {name="testnodes_liquidsource_r"..r..".png^[colorize:#FFFFFF:100", backface_culling=true},
409                 },
410                 use_texture_alpha = "blend",
411
412
413                 walkable = false,
414                 liquid_range = r,
415                 liquid_viscosity = 0,
416                 liquid_alternative_flowing = "testnodes:liquid_flowing_"..r,
417                 liquid_alternative_source = "testnodes:liquid_"..r,
418                 groups = { dig_immediate = 3 },
419         })
420         minetest.register_node("testnodes:liquid_flowing_"..r, {
421                 description = S("Flowing Liquid Drawtype Test Node, Range @1", r),
422                 drawtype = "flowingliquid",
423                 paramtype = "light",
424                 paramtype2 = "flowingliquid",
425                 tiles = {
426                         "testnodes_liquidflowing_r"..r..".png^[colorize:#FFFFFF:100",
427                 },
428                 special_tiles = {
429                         {name="testnodes_liquidflowing_r"..r..".png^[colorize:#FFFFFF:100", backface_culling=false},
430                         {name="testnodes_liquidflowing_r"..r..".png^[colorize:#FFFFFF:100", backface_culling=false},
431                 },
432                 use_texture_alpha = "blend",
433
434
435                 walkable = false,
436                 liquid_range = r,
437                 liquid_viscosity = 0,
438                 liquid_alternative_flowing = "testnodes:liquid_flowing_"..r,
439                 liquid_alternative_source = "testnodes:liquid_"..r,
440                 groups = { dig_immediate = 3 },
441         })
442
443 end
444
445 -- Waving liquid test (drawtype only)
446 minetest.register_node("testnodes:liquid_waving", {
447         description = S("Waving Source Liquid Drawtype Test Node"),
448         drawtype = "liquid",
449         paramtype = "light",
450         tiles = {
451                 "testnodes_liquidsource.png^[colorize:#0000FF:127",
452         },
453         special_tiles = {
454                 {name="testnodes_liquidsource.png^[colorize:#0000FF:127", backface_culling=false},
455                 {name="testnodes_liquidsource.png^[colorize:#0000FF:127", backface_culling=true},
456         },
457         use_texture_alpha = "blend",
458         waving = 3,
459
460
461         walkable = false,
462         liquid_range = 1,
463         liquid_viscosity = 0,
464         liquid_alternative_flowing = "testnodes:liquid_flowing_waving",
465         liquid_alternative_source = "testnodes:liquid_waving",
466         groups = { dig_immediate = 3 },
467 })
468 minetest.register_node("testnodes:liquid_flowing_waving", {
469         description = S("Waving Flowing Liquid Drawtype Test Node"),
470         drawtype = "flowingliquid",
471         paramtype = "light",
472         paramtype2 = "flowingliquid",
473         tiles = {
474                 "testnodes_liquidflowing.png^[colorize:#0000FF:127",
475         },
476         special_tiles = {
477                 {name="testnodes_liquidflowing.png^[colorize:#0000FF:127", backface_culling=false},
478                 {name="testnodes_liquidflowing.png^[colorize:#0000FF:127", backface_culling=false},
479         },
480         use_texture_alpha = "blend",
481         waving = 3,
482
483
484         walkable = false,
485         liquid_range = 1,
486         liquid_viscosity = 0,
487         liquid_alternative_flowing = "testnodes:liquid_flowing_waving",
488         liquid_alternative_source = "testnodes:liquid_waving",
489         groups = { dig_immediate = 3 },
490 })
491
492 -- Invisible node
493 minetest.register_node("testnodes:airlike", {
494         description = S("Airlike Drawtype Test Node"),
495         drawtype = "airlike",
496         paramtype = "light",
497
498
499         walkable = false,
500         groups = { dig_immediate = 3 },
501         sunlight_propagates = true,
502 })
503
504 -- param2 changes liquid height
505 minetest.register_node("testnodes:glassliquid", {
506         description = S("Glasslike Liquid Level Drawtype Test Node"),
507         drawtype = "glasslike_framed",
508         paramtype = "light",
509         paramtype2 = "glasslikeliquidlevel",
510         tiles = {
511                 "testnodes_glasslikeliquid.png",
512         },
513         special_tiles = {
514                 "testnodes_liquid.png",
515         },
516
517         groups = { dig_immediate = 3 },
518 })
519
520 -- Adding many raillike examples, primarily to demonstrate the behavior of
521 -- "raillike groups". Nodes of the same type (rail, groupless, line, street)
522 -- should connect to nodes of the same "rail type" (=same shape, different
523 -- color) only.
524 local rails = {
525         { "rail", {"testnodes_rail_straight.png", "testnodes_rail_curved.png", "testnodes_rail_t_junction.png", "testnodes_rail_crossing.png"} },
526         { "line", {"testnodes_line_straight.png", "testnodes_line_curved.png", "testnodes_line_t_junction.png", "testnodes_line_crossing.png"}, },
527         { "street", {"testnodes_street_straight.png", "testnodes_street_curved.png", "testnodes_street_t_junction.png", "testnodes_street_crossing.png"}, },
528         -- the "groupless" nodes are nodes in which the "connect_to_raillike" group is not set
529         { "groupless", {"testnodes_rail2_straight.png", "testnodes_rail2_curved.png", "testnodes_rail2_t_junction.png", "testnodes_rail2_crossing.png"} },
530 }
531 local colors = { "", "cyan", "red" }
532
533 for r=1, #rails do
534         local id = rails[r][1]
535         local tiles = rails[r][2]
536         local raillike_group
537         if id ~= "groupless" then
538                 raillike_group = minetest.raillike_group(id)
539         end
540         for c=1, #colors do
541                 local color
542                 if colors[c] ~= "" then
543                         color = colors[c]
544                 end
545                 minetest.register_node("testnodes:raillike_"..id..c, {
546                         description = S("Raillike Drawtype Test Node: @1 @2", id, c),
547                         drawtype = "raillike",
548                         paramtype = "light",
549                         tiles = tiles,
550                         groups = { connect_to_raillike = raillike_group, dig_immediate = 3 },
551
552
553                         color = color,
554                         selection_box = {
555                                 type = "fixed",
556                                 fixed = {{-0.5,  -0.5,  -0.5, 0.5, -0.4, 0.5}},
557                         },
558                         sunlight_propagates = true,
559                         walkable = false,
560                 })
561         end
562 end
563
564
565
566 -- Add visual_scale variants of previous nodes for half and double size
567 local scale = function(subname, desc_double, desc_half)
568         local original = "testnodes:"..subname
569         local def = table.copy(minetest.registered_items[original])
570         def.visual_scale = 2.0
571         def.description = desc_double
572         minetest.register_node("testnodes:"..subname.."_double", def)
573         def = table.copy(minetest.registered_items[original])
574         def.visual_scale = 0.5
575         def.description = desc_half
576         minetest.register_node("testnodes:"..subname.."_half", def)
577 end
578
579 scale("allfaces",
580         S("Double-sized Allfaces Drawtype Test Node"),
581         S("Half-sized Allfaces Drawtype Test Node"))
582 scale("allfaces_optional",
583         S("Double-sized Allfaces Optional Drawtype Test Node"),
584         S("Half-sized Allfaces Optional Drawtype Test Node"))
585 scale("allfaces_optional_waving",
586         S("Double-sized Waving Allfaces Optional Drawtype Test Node"),
587         S("Half-sized Waving Allfaces Optional Drawtype Test Node"))
588 scale("plantlike",
589         S("Double-sized Plantlike Drawtype Test Node"),
590         S("Half-sized Plantlike Drawtype Test Node"))
591 scale("torchlike_wallmounted",
592         S("Double-sized Wallmounted Torchlike Drawtype Test Node"),
593         S("Half-sized Wallmounted Torchlike Drawtype Test Node"))
594 scale("signlike_wallmounted",
595         S("Double-sized Wallmounted Signlike Drawtype Test Node"),
596         S("Half-sized Wallmounted Signlike Drawtype Test Node"))
597 scale("firelike",
598         S("Double-sized Firelike Drawtype Test Node"),
599         S("Half-sized Firelike Drawtype Test Node"))