Update helptext of obsidian
[MineClone/MineClone2.git] / mods / ITEMS / mcl_torches / init.lua
blob179308358ecb6ee7b244a05408466031a3eca306
1 local S = minetest.get_translator("mcl_torches")
2 local LIGHT_TORCH = minetest.LIGHT_MAX
4 local spawn_flames_floor = function(pos)
5 -- Flames
6 mcl_particles.add_node_particlespawner(pos, {
7 amount = 8,
8 time = 0,
9 minpos = vector.add(pos, { x = -0.1, y = 0.05, z = -0.1 }),
10 maxpos = vector.add(pos, { x = 0.1, y = 0.15, z = 0.1 }),
11 minvel = { x = -0.01, y = 0, z = -0.01 },
12 maxvel = { x = 0.01, y = 0.1, z = 0.01 },
13 minexptime = 0.3,
14 maxexptime = 0.6,
15 minsize = 0.7,
16 maxsize = 2,
17 texture = "mcl_particles_flame.png",
18 glow = LIGHT_TORCH,
19 }, "low")
20 -- Smoke
21 mcl_particles.add_node_particlespawner(pos, {
22 amount = 0.5,
23 time = 0,
24 minpos = vector.add(pos, { x = -1/16, y = 0.04, z = -1/16 }),
25 maxpos = vector.add(pos, { x = -1/16, y = 0.06, z = -1/16 }),
26 minvel = { x = 0, y = 0.5, z = 0 },
27 maxvel = { x = 0, y = 0.6, z = 0 },
28 minexptime = 2.0,
29 maxexptime = 2.0,
30 minsize = 1.5,
31 maxsize = 1.5,
32 texture = "mcl_particles_smoke_anim.png",
33 animation = {
34 type = "vertical_frames",
35 aspect_w = 8,
36 aspect_h = 8,
37 length = 2.05,
39 }, "medium")
40 end
42 local spawn_flames_wall = function(pos, param2)
43 local minrelpos, maxrelpos
44 local dir = minetest.wallmounted_to_dir(param2)
45 if dir.x < 0 then
46 minrelpos = { x = -0.38, y = 0.04, z = -0.1 }
47 maxrelpos = { x = -0.2, y = 0.14, z = 0.1 }
48 elseif dir.x > 0 then
49 minrelpos = { x = 0.2, y = 0.04, z = -0.1 }
50 maxrelpos = { x = 0.38, y = 0.14, z = 0.1 }
51 elseif dir.z < 0 then
52 minrelpos = { x = -0.1, y = 0.04, z = -0.38 }
53 maxrelpos = { x = 0.1, y = 0.14, z = -0.2 }
54 elseif dir.z > 0 then
55 minrelpos = { x = -0.1, y = 0.04, z = 0.2 }
56 maxrelpos = { x = 0.1, y = 0.14, z = 0.38 }
57 else
58 return
59 end
60 -- Flames
61 mcl_particles.add_node_particlespawner(pos, {
62 amount = 8,
63 time = 0,
64 minpos = vector.add(pos, minrelpos),
65 maxpos = vector.add(pos, maxrelpos),
66 minvel = { x = -0.01, y = 0, z = -0.01 },
67 maxvel = { x = 0.01, y = 0.1, z = 0.01 },
68 minexptime = 0.3,
69 maxexptime = 0.6,
70 minsize = 0.7,
71 maxsize = 2,
72 texture = "mcl_particles_flame.png",
73 glow = LIGHT_TORCH,
74 }, "low")
75 -- Smoke
76 mcl_particles.add_node_particlespawner(pos, {
77 amount = 0.5,
78 time = 0,
79 minpos = vector.add(pos, minrelpos),
80 maxpos = vector.add(pos, maxrelpos),
81 minvel = { x = 0, y = 0.5, z = 0 },
82 maxvel = { x = 0, y = 0.6, z = 0 },
83 minexptime = 2.0,
84 maxexptime = 2.0,
85 minsize = 1.5,
86 maxsize = 1.5,
87 texture = "mcl_particles_smoke_anim.png",
88 animation = {
89 type = "vertical_frames",
90 aspect_w = 8,
91 aspect_h = 8,
92 length = 2.05,
94 }, "medium")
95 end
97 local remove_flames = function(pos)
98 mcl_particles.delete_node_particlespawners(pos)
99 end
102 -- 3d torch part
105 -- Check if placement at given node is allowed
106 local function check_placement_allowed(node, wdir)
107 -- Torch placement rules: Disallow placement on some nodes. General rule: Solid, opaque, full cube collision box nodes are allowed.
108 -- Special allowed nodes:
109 -- * soul sand
110 -- * mob spawner
111 -- * chorus flower
112 -- * glass, barrier, ice
113 -- * Fence, wall, end portal frame with ender eye: Only on top
114 -- * Slab, stairs: Only on top if upside down
116 -- Special forbidden nodes:
117 -- * Piston, sticky piston
118 local def = minetest.registered_nodes[node.name]
119 if not def then
120 return false
121 -- No ceiling torches
122 elseif wdir == 0 then
123 return false
124 elseif not def.buildable_to then
125 if node.name ~= "mcl_core:ice" and node.name ~= "mcl_nether:soul_sand" and node.name ~= "mcl_mobspawners:spawner" and node.name ~= "mcl_core:barrier" and node.name ~= "mcl_end:chorus_flower" and node.name ~= "mcl_end:chorus_flower_dead" and (not def.groups.glass) and
126 ((not def.groups.solid) or (not def.groups.opaque)) then
127 -- Only allow top placement on these nodes
128 if node.name == "mcl_end:dragon_egg" or node.name == "mcl_portals:end_portal_frame_eye" or def.groups.fence == 1 or def.groups.wall or def.groups.slab_top == 1 or def.groups.anvil or def.groups.pane or (def.groups.stair == 1 and minetest.facedir_to_dir(node.param2).y ~= 0) then
129 if wdir ~= 1 then
130 return false
132 else
133 return false
135 elseif minetest.get_item_group(node.name, "piston") >= 1 then
136 return false
139 return true
142 mcl_torches = {}
144 mcl_torches.register_torch = function(substring, description, doc_items_longdesc, doc_items_usagehelp, icon, mesh_floor, mesh_wall, tiles, light, groups, sounds, moredef, moredef_floor, moredef_wall)
145 local itemstring = minetest.get_current_modname()..":"..substring
146 local itemstring_wall = minetest.get_current_modname()..":"..substring.."_wall"
148 if light == nil then light = minetest.LIGHT_MAX end
149 if mesh_floor == nil then mesh_floor = "mcl_torches_torch_floor.obj" end
150 if mesh_wall == nil then mesh_wall = "mcl_torches_torch_wall.obj" end
151 if groups == nil then groups = {} end
153 groups.attached_node = 1
154 groups.torch = 1
155 groups.dig_by_water = 1
156 groups.destroy_by_lava_flow = 1
157 groups.dig_by_piston = 1
159 local floordef = {
160 description = description,
161 _doc_items_longdesc = doc_items_longdesc,
162 _doc_items_usagehelp = doc_items_usagehelp,
163 drawtype = "mesh",
164 mesh = mesh_floor,
165 inventory_image = icon,
166 wield_image = icon,
167 tiles = tiles,
168 paramtype = "light",
169 paramtype2 = "wallmounted",
170 sunlight_propagates = true,
171 is_ground_content = false,
172 walkable = false,
173 liquids_pointable = false,
174 light_source = light,
175 groups = groups,
176 drop = itemstring,
177 selection_box = {
178 type = "wallmounted",
179 wall_top = {-1/16, -1/16, -1/16, 1/16, 0.5, 1/16},
180 wall_bottom = {-1/16, -0.5, -1/16, 1/16, 1/16, 1/16},
182 sounds = sounds,
183 node_placement_prediction = "",
184 on_place = function(itemstack, placer, pointed_thing)
185 if pointed_thing.type ~= "node" then
186 -- no interaction possible with entities, for now.
187 return itemstack
190 local under = pointed_thing.under
191 local node = minetest.get_node(under)
192 local def = minetest.registered_nodes[node.name]
193 if not def then return itemstack end
195 -- Call on_rightclick if the pointed node defines it
196 if placer and not placer:get_player_control().sneak then
197 if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
198 return minetest.registered_nodes[node.name].on_rightclick(under, node, placer, itemstack) or itemstack
202 local above = pointed_thing.above
203 local wdir = minetest.dir_to_wallmounted({x = under.x - above.x, y = under.y - above.y, z = under.z - above.z})
205 if check_placement_allowed(node, wdir) == false then
206 return itemstack
209 local itemstring = itemstack:get_name()
210 local fakestack = ItemStack(itemstack)
211 local idef = fakestack:get_definition()
212 local retval
214 if wdir == 1 then
215 retval = fakestack:set_name(itemstring)
216 else
217 retval = fakestack:set_name(itemstring_wall)
219 if not retval then
220 return itemstack
223 local success
224 itemstack, success = minetest.item_place(fakestack, placer, pointed_thing, wdir)
225 itemstack:set_name(itemstring)
227 if success and idef.sounds and idef.sounds.place then
228 minetest.sound_play(idef.sounds.place, {pos=under, gain=1}, true)
230 return itemstack
231 end,
232 on_rotate = false,
234 if moredef ~= nil then
235 for k,v in pairs(moredef) do
236 floordef[k] = v
239 if moredef_floor ~= nil then
240 for k,v in pairs(moredef_floor) do
241 floordef[k] = v
244 minetest.register_node(itemstring, floordef)
246 local groups_wall = table.copy(groups)
247 groups_wall.torch = 2
249 local walldef = {
250 drawtype = "mesh",
251 mesh = mesh_wall,
252 tiles = tiles,
253 paramtype = "light",
254 paramtype2 = "wallmounted",
255 sunlight_propagates = true,
256 is_ground_content = false,
257 walkable = false,
258 light_source = light,
259 groups = groups_wall,
260 drop = itemstring,
261 selection_box = {
262 type = "wallmounted",
263 wall_top = {-0.1, -0.1, -0.1, 0.1, 0.5, 0.1},
264 wall_bottom = {-0.1, -0.5, -0.1, 0.1, 0.1, 0.1},
265 wall_side = {-0.5, -0.5, -0.1, -0.2, 0.1, 0.1},
267 sounds = sounds,
268 on_rotate = false,
270 if moredef ~= nil then
271 for k,v in pairs(moredef) do
272 walldef[k] = v
275 if moredef_wall ~= nil then
276 for k,v in pairs(moredef_wall) do
277 walldef[k] = v
280 minetest.register_node(itemstring_wall, walldef)
283 -- Add entry alias for the Help
284 if minetest.get_modpath("doc") then
285 doc.add_entry_alias("nodes", itemstring, "nodes", itemstring_wall)
290 mcl_torches.register_torch("torch",
291 S("Torch"),
292 S("Torches are light sources which can be placed at the side or on the top of most blocks."),
293 nil,
294 "default_torch_on_floor.png",
295 "mcl_torches_torch_floor.obj", "mcl_torches_torch_wall.obj",
297 name = "default_torch_on_floor_animated.png",
298 animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 3.3}
300 LIGHT_TORCH,
301 {dig_immediate=3, torch=1, deco_block=1},
302 mcl_sounds.node_sound_wood_defaults(),
303 {_doc_items_hidden = false,
304 on_destruct = function(pos)
305 remove_flames(pos)
306 end},
307 {on_construct = function(pos)
308 spawn_flames_floor(pos)
309 end},
310 {on_construct = function(pos)
311 local node = minetest.get_node(pos)
312 spawn_flames_wall(pos, node.param2)
313 end})
315 minetest.register_craft({
316 output = "mcl_torches:torch 4",
317 recipe = {
318 { "group:coal" },
319 { "mcl_core:stick" },
323 minetest.register_lbm({
324 label = "Torch flame particles",
325 name = "mcl_torches:flames",
326 nodenames = {"mcl_torches:torch", "mcl_torches:torch_wall"},
327 run_at_every_load = true,
328 action = function(pos, node)
329 if node.name == "mcl_torches:torch" then
330 spawn_flames_floor(pos)
331 elseif node.name == "mcl_torches:torch_wall" then
332 spawn_flames_wall(pos, node.param2)
334 end,