]> git.lizzy.rs Git - xdecor.git/blob - nodes.lua
Move sitting functions in handlers folder (turn it globals)
[xdecor.git] / nodes.lua
1 screwdriver = screwdriver or {}
2
3 xpanes.register_pane("bamboo_frame", {
4         description = "Bamboo Frame",
5         tiles = {"xdecor_bamboo_frame.png"},
6         drawtype = "airlike",
7         paramtype = "light",
8         textures = {"xdecor_bamboo_frame.png", "xdecor_bamboo_frame.png", "xpanes_space.png"},
9         inventory_image = "xdecor_bamboo_frame.png",
10         wield_image = "xdecor_bamboo_frame.png",
11         groups = {choppy=3, oddly_breakable_by_hand=2, pane=1, flammable=2},
12         recipe = {
13                 {"default:papyrus", "default:papyrus", "default:papyrus"},
14                 {"default:papyrus", "farming:cotton", "default:papyrus"},
15                 {"default:papyrus", "default:papyrus", "default:papyrus"}
16         }
17 })
18
19 xdecor.register("baricade", {
20         description = "Baricade",
21         drawtype = "plantlike",
22         walkable = false,
23         inventory_image = "xdecor_baricade.png",
24         tiles = {"xdecor_baricade.png"},
25         groups = {choppy=2, oddly_breakable_by_hand=1, flammable=3},
26         damage_per_second = 4,
27         selection_box = xdecor.nodebox.slab_y(0.3)
28 })
29
30 xdecor.register("barrel", {
31         description = "Barrel",
32         inventory = {size=24},
33         infotext = "Barrel",
34         tiles = {"xdecor_barrel_top.png", "xdecor_barrel_sides.png"},
35         groups = {choppy=2, oddly_breakable_by_hand=1, flammable=3},
36         sounds = default.node_sound_wood_defaults()
37 })
38
39 xdecor.register("cabinet", {
40         description = "Wood Cabinet",
41         inventory = {size=24},
42         infotext = "Wood Cabinet",
43         groups = {choppy=2, oddly_breakable_by_hand=1, flammable=3},
44         sounds = default.node_sound_wood_defaults(),
45         on_rotate = screwdriver.rotate_simple,
46         tiles = {
47                 "xdecor_cabinet_sides.png", "xdecor_cabinet_sides.png",
48                 "xdecor_cabinet_sides.png", "xdecor_cabinet_sides.png",
49                 "xdecor_cabinet_sides.png", "xdecor_cabinet_front.png"
50         }
51 })
52
53 xdecor.register("cabinet_half", {
54         description = "Half Wood Cabinet",
55         inventory = {size=8},
56         infotext = "Half Wood Cabinet",
57         groups = {choppy=3, oddly_breakable_by_hand=2, flammable=3},
58         sounds = default.node_sound_wood_defaults(),
59         node_box = xdecor.nodebox.slab_y(0.5, 0.5),
60         tiles = {
61                 "xdecor_cabinet_sides.png", "xdecor_cabinet_sides.png",
62                 "xdecor_half_cabinet_sides.png", "xdecor_half_cabinet_sides.png",
63                 "xdecor_half_cabinet_sides.png", "xdecor_half_cabinet_front.png"
64         }
65 })
66
67 xdecor.register("candle", {
68         description = "Candle",
69         light_source = 12,
70         drawtype = "torchlike",
71         inventory_image = "xdecor_candle_inv.png",
72         wield_image = "xdecor_candle_wield.png",
73         paramtype2 = "wallmounted",
74         legacy_wallmounted = true,
75         walkable = false,
76         groups = {dig_immediate=3, attached_node=1},
77         tiles = {
78                 { name = "xdecor_candle_floor.png",
79                         animation = {type="vertical_frames", length=1.5} },
80                 { name = "xdecor_candle_ceiling.png",
81                         animation = {type="vertical_frames", length=1.5} },
82                 { name = "xdecor_candle_wall.png",
83                         animation = {type="vertical_frames", length=1.5} }
84         },
85         selection_box = {
86                 type = "wallmounted",
87                 wall_top = {-0.3, -0.4, -0.3, 0.3, 0.5, 0.3},
88                 wall_bottom = {-0.25, -0.5, -0.25, 0.25, 0.1, 0.25},
89                 wall_side = {-0.5, -0.35, -0.15, -0.15, 0.4, 0.15}
90         }
91 })
92
93 xdecor.register("chair", {
94         description = "Chair",
95         tiles = {"xdecor_wood.png"},
96         sounds = default.node_sound_wood_defaults(),
97         groups = {choppy=3, oddly_breakable_by_hand=2, flammable=3},
98         on_rotate = screwdriver.rotate_simple,
99         node_box = xdecor.pixelbox(16, {
100                 {3,  0, 11,   2, 16, 2},
101                 {11, 0, 11,   2, 16, 2},
102                 {5,  9, 11.5, 6,  6, 1},
103                 {3,  0,  3,   2,  6, 2},
104                 {11, 0,  3,   2,  6, 2},
105                 {3,  6,  3,   10, 2, 8}
106         }),
107         can_dig = xdecor.sit_dig,
108         on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
109                 pos.y = pos.y + 0  -- Sitting position.
110                 xdecor.sit(pos, node, clicker, pointed_thing)
111         end
112 })
113
114 xpanes.register_pane("chainlink", {
115         description = "Chain Link",
116         tiles = {"xdecor_chainlink.png"},
117         drawtype = "airlike",
118         paramtype = "light",
119         textures = {"xdecor_chainlink.png", "xdecor_chainlink.png", "xpanes_space.png"},
120         inventory_image = "xdecor_chainlink.png",
121         wield_image = "xdecor_chainlink.png",
122         groups = {cracky=3, oddly_breakable_by_hand=2, pane=1},
123         recipe = {
124                 {"default:steel_ingot", "", "default:steel_ingot"},
125                 {"", "default:steel_ingot", ""},
126                 {"default:steel_ingot", "", "default:steel_ingot"}
127         }
128 })
129
130 -- The following nodedef is licensed under WTFPL for granting a possible re-use
131 -- in Minetest Game (https://github.com/minetest/minetest_game). 
132 xdecor.register("cobweb", {
133         description = "Cobweb",
134         drawtype = "plantlike",
135         tiles = {"xdecor_cobweb.png"},
136         inventory_image = "xdecor_cobweb.png",
137         liquid_viscosity = 8,
138         liquidtype = "source",
139         liquid_alternative_flowing = "xdecor:cobweb",
140         liquid_alternative_source = "xdecor:cobweb",
141         liquid_renewable = false,
142         liquid_range = 0,
143         walkable = false,
144         selection_box = {type = "regular"},
145         groups = {dig_immediate=3, liquid=3, flammable=3},
146         sounds = default.node_sound_leaves_defaults()
147 })
148
149 for _, c in pairs({"red"}) do  -- Add more curtains colors simply here.
150         xdecor.register("curtain_"..c, {
151                 description = c:gsub("^%l", string.upper).." Curtain",
152                 walkable = false,
153                 tiles = {"wool_white.png^[colorize:"..c..":170"},
154                 inventory_image = "wool_white.png^[colorize:"..c..":170^xdecor_curtain_open_overlay.png^[makealpha:255,126,126",
155                 wield_image = "wool_white.png^[colorize:"..c..":170",
156                 drawtype = "signlike",
157                 paramtype2 = "wallmounted",
158                 groups = {dig_immediate=3, flammable=3},
159                 selection_box = {type="wallmounted"},
160                 on_rightclick = function(pos, node)
161                         minetest.set_node(pos, {name="xdecor:curtain_open_"..c, param2=node.param2})
162                 end
163         })
164
165         xdecor.register("curtain_open_"..c, {
166                 tiles = {"wool_white.png^[colorize:"..c..":170^xdecor_curtain_open_overlay.png^[makealpha:255,126,126"},
167                 drawtype = "signlike",
168                 paramtype2 = "wallmounted",
169                 walkable = false,
170                 groups = {dig_immediate=3, flammable=3, not_in_creative_inventory=1},
171                 selection_box = {type="wallmounted"},
172                 drop = "xdecor:curtain_"..c,
173                 on_rightclick = function(pos, node)
174                         minetest.set_node(pos, {name="xdecor:curtain_"..c, param2=node.param2})
175                 end
176         })
177
178         minetest.register_craft({
179                 output = "xdecor:curtain_"..c.." 4",
180                 recipe = {
181                         {"", "wool:"..c, ""},
182                         {"", "wool:"..c, ""}
183                 }
184         })
185 end
186
187 xdecor.register("crate", {
188         description = "Crate",
189         inventory = {size=24},
190         infotext = "Crate",
191         tiles = {"xdecor_crate.png"},
192         groups = {choppy=2, oddly_breakable_by_hand=1, flammable=3},
193         sounds = default.node_sound_wood_defaults()
194 })
195
196 xdecor.register("cushion", {
197         description = "Cushion",
198         tiles = {"xdecor_cushion.png"},
199         groups = {snappy=3, flammable=3, fall_damage_add_percent=-50},
200         on_place = minetest.rotate_node,
201         node_box = xdecor.nodebox.slab_y(0.5),
202         can_dig = xdecor.sit_dig,
203         on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
204                 pos.y = pos.y + 0
205                 xdecor.sit(pos, node, clicker, pointed_thing)
206
207                 local wield_item = clicker:get_wielded_item():get_name()
208                 if wield_item == "xdecor:cushion" and clicker:get_player_control().sneak then
209                         local player_name = clicker:get_player_name()
210                         if minetest.is_protected(pos, player_name) then
211                                 minetest.record_protection_violation(pos, player_name) return
212                         end
213
214                         minetest.set_node(pos, {name="xdecor:cushion_block", param2=node.param2})
215
216                         if not minetest.setting_getbool("creative_mode") then
217                                 itemstack:take_item()
218                         end
219                         return itemstack
220                 end
221         end
222 })
223
224 xdecor.register("cushion_block", {
225         tiles = {"xdecor_cushion.png"},
226         groups = {snappy=3, flammable=3, fall_damage_add_percent=-75, not_in_creative_inventory=1},
227         drop = "xdecor:cushion 2"
228 })
229
230 local function door_access(door)
231         return door:sub(1,6) == "prison"
232 end
233
234 local door_types = {
235         {"japanese", "brown"}, {"prison", "grey"}, {"prison_rust", "rust"},
236         {"screen", "brownb"}, {"slide", "brownc"}, {"woodglass", "brown"}
237 }
238
239 for _, d in pairs(door_types) do
240         doors.register_door("xdecor:"..d[1].."_door", {
241                 description = string.gsub(" "..d[1], "%W%l", string.upper):sub(2):gsub("_", " ").." Door",
242                 inventory_image = "xdecor_"..d[1].."_door_inv.png",
243                 groups = {choppy=3, cracky=3, oddly_breakable_by_hand=1, flammable=2, door=1},
244                 tiles_bottom = {"xdecor_"..d[1].."_door_b.png", "xdecor_"..d[2]..".png"},
245                 tiles_top = {"xdecor_"..d[1].."_door_a.png", "xdecor_"..d[2]..".png"},
246                 only_placer_can_open = door_access(d[1]),
247                 sounds = default.node_sound_wood_defaults(),
248                 sunlight = false
249         })
250 end
251
252 xdecor.register("empty_shelf", {
253         description = "Empty Shelf",
254         inventory = {size=24},
255         infotext = "Empty Shelf",
256         tiles = {"default_wood.png", "default_wood.png^xdecor_empty_shelf.png"},
257         groups = {choppy=2, oddly_breakable_by_hand=1, flammable=3},
258         sounds = default.node_sound_wood_defaults(),
259         on_rotate = screwdriver.rotate_simple
260 })
261
262 xdecor.register("enderchest", {
263         description = "Ender Chest",
264         tiles = {
265                 "xdecor_enderchest_top.png", "xdecor_enderchest_top.png",
266                 "xdecor_enderchest_side.png", "xdecor_enderchest_side.png",
267                 "xdecor_enderchest_side.png", "xdecor_enderchest_front.png"
268         },
269         groups = {cracky=1, choppy=1, oddly_breakable_by_hand=1},
270         sounds = default.node_sound_stone_defaults(),
271         on_rotate = screwdriver.rotate_simple,
272         on_construct = function(pos)
273                 local meta = minetest.get_meta(pos)
274                 meta:set_string("formspec", [[ size[8,9]
275                                 list[current_player;enderchest;0,0;8,4;]
276                                 list[current_player;main;0,5;8,4;]
277                                 listring[current_player;enderchest]
278                                 listring[current_player;main] ]]
279                                 ..xbg..default.get_hotbar_bg(0,5))
280                 meta:set_string("infotext", "Ender Chest")
281         end
282 })
283
284 minetest.register_on_joinplayer(function(player)
285         local inv = player:get_inventory()
286         inv:set_size("enderchest", 8*4)
287 end)
288
289 xdecor.register("fire", {
290         description = "Fancy Fire",
291         drawtype = "plantlike",
292         light_source = 14,
293         walkable = false,
294         tiles = {
295                 { name = "xdecor_fire_anim.png",
296                 animation = {type="vertical_frames", length=1.5} }
297         },
298         damage_per_second = 4,
299         drop = "",
300         selection_box = {
301                 type = "fixed", fixed = {-0.3, -0.5, -0.3, 0.3, -0.3, 0.3}
302         },
303         groups = {dig_immediate=3, hot=3, not_in_creative_inventory=1}
304 })
305
306 xdecor.register("ivy", {
307         description = "Ivy",
308         drawtype = "signlike",
309         walkable = false,
310         climbable = true,
311         groups = {dig_immediate=3, flammable=3, plant=1},
312         paramtype2 = "wallmounted",
313         selection_box = {type="wallmounted"},
314         legacy_wallmounted = true,
315         tiles = {"xdecor_ivy.png"},
316         inventory_image = "xdecor_ivy.png",
317         wield_image = "xdecor_ivy.png",
318         sounds = default.node_sound_leaves_defaults()
319 })
320
321 xdecor.register("lantern", {
322         description = "Lantern",
323         light_source = 12,
324         drawtype = "torchlike",
325         inventory_image = "xdecor_lantern_floor.png",
326         wield_image = "xdecor_lantern_floor.png", 
327         paramtype2 = "wallmounted",
328         legacy_wallmounted = true,
329         walkable = false,
330         groups = {dig_immediate=3, attached_node=1},
331         tiles = {"xdecor_lantern_floor.png", "xdecor_lantern_ceiling.png",
332                         "xdecor_lantern.png"},
333         selection_box = {
334                 type = "wallmounted",
335                 wall_top = {-0.25, -0.4, -0.25, 0.25, 0.5, 0.25},
336                 wall_bottom = {-0.25, -0.5, -0.25, 0.25, 0.4, 0.25},
337                 wall_side = {-0.5, -0.5, -0.15, 0.5, 0.5, 0.15}
338         }
339 })
340
341 for _, l in pairs({"iron", "wooden"}) do
342         xdecor.register(l.."_lightbox", {
343                 description = l:gsub("^%l", string.upper).." Light Box",
344                 tiles = {"xdecor_"..l.."_lightbox.png"},
345                 groups = {cracky=3, choppy=3, oddly_breakable_by_hand=2},
346                 light_source = 13,
347                 sounds = default.node_sound_glass_defaults()
348         })
349 end
350
351 minetest.register_alias("xdecor:lightbox", "xdecor:wooden_lightbox")
352
353 xdecor.register("packed_ice", {
354         drawtype = "normal",
355         description = "Packed Ice",
356         tiles = {"xdecor_packed_ice.png"},
357         groups = {cracky=1, puts_out_fire=1},
358         sounds = default.node_sound_glass_defaults()
359 })
360
361 local flowers = {"dandelion_white", "dandelion_yellow", "geranium", "rose",
362                 "tulip", "viola"}
363
364 for _, f in pairs(flowers) do
365         xdecor.register("potted_"..f, {
366                 description = string.gsub("Potted Flowers ("..f..")", "_", " "),
367                 walkable = false,
368                 groups = {dig_immediate=3, flammable=3, plant=1, flower=1},
369                 tiles = {"xdecor_"..f.."_pot.png"},
370                 inventory_image = "xdecor_"..f.."_pot.png",
371                 drawtype = "plantlike",
372                 sounds = default.node_sound_leaves_defaults(),
373                 selection_box = xdecor.nodebox.slab_y(0.3)
374         })
375
376         minetest.register_craft({
377                 output = "xdecor:potted_"..f,
378                 recipe = {
379                         {"default:clay_brick", "flowers:"..f, "default:clay_brick"},
380                         {"", "default:clay_brick", ""}
381                 }
382         })
383 end
384
385 xdecor.register("painting_1", {
386         description = "Painting",
387         tiles = {"xdecor_painting_1.png"},
388         inventory_image = "xdecor_painting_empty.png",
389         wield_image = "xdecor_painting_empty.png",
390         paramtype2 = "wallmounted",
391         legacy_wallmounted = true,
392         wield_image = "xdecor_painting_empty.png",
393         sunlight_propagates = true,
394         groups = {choppy=3, oddly_breakable_by_hand=2, flammable=3, attached_node=1},
395         sounds = default.node_sound_wood_defaults(),
396         node_box = {
397                 type = "wallmounted",
398                 wall_top = {-0.4375, 0.4375, -0.3125, 0.4375, 0.5, 0.3125},
399                 wall_bottom = {-0.4375, -0.5, -0.3125, 0.4375, -0.4375, 0.3125},
400                 wall_side = {-0.5, -0.3125, -0.4375, -0.4375, 0.3125, 0.4375}
401         },
402         on_construct = function(pos)
403                 local node = minetest.get_node(pos)
404                 local random = math.random(4)
405                 if random == 1 then return end
406                 minetest.set_node(pos, {name="xdecor:painting_"..random, param2=node.param2})
407         end
408 })
409
410 for i = 2, 4 do
411         xdecor.register("painting_"..i, {
412                 tiles = {"xdecor_painting_"..i..".png"},
413                 paramtype2 = "wallmounted",
414                 legacy_wallmounted = true,
415                 drop = "xdecor:painting_1",
416                 sunlight_propagates = true,
417                 groups = {choppy=3, oddly_breakable_by_hand=2, flammable=3, attached_node=1, not_in_creative_inventory=1},
418                 sounds = default.node_sound_wood_defaults(),
419                 node_box = {
420                         type = "wallmounted",
421                         wall_top = {-0.4375, 0.4375, -0.3125, 0.4375, 0.5, 0.3125},
422                         wall_bottom = {-0.4375, -0.5, -0.3125, 0.4375, -0.4375, 0.3125},
423                         wall_side = {-0.5, -0.3125, -0.4375, -0.4375, 0.3125, 0.4375}
424                 }
425         })
426 end
427
428 for _, b in pairs({{"cactus", "cactus"}, {"moon", "stone"}}) do
429         xdecor.register(b[1].."brick", {
430                 drawtype = "normal",
431                 description = b[1]:gsub("^%l", string.upper).." Brick",
432                 tiles = {"xdecor_"..b[1].."brick.png"},
433                 groups = {cracky=2},
434                 sounds = default.node_sound_stone_defaults(),
435         })
436         
437         minetest.register_craft({
438         output = "xdecor:"..b[1].."brick",
439         recipe = {
440                 {"default:brick", "default:"..b[2]}
441         }
442 })
443 end
444
445 xdecor.register("multishelf", {
446         description = "Multi Shelf",
447         inventory = {size=24},
448         infotext = "Multi Shelf",
449         on_rotate = screwdriver.rotate_simple,
450         tiles = {"default_wood.png", "default_wood.png^xdecor_multishelf.png"},
451         groups = {choppy=2, oddly_breakable_by_hand=1, flammable=3},
452         sounds = default.node_sound_wood_defaults()
453 })
454
455 xpanes.register_pane("rust_bar", {
456         description = "Rust Bars",
457         tiles = {"xdecor_rust_bars.png"},
458         drawtype = "airlike",
459         paramtype = "light",
460         textures = {"xdecor_rust_bars.png", "xdecor_rust_bars.png", "xpanes_space.png"},
461         inventory_image = "xdecor_rust_bars.png",
462         wield_image = "xdecor_rust_bars.png",
463         groups = {cracky=3, oddly_breakable_by_hand=2, pane=1},
464         recipe = {
465                 {"", "default:dirt", ""},
466                 {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
467                 {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}
468         }
469 })
470
471 xdecor.register("stonepath", {
472         description = "Garden Stone Path",
473         tiles = {"default_stone.png"},
474         groups = {snappy=3},
475         on_rotate = screwdriver.rotate_simple,
476         sounds = default.node_sound_stone_defaults(),
477         sunlight_propagates = true,
478         node_box = xdecor.pixelbox(16, {
479                 {8,  0,  8, 6, .5, 6},
480                 {1,  0,  1, 6, .5, 6},
481                 {1,  0, 10, 5, .5, 5},
482                 {10, 0,  2, 4, .5, 4}
483         }),
484         selection_box = xdecor.nodebox.slab_y(0.05)
485 })
486
487 local stonish = {"desertstone_tile", "stone_tile", "stone_rune",
488                 "coalstone_tile", "hard_clay"}
489
490 for _, t in pairs(stonish) do
491         xdecor.register(t, {
492                 drawtype = "normal",
493                 description = string.gsub(" "..t, "%W%l", string.upper):sub(2):gsub("_", " "),
494                 tiles = {"xdecor_"..t..".png"},
495                 groups = {cracky=1},
496                 sounds = default.node_sound_stone_defaults()
497         })
498 end
499
500 xdecor.register("table", {
501         description = "Table",
502         tiles = {"xdecor_wood.png"},
503         groups = {choppy=3, oddly_breakable_by_hand=2, flammable=3},
504         sounds = default.node_sound_wood_defaults(),
505         node_box = xdecor.pixelbox(16, {
506                 {0, 14, 0, 16, 2, 16}, {5.5, 0, 5.5, 5, 14, 6}
507         })
508 })
509
510 xdecor.register("tatami", {
511         description = "Tatami",
512         tiles = {"xdecor_tatami.png"},
513         wield_image = "xdecor_tatami.png",
514         groups = {snappy=3, flammable=3},
515         node_box = xdecor.nodebox.slab_y(0.0625)
516 })
517
518 xdecor.register("tv", {
519         description = "Television",
520         light_source = 11,
521         groups = {snappy=3},
522         on_rotate = screwdriver.rotate_simple,
523         tiles = {
524                 "xdecor_television_left.png^[transformR270",
525                 "xdecor_television_left.png^[transformR90",
526                 "xdecor_television_left.png^[transformFX",
527                 "xdecor_television_left.png", "xdecor_television_back.png",
528                 { name = "xdecor_television_front_animated.png",
529                         animation = {type="vertical_frames", length=80.0} }
530         }
531 })
532
533 xpanes.register_pane("wood_frame", {
534         description = "Wood Frame",
535         tiles = {"xdecor_wood_frame.png"},
536         drawtype = "airlike",
537         paramtype = "light",
538         textures = {"xdecor_wood_frame.png", "xdecor_wood_frame.png", "xpanes_space.png"},
539         inventory_image = "xdecor_wood_frame.png",
540         wield_image = "xdecor_wood_frame.png",
541         groups = {choppy=3, oddly_breakable_by_hand=2, pane=1, flammable=3},
542         sounds = default.node_sound_wood_defaults(),
543         recipe = {
544                 {"group:wood", "group:stick", "group:wood"},
545                 {"group:stick", "group:stick", "group:stick"},
546                 {"group:wood", "group:stick", "group:wood"}
547         }
548 })
549
550 xdecor.register("woodframed_glass", {
551         description = "Wood Framed Glass",
552         drawtype = "glasslike_framed",
553         tiles = {"xdecor_woodframed_glass.png", "xdecor_woodframed_glass_detail.png"},
554         groups = {cracky=3, oddly_breakable_by_hand=2},
555         sounds = default.node_sound_glass_defaults()
556 })
557
558 xdecor.register("wood_tile", {
559         description = "Wood Tile",
560         tiles = {"xdecor_wood_tile.png"},
561         drawtype = "normal",
562         groups = {choppy=1, oddly_breakable_by_hand=1, wood=1, flammable=2},
563         sounds = default.node_sound_wood_defaults()
564 })