Creative: Make the placenode registration check for non-player placers
[oweals/minetest_game.git] / mods / default / torch.lua
1
2 --[[
3
4 Torch mod - formerly mod "Torches"
5 ======================
6
7 (c) Copyright BlockMen (2013-2015)
8 (C) Copyright sofar <sofar@foo-projects.org> (2016)
9
10 This mod changes the default torch drawtype from "torchlike" to "mesh",
11 giving the torch a three dimensional appearance. The mesh contains the
12 proper pixel mapping to make the animation appear as a particle above
13 the torch, while in fact the animation is just the texture of the mesh.
14
15
16 License:
17 ~~~~~~~~
18 (c) Copyright BlockMen (2013-2015)
19
20 Textures and Meshes/Models:
21 CC-BY 3.0 BlockMen
22 Note that the models were entirely done from scratch by sofar.
23
24 Code:
25 Licensed under the GNU LGPL version 2.1 or higher.
26 You can redistribute it and/or modify it under
27 the terms of the GNU Lesser General Public License
28 as published by the Free Software Foundation;
29
30 You should have received a copy of the GNU Lesser General Public
31 License along with this library; if not, write to the Free Software
32 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
33
34 See LICENSE.txt and http://www.gnu.org/licenses/lgpl-2.1.txt
35
36 --]]
37
38 minetest.register_node("default:torch", {
39         description = "Torch",
40         drawtype = "mesh",
41         mesh = "torch_floor.obj",
42         inventory_image = "default_torch_on_floor.png",
43         wield_image = "default_torch_on_floor.png",
44         tiles = {{
45                     name = "default_torch_on_floor_animated.png",
46                     animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
47         }},
48         paramtype = "light",
49         paramtype2 = "wallmounted",
50         sunlight_propagates = true,
51         walkable = false,
52         liquids_pointable = false,
53         light_source = 12,
54         groups = {choppy=2, dig_immediate=3, flammable=1, attached_node=1, torch=1},
55         drop = "default:torch",
56         selection_box = {
57                 type = "wallmounted",
58                 wall_bottom = {-1/8, -1/2, -1/8, 1/8, 2/16, 1/8},
59         },
60         sounds = default.node_sound_wood_defaults(),
61         on_place = function(itemstack, placer, pointed_thing)
62                 local under = pointed_thing.under
63                 local node = minetest.get_node(under)
64                 local def = minetest.registered_nodes[node.name]
65                 if def and def.on_rightclick and
66                         ((not placer) or (placer and not placer:get_player_control().sneak)) then
67                         return def.on_rightclick(under, node, placer, itemstack,
68                                 pointed_thing) or itemstack
69                 end
70
71                 local above = pointed_thing.above
72                 local wdir = minetest.dir_to_wallmounted(vector.subtract(under, above))
73                 local fakestack = itemstack
74                 if wdir == 0 then
75                         fakestack:set_name("default:torch_ceiling")
76                 elseif wdir == 1 then
77                         fakestack:set_name("default:torch")
78                 else
79                         fakestack:set_name("default:torch_wall")
80                 end
81
82                 itemstack = minetest.item_place(fakestack, placer, pointed_thing, wdir)
83                 itemstack:set_name("default:torch")
84
85                 return itemstack
86         end
87 })
88
89 minetest.register_node("default:torch_wall", {
90         drawtype = "mesh",
91         mesh = "torch_wall.obj",
92         tiles = {{
93                     name = "default_torch_on_floor_animated.png",
94                     animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
95         }},
96         paramtype = "light",
97         paramtype2 = "wallmounted",
98         sunlight_propagates = true,
99         walkable = false,
100         light_source = 12,
101         groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
102         drop = "default:torch",
103         selection_box = {
104                 type = "wallmounted",
105                 wall_side = {-1/2, -1/2, -1/8, -1/8, 1/8, 1/8},
106         },
107         sounds = default.node_sound_wood_defaults(),
108 })
109
110 minetest.register_node("default:torch_ceiling", {
111         drawtype = "mesh",
112         mesh = "torch_ceiling.obj",
113         tiles = {{
114                     name = "default_torch_on_floor_animated.png",
115                     animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
116         }},
117         paramtype = "light",
118         paramtype2 = "wallmounted",
119         sunlight_propagates = true,
120         walkable = false,
121         light_source = 12,
122         groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1},
123         drop = "default:torch",
124         selection_box = {
125                 type = "wallmounted",
126                 wall_top = {-1/8, -1/16, -5/16, 1/8, 1/2, 1/8},
127         },
128         sounds = default.node_sound_wood_defaults(),
129 })
130
131 minetest.register_lbm({
132         name = "default:3dtorch",
133         nodenames = {"default:torch", "torches:floor", "torches:wall"},
134         action = function(pos, node)
135                 if node.param2 == 0 then
136                         minetest.set_node(pos, {name = "default:torch_ceiling",
137                                 param2 = node.param2})
138                 elseif node.param2 == 1 then
139                         minetest.set_node(pos, {name = "default:torch",
140                                 param2 = node.param2})
141                 else
142                         minetest.set_node(pos, {name = "default:torch_wall",
143                                 param2 = node.param2})
144                 end
145         end
146 })