kpoppel
2013-06-19 37d9d94c44cbadc7e6550efc22612c7c605a9040
commit | author | age
37d9d9 1 -- NOTE: The code is takes directly from VanessaE's homedecor mod.
K 2 -- I just made it the lights into indictive appliances for this mod.
3
4 -- This file supplies electric powered glowlights
5
6 -- Boilerplate to support localized strings if intllib mod is installed.
7 local S
8 if (minetest.get_modpath("intllib")) then
9     dofile(minetest.get_modpath("intllib").."/intllib.lua")
10     S = intllib.Getter(minetest.get_current_modname())
11 else
12     S = function ( s ) return s end
13 end
14
15 function technic_homedecor_node_is_owned(pos, placer)
16         local ownername = false
17         if type(IsPlayerNodeOwner) == "function" then                                   -- node_ownership mod
18                 if HasOwner(pos, placer) then                                           -- returns true if the node is owned
19                         if not IsPlayerNodeOwner(pos, placer:get_player_name()) then
20                                 if type(getLastOwner) == "function" then                -- ...is an old version
21                                         ownername = getLastOwner(pos)
22                                 elseif type(GetNodeOwnerName) == "function" then        -- ...is a recent version
23                                         ownername = GetNodeOwnerName(pos)
24                                 else
25                                         ownername = S("someone")
26                                 end
27                         end
28                 end
29
30         elseif type(isprotect)=="function" then                                         -- glomie's protection mod
31                 if not isprotect(5, pos, placer) then
32                         ownername = S("someone")
33                 end
34         elseif type(protector)=="table" and type(protector.can_dig)=="function" then                                    -- Zeg9's protection mod
35                 if not protector.can_dig(5, pos, placer) then
36                         ownername = S("someone")
37                 end
38         end
39
40         if ownername ~= false then
41                 minetest.chat_send_player( placer:get_player_name(), S("Sorry, %s owns that spot."):format(ownername) )
42                 return true
43         else
44                 return false
45         end
46 end
47
48 local dirs1 = { 20, 23, 22, 21 }
49 local dirs2 = { 9, 18, 7, 12 }
50
51 function technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
52     if not technic_homedecor_node_is_owned(pointed_thing.under, placer) 
53        and not technic_homedecor_node_is_owned(pointed_thing.above, placer) then
54         local node = minetest.env:get_node(pointed_thing.under)
55         if not minetest.registered_nodes[node.name] or not minetest.registered_nodes[node.name].on_rightclick then
56
57             local above = pointed_thing.above
58             local under = pointed_thing.under
59             local pitch = placer:get_look_pitch()
60             local pname = minetest.env:get_node(under).name
61             local node = minetest.env:get_node(above)
62             local fdir = minetest.dir_to_facedir(placer:get_look_dir())
63             local wield_name = itemstack:get_name()
64
65             if not minetest.registered_nodes[pname]
66                 or not minetest.registered_nodes[pname].on_rightclick then
67
68                 local iswall = (above.x ~= under.x) or (above.z ~= under.z)
69                 local isceiling = (above.x == under.x) and (above.z == under.z) and (pitch > 0)
70                 local pos1 = above
71
72                 if minetest.registered_nodes[pname]["buildable_to"] then
73                     pos1 = under
74                     iswall = false
75                 end
76
77                 if not minetest.registered_nodes[minetest.env:get_node(pos1).name]["buildable_to"] then return end
78
79                 if iswall then 
80                     minetest.env:add_node(pos1, {name = wield_name, param2 = dirs2[fdir+1] }) -- place wall variant
81                 elseif isceiling then
82                     minetest.env:add_node(pos1, {name = wield_name, param2 = 20 }) -- place upside down variant
83                 else
84                     minetest.env:add_node(pos1, {name = wield_name, param2 = 0 }) -- place right side up
85                 end
86
87                 if not homedecor_expect_infinite_stacks then
88                     itemstack:take_item()
89                     return itemstack
90                 end
91             end
92         else
93             minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack)
94         end
95     end
96 end
97
98 -- Yellow -- Half node
99 minetest.register_node('technic:homedecor_glowlight_half_yellow', {
100     description = S("Yellow Glowlight (thick)"),
101     drawtype = "nodebox",
102     tiles = {
103         'technic_homedecor_glowlight_yellow_tb.png',
104         'technic_homedecor_glowlight_yellow_tb.png',
105         'technic_homedecor_glowlight_thick_yellow_sides.png',
106         'technic_homedecor_glowlight_thick_yellow_sides.png',
107         'technic_homedecor_glowlight_thick_yellow_sides.png',
108         'technic_homedecor_glowlight_thick_yellow_sides.png'
109     },
110         selection_box = {
111                 type = "fixed",
112                 fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
113         },
114         node_box = {
115                 type = "fixed",
116                 fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
117         },
118
119     sunlight_propagates = false,
120     paramtype = "light",
121     paramtype2 = "facedir",
122     walkable = true,
123     sounds = default.node_sound_wood_defaults(),
124
125     groups = { snappy = 3 },
126     on_place = function(itemstack, placer, pointed_thing)
127         technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
128         return itemstack
129          end,
130     on_construct = function(pos)
131               print("Hello")
132               technic_inductive_on_construct(pos, 100, "Yellow Glowlight (thick)")
133               print("Hello2")
134                end,
135     on_punch = function(pos, node, puncher)
136               print("Punch")
137               technic_inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_half_yellow_active")
138               print("Punch2")
139            end
140 })
141
142 minetest.register_node('technic:homedecor_glowlight_half_yellow_active', {
143     description = S("Yellow Glowlight (thick)"),
144     drawtype = "nodebox",
145     tiles = {
146         'technic_homedecor_glowlight_yellow_tb.png',
147         'technic_homedecor_glowlight_yellow_tb.png',
148         'technic_homedecor_glowlight_thick_yellow_sides.png',
149         'technic_homedecor_glowlight_thick_yellow_sides.png',
150         'technic_homedecor_glowlight_thick_yellow_sides.png',
151         'technic_homedecor_glowlight_thick_yellow_sides.png'
152     },
153         selection_box = {
154                 type = "fixed",
155                 fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
156         },
157         node_box = {
158                 type = "fixed",
159                 fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
160         },
161
162     sunlight_propagates = false,
163     paramtype = "light",
164     paramtype2 = "facedir",
165     walkable = true,
166     light_source = LIGHT_MAX,
167     sounds = default.node_sound_wood_defaults(),
168
169     groups = { snappy = 3, not_in_creative_inventory=1},
170     drop="technic:homedecor_glowlight_half_yellow",
171     on_place = function(itemstack, placer, pointed_thing)
172         technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
173         return itemstack
174          end,
175     on_construct = function(pos)
176               technic_inductive_on_construct(pos, 100, "Yellow Glowlight (thick)")
177                end,
178     on_punch = function(pos, node, puncher)
179               technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_half_yellow")
180            end
181 })
182
183 -- Yellow -- Quarter node
184 minetest.register_node('technic:homedecor_glowlight_quarter_yellow', {
185     description = S("Yellow Glowlight (thin)"),
186     drawtype = "nodebox",
187     tiles = {
188         'technic_homedecor_glowlight_yellow_tb.png',
189         'technic_homedecor_glowlight_yellow_tb.png',
190         'technic_homedecor_glowlight_thin_yellow_sides.png',
191         'technic_homedecor_glowlight_thin_yellow_sides.png',
192         'technic_homedecor_glowlight_thin_yellow_sides.png',
193         'technic_homedecor_glowlight_thin_yellow_sides.png'
194     },
195         selection_box = {
196                 type = "fixed",
197                 fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
198         },
199         node_box = {
200                 type = "fixed",
201                 fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
202         },
203
204     sunlight_propagates = false,
205     paramtype = "light",
206     paramtype2 = "facedir",
207     walkable = true,
208     sounds = default.node_sound_wood_defaults(),
209
210     groups = { snappy = 3 },
211     on_place = function(itemstack, placer, pointed_thing)
212         technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
213         return itemstack
214          end,
215     on_construct = function(pos)
216               technic_inductive_on_construct(pos, 100, "Yellow Glowlight (thin)")
217                end,
218     on_punch = function(pos, node, puncher)
219               technic_inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_quarter_yellow_active")
220            end
221 })
222
223 minetest.register_node('technic:homedecor_glowlight_quarter_yellow_active', {
224     description = S("Yellow Glowlight (thin)"),
225     drawtype = "nodebox",
226     tiles = {
227         'technic_homedecor_glowlight_yellow_tb.png',
228         'technic_homedecor_glowlight_yellow_tb.png',
229         'technic_homedecor_glowlight_thin_yellow_sides.png',
230         'technic_homedecor_glowlight_thin_yellow_sides.png',
231         'technic_homedecor_glowlight_thin_yellow_sides.png',
232         'technic_homedecor_glowlight_thin_yellow_sides.png'
233     },
234         selection_box = {
235                 type = "fixed",
236                 fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
237         },
238         node_box = {
239                 type = "fixed",
240                 fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
241         },
242
243     sunlight_propagates = false,
244     paramtype = "light",
245     paramtype2 = "facedir",
246     walkable = true,
247     light_source = LIGHT_MAX-1,
248     sounds = default.node_sound_wood_defaults(),
249
250     groups = { snappy = 3, not_in_creative_inventory=1},
251     drop="technic:homedecor_glowlight_quarter_yellow",
252     on_place = function(itemstack, placer, pointed_thing)
253         technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
254         return itemstack
255          end,
256     on_construct = function(pos)
257               technic_inductive_on_construct(pos, 100, "Yellow Glowlight (thin)")
258                end,
259     on_punch = function(pos, node, puncher)
260               technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_quarter_yellow")
261            end
262 })
263
264
265 -- White -- half node
266 minetest.register_node('technic:homedecor_glowlight_half_white', {
267     description = S("White Glowlight (thick)"),
268     drawtype = "nodebox",
269     tiles = {
270         'technic_homedecor_glowlight_white_tb.png',
271         'technic_homedecor_glowlight_white_tb.png',
272         'technic_homedecor_glowlight_thick_white_sides.png',
273         'technic_homedecor_glowlight_thick_white_sides.png',
274         'technic_homedecor_glowlight_thick_white_sides.png',
275         'technic_homedecor_glowlight_thick_white_sides.png'
276     },
277         selection_box = {
278                 type = "fixed",
279                 fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
280         },
281         node_box = {
282                 type = "fixed",
283                 fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
284         },
285
286     sunlight_propagates = false,
287     paramtype = "light",
288     paramtype2 = "facedir",
289     walkable = true,
290     sounds = default.node_sound_wood_defaults(),
291
292     groups = { snappy = 3 },
293     on_place = function(itemstack, placer, pointed_thing)
294         technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
295         return itemstack
296          end,
297     on_construct = function(pos)
298               technic_inductive_on_construct(pos, 100, "White Glowlight (thick)")
299                end,
300     on_punch = function(pos, node, puncher)
301               technic_inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_half_white_active")
302            end
303 })
304
305 minetest.register_node('technic:homedecor_glowlight_half_white_active', {
306     description = S("White Glowlight (thick)"),
307     drawtype = "nodebox",
308     tiles = {
309         'technic_homedecor_glowlight_white_tb.png',
310         'technic_homedecor_glowlight_white_tb.png',
311         'technic_homedecor_glowlight_thick_white_sides.png',
312         'technic_homedecor_glowlight_thick_white_sides.png',
313         'technic_homedecor_glowlight_thick_white_sides.png',
314         'technic_homedecor_glowlight_thick_white_sides.png'
315     },
316         selection_box = {
317                 type = "fixed",
318                 fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
319         },
320         node_box = {
321                 type = "fixed",
322                 fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
323         },
324
325     sunlight_propagates = false,
326     paramtype = "light",
327     paramtype2 = "facedir",
328     walkable = true,
329     light_source = LIGHT_MAX,
330     sounds = default.node_sound_wood_defaults(),
331
332     groups = { snappy = 3, not_in_creative_inventory=1},
333     drop="technic:homedecor_glowlight_half_white",
334     on_place = function(itemstack, placer, pointed_thing)
335         technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
336         return itemstack
337          end,
338     on_construct = function(pos)
339               technic_inductive_on_construct(pos, 100, "White Glowlight (thick)")
340                end,
341     on_punch = function(pos, node, puncher)
342               technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_half_white")
343            end
344 })
345
346 -- White -- Quarter node
347 minetest.register_node('technic:homedecor_glowlight_quarter_white', {
348     description = S("White Glowlight (thin)"),
349     drawtype = "nodebox",
350     tiles = {
351         'technic_homedecor_glowlight_white_tb.png',
352         'technic_homedecor_glowlight_white_tb.png',
353         'technic_homedecor_glowlight_thin_white_sides.png',
354         'technic_homedecor_glowlight_thin_white_sides.png',
355         'technic_homedecor_glowlight_thin_white_sides.png',
356         'technic_homedecor_glowlight_thin_white_sides.png'
357     },
358         selection_box = {
359                 type = "fixed",
360                 fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
361         },
362         node_box = {
363                 type = "fixed",
364                 fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
365         },
366
367     sunlight_propagates = false,
368     paramtype = "light",
369     paramtype2 = "facedir",
370     walkable = true,
371     sounds = default.node_sound_wood_defaults(),
372
373     groups = { snappy = 3 },
374     on_place = function(itemstack, placer, pointed_thing)
375         technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
376         return itemstack
377          end,
378     on_construct = function(pos)
379               technic_inductive_on_construct(pos, 100, "White Glowlight (thin)")
380                end,
381     on_punch = function(pos, node, puncher)
382               technic_inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_quarter_white_active")
383            end
384 })
385
386 minetest.register_node('technic:homedecor_glowlight_quarter_white_active', {
387     description = S("White Glowlight (thin)"),
388     drawtype = "nodebox",
389     tiles = {
390         'technic_homedecor_glowlight_white_tb.png',
391         'technic_homedecor_glowlight_white_tb.png',
392         'technic_homedecor_glowlight_thin_white_sides.png',
393         'technic_homedecor_glowlight_thin_white_sides.png',
394         'technic_homedecor_glowlight_thin_white_sides.png',
395         'technic_homedecor_glowlight_thin_white_sides.png'
396     },
397         selection_box = {
398                 type = "fixed",
399                 fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
400         },
401         node_box = {
402                 type = "fixed",
403                 fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
404         },
405
406     sunlight_propagates = false,
407     paramtype = "light",
408     paramtype2 = "facedir",
409     walkable = true,
410     light_source = LIGHT_MAX-1,
411     sounds = default.node_sound_wood_defaults(),
412
413     groups = { snappy = 3, not_in_creative_inventory=1},
414     drop="technic:homedecor_glowlight_quarter_white",
415     on_place = function(itemstack, placer, pointed_thing)
416         technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
417         return itemstack
418          end,
419     on_construct = function(pos)
420               technic_inductive_on_construct(pos, 100, "White Glowlight (thin)")
421                end,
422     on_punch = function(pos, node, puncher)
423               technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_quarter_white")
424            end
425 })
426
427 -- Glowlight "cubes" - yellow
428 minetest.register_node('technic:homedecor_glowlight_small_cube_yellow', {
429     description = S("Yellow Glowlight (small cube)"),
430     drawtype = "nodebox",
431     tiles = {
432         'technic_homedecor_glowlight_cube_yellow_tb.png',
433         'technic_homedecor_glowlight_cube_yellow_tb.png',
434         'technic_homedecor_glowlight_cube_yellow_sides.png',
435         'technic_homedecor_glowlight_cube_yellow_sides.png',
436         'technic_homedecor_glowlight_cube_yellow_sides.png',
437         'technic_homedecor_glowlight_cube_yellow_sides.png'
438     },
439         selection_box = {
440                 type = "fixed",
441                 fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
442         },
443         node_box = {
444                 type = "fixed",
445                 fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
446         },
447
448     sunlight_propagates = false,
449     paramtype = "light",
450     paramtype2 = "facedir",
451     walkable = true,
452     sounds = default.node_sound_wood_defaults(),
453
454     groups = { snappy = 3 },
455     on_place = function(itemstack, placer, pointed_thing)
456         technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
457         return itemstack
458          end,
459     on_construct = function(pos)
460               technic_inductive_on_construct(pos, 50, "Yellow Glowlight (small cube)")
461                end,
462     on_punch = function(pos, node, puncher)
463               technic_inductive_on_punch_off(pos, 50, "technic:homedecor_glowlight_small_cube_yellow_active")
464            end
465 })
466
467 minetest.register_node('technic:homedecor_glowlight_small_cube_yellow_active', {
468     description = S("Yellow Glowlight (small cube)"),
469     drawtype = "nodebox",
470     tiles = {
471         'technic_homedecor_glowlight_cube_yellow_tb.png',
472         'technic_homedecor_glowlight_cube_yellow_tb.png',
473         'technic_homedecor_glowlight_cube_yellow_sides.png',
474         'technic_homedecor_glowlight_cube_yellow_sides.png',
475         'technic_homedecor_glowlight_cube_yellow_sides.png',
476         'technic_homedecor_glowlight_cube_yellow_sides.png'
477     },
478         selection_box = {
479                 type = "fixed",
480                 fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
481         },
482         node_box = {
483                 type = "fixed",
484                 fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
485         },
486
487     sunlight_propagates = false,
488     paramtype = "light",
489     paramtype2 = "facedir",
490     walkable = true,
491     light_source = LIGHT_MAX-1,
492     sounds = default.node_sound_wood_defaults(),
493
494     groups = { snappy = 3, not_in_creative_inventory=1},
495     drop="technic:homedecor_glowlight_cube_yellow",
496     on_place = function(itemstack, placer, pointed_thing)
497         technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
498         return itemstack
499          end,
500     on_construct = function(pos)
501               technic_inductive_on_construct(pos, 50, "Yellow Glowlight (small cube)")
502                end,
503     on_punch = function(pos, node, puncher)
504               technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_small_cube_yellow")
505            end
506 })
507
508 -- Glowlight "cubes" - white
509 minetest.register_node('technic:homedecor_glowlight_small_cube_white', {
510     description = S("White Glowlight (small cube)"),
511     drawtype = "nodebox",
512     tiles = {
513         'technic_homedecor_glowlight_cube_white_tb.png',
514         'technic_homedecor_glowlight_cube_white_tb.png',
515         'technic_homedecor_glowlight_cube_white_sides.png',
516         'technic_homedecor_glowlight_cube_white_sides.png',
517         'technic_homedecor_glowlight_cube_white_sides.png',
518         'technic_homedecor_glowlight_cube_white_sides.png'
519     },
520         selection_box = {
521                 type = "fixed",
522                 fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
523         },
524         node_box = {
525                 type = "fixed",
526                 fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
527         },
528
529     sunlight_propagates = false,
530     paramtype = "light",
531     paramtype2 = "facedir",
532     walkable = true,
533     sounds = default.node_sound_wood_defaults(),
534
535     groups = { snappy = 3 },
536     on_place = function(itemstack, placer, pointed_thing)
537         technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
538         return itemstack
539          end,
540     on_construct = function(pos)
541               technic_inductive_on_construct(pos, 50, "White Glowlight (small cube)")
542                end,
543     on_punch = function(pos, node, puncher)
544               technic_inductive_on_punch_off(pos, 50, "technic:homedecor_glowlight_small_cube_white_active")
545            end
546 })
547
548 minetest.register_node('technic:homedecor_glowlight_small_cube_white_active', {
549     description = S("White Glowlight (small cube)"),
550     drawtype = "nodebox",
551     tiles = {
552         'technic_homedecor_glowlight_cube_white_tb.png',
553         'technic_homedecor_glowlight_cube_white_tb.png',
554         'technic_homedecor_glowlight_cube_white_sides.png',
555         'technic_homedecor_glowlight_cube_white_sides.png',
556         'technic_homedecor_glowlight_cube_white_sides.png',
557         'technic_homedecor_glowlight_cube_white_sides.png'
558     },
559         selection_box = {
560                 type = "fixed",
561                 fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
562         },
563         node_box = {
564                 type = "fixed",
565                 fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
566         },
567
568     sunlight_propagates = false,
569     paramtype = "light",
570     paramtype2 = "facedir",
571     walkable = true,
572     light_source = LIGHT_MAX-1,
573     sounds = default.node_sound_wood_defaults(),
574
575     groups = { snappy = 3, not_in_creative_inventory=1},
576     drop="technic:homedecor_glowlight_cube_white",
577     on_place = function(itemstack, placer, pointed_thing)
578         technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
579         return itemstack
580          end,
581     on_construct = function(pos)
582               technic_inductive_on_construct(pos, 50, "White Glowlight (small cube)")
583                end,
584     on_punch = function(pos, node, puncher)
585               technic_inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_small_cube_white")
586            end
587 })
588
589 register_inductive_machine("technic:homedecor_glowlight_half_yellow")
590 register_inductive_machine("technic:homedecor_glowlight_half_white")
591 register_inductive_machine("technic:homedecor_glowlight_quarter_yellow")
592 register_inductive_machine("technic:homedecor_glowlight_quarter_white")
593 register_inductive_machine("technic:homedecor_glowlight_small_cube_yellow")
594 register_inductive_machine("technic:homedecor_glowlight_small_cube_white")