Remove cave ice from creative inventory
[oweals/minetest_game.git] / mods / default / torch.lua
1 local function on_flood(pos, oldnode, newnode)
2         minetest.add_item(pos, ItemStack("default:torch 1"))
3         -- Play flame-extinguish sound if liquid is not an 'igniter'
4         local nodedef = minetest.registered_items[newnode.name]
5         if not (nodedef and nodedef.groups and
6                         nodedef.groups.igniter and nodedef.groups.igniter > 0) then
7                 minetest.sound_play(
8                         "default_cool_lava",
9                         {pos = pos, max_hear_distance = 16, gain = 0.1}
10                 )
11         end
12         -- Remove the torch node
13         return false
14 end
15
16 minetest.register_node("default:torch", {
17         description = "Torch",
18         drawtype = "mesh",
19         mesh = "torch_floor.obj",
20         inventory_image = "default_torch_on_floor.png",
21         wield_image = "default_torch_on_floor.png",
22         tiles = {{
23                     name = "default_torch_on_floor_animated.png",
24                     animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
25         }},
26         paramtype = "light",
27         paramtype2 = "wallmounted",
28         sunlight_propagates = true,
29         walkable = false,
30         liquids_pointable = false,
31         light_source = 12,
32         groups = {choppy=2, dig_immediate=3, flammable=1, attached_node=1, torch=1},
33         drop = "default:torch",
34         selection_box = {
35                 type = "wallmounted",
36                 wall_bottom = {-1/8, -1/2, -1/8, 1/8, 2/16, 1/8},
37         },
38         sounds = default.node_sound_wood_defaults(),
39         on_place = function(itemstack, placer, pointed_thing)
40                 local under = pointed_thing.under
41                 local node = minetest.get_node(under)
42                 local def = minetest.registered_nodes[node.name]
43                 if def and def.on_rightclick and
44                         not (placer and placer:is_player() and
45                         placer:get_player_control().sneak) then
46                         return def.on_rightclick(under, node, placer, itemstack,
47                                 pointed_thing) or itemstack
48                 end
49
50                 local above = pointed_thing.above
51                 local wdir = minetest.dir_to_wallmounted(vector.subtract(under, above))
52                 local fakestack = itemstack
53                 if wdir == 0 then
54                         fakestack:set_name("default:torch_ceiling")
55                 elseif wdir == 1 then
56                         fakestack:set_name("default:torch")
57                 else
58                         fakestack:set_name("default:torch_wall")
59                 end
60
61                 itemstack = minetest.item_place(fakestack, placer, pointed_thing, wdir)
62                 itemstack:set_name("default:torch")
63
64                 return itemstack
65         end,
66         floodable = true,
67         on_flood = on_flood,
68 })
69
70 minetest.register_node("default:torch_wall", {
71         drawtype = "mesh",
72         mesh = "torch_wall.obj",
73         tiles = {{
74                     name = "default_torch_on_floor_animated.png",
75                     animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
76         }},
77         paramtype = "light",
78         paramtype2 = "wallmounted",
79         sunlight_propagates = true,
80         walkable = false,
81         light_source = 12,
82         groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
83         drop = "default:torch",
84         selection_box = {
85                 type = "wallmounted",
86                 wall_side = {-1/2, -1/2, -1/8, -1/8, 1/8, 1/8},
87         },
88         sounds = default.node_sound_wood_defaults(),
89         floodable = true,
90         on_flood = on_flood,
91 })
92
93 minetest.register_node("default:torch_ceiling", {
94         drawtype = "mesh",
95         mesh = "torch_ceiling.obj",
96         tiles = {{
97                     name = "default_torch_on_floor_animated.png",
98                     animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
99         }},
100         paramtype = "light",
101         paramtype2 = "wallmounted",
102         sunlight_propagates = true,
103         walkable = false,
104         light_source = 12,
105         groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
106         drop = "default:torch",
107         selection_box = {
108                 type = "wallmounted",
109                 wall_top = {-1/8, -1/16, -5/16, 1/8, 1/2, 1/8},
110         },
111         sounds = default.node_sound_wood_defaults(),
112         floodable = true,
113         on_flood = on_flood,
114 })
115
116 minetest.register_lbm({
117         name = "default:3dtorch",
118         nodenames = {"default:torch", "torches:floor", "torches:wall"},
119         action = function(pos, node)
120                 if node.param2 == 0 then
121                         minetest.set_node(pos, {name = "default:torch_ceiling",
122                                 param2 = node.param2})
123                 elseif node.param2 == 1 then
124                         minetest.set_node(pos, {name = "default:torch",
125                                 param2 = node.param2})
126                 else
127                         minetest.set_node(pos, {name = "default:torch_wall",
128                                 param2 = node.param2})
129                 end
130         end
131 })