1 local S
= minetest
.get_translator("mcl_torches")
2 local LIGHT_TORCH
= minetest
.LIGHT_MAX
4 local spawn_flames_floor
= function(pos
)
6 mcl_particles
.add_node_particlespawner(pos
, {
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 },
17 texture
= "mcl_particles_flame.png",
21 mcl_particles
.add_node_particlespawner(pos
, {
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 },
32 texture
= "mcl_particles_smoke_anim.png",
34 type = "vertical_frames",
42 local spawn_flames_wall
= function(pos
, param2
)
43 local minrelpos
, maxrelpos
44 local dir
= minetest
.wallmounted_to_dir(param2
)
46 minrelpos
= { x
= -0.38, y
= 0.04, z
= -0.1 }
47 maxrelpos
= { x
= -0.2, y
= 0.14, z
= 0.1 }
49 minrelpos
= { x
= 0.2, y
= 0.04, z
= -0.1 }
50 maxrelpos
= { x
= 0.38, y
= 0.14, z
= 0.1 }
52 minrelpos
= { x
= -0.1, y
= 0.04, z
= -0.38 }
53 maxrelpos
= { x
= 0.1, y
= 0.14, z
= -0.2 }
55 minrelpos
= { x
= -0.1, y
= 0.04, z
= 0.2 }
56 maxrelpos
= { x
= 0.1, y
= 0.14, z
= 0.38 }
61 mcl_particles
.add_node_particlespawner(pos
, {
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 },
72 texture
= "mcl_particles_flame.png",
76 mcl_particles
.add_node_particlespawner(pos
, {
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 },
87 texture
= "mcl_particles_smoke_anim.png",
89 type = "vertical_frames",
97 local remove_flames
= function(pos
)
98 mcl_particles
.delete_node_particlespawners(pos
)
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:
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
]
121 -- No ceiling torches
122 elseif wdir
== 0 then
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
135 elseif minetest
.get_item_group(node
.name
, "piston") >= 1 then
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
155 groups
.dig_by_water
= 1
156 groups
.destroy_by_lava_flow
= 1
157 groups
.dig_by_piston
= 1
160 description
= description
,
161 _doc_items_longdesc
= doc_items_longdesc
,
162 _doc_items_usagehelp
= doc_items_usagehelp
,
165 inventory_image
= icon
,
169 paramtype2
= "wallmounted",
170 sunlight_propagates
= true,
171 is_ground_content
= false,
173 liquids_pointable
= false,
174 light_source
= light
,
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},
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.
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
209 local itemstring
= itemstack
:get_name()
210 local fakestack
= ItemStack(itemstack
)
211 local idef
= fakestack
:get_definition()
215 retval
= fakestack
:set_name(itemstring
)
217 retval
= fakestack
:set_name(itemstring_wall
)
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)
234 if moredef
~= nil then
235 for k
,v
in pairs(moredef
) do
239 if moredef_floor
~= nil then
240 for k
,v
in pairs(moredef_floor
) do
244 minetest
.register_node(itemstring
, floordef
)
246 local groups_wall
= table.copy(groups
)
247 groups_wall
.torch
= 2
254 paramtype2
= "wallmounted",
255 sunlight_propagates
= true,
256 is_ground_content
= false,
258 light_source
= light
,
259 groups
= groups_wall
,
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},
270 if moredef
~= nil then
271 for k
,v
in pairs(moredef
) do
275 if moredef_wall
~= nil then
276 for k
,v
in pairs(moredef_wall
) do
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",
292 S("Torches are light sources which can be placed at the side or on the top of most blocks."),
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}
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
)
307 {on_construct
= function(pos
)
308 spawn_flames_floor(pos
)
310 {on_construct
= function(pos
)
311 local node
= minetest
.get_node(pos
)
312 spawn_flames_wall(pos
, node
.param2
)
315 minetest
.register_craft({
316 output
= "mcl_torches:torch 4",
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
)