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