8 mcl_torches
.register_torch
= function(substring
, description
, doc_items_longdesc
, doc_items_usagehelp
, icon
, mesh_floor
, mesh_wall
, tiles
, light
, groups
, sounds
, moredef
)
9 local itemstring
= minetest
.get_current_modname()..":"..substring
10 local itemstring_wall
= minetest
.get_current_modname()..":"..substring
.."_wall"
12 if light
== nil then light
= 14 end
13 if mesh_floor
== nil then mesh_floor
= "mcl_torches_torch_floor.obj" end
14 if mesh_wall
== nil then mesh_wall
= "mcl_torches_torch_wall.obj" end
15 if groups
== nil then groups
= {} end
17 groups
.attached_node
= 1
19 groups
.dig_by_water
= 1
20 groups
.destroy_by_lava_flow
= 1
21 groups
.dig_by_piston
= 1
24 description
= description
,
25 _doc_items_longdesc
= doc_items_longdesc
,
26 _doc_items_usagehelp
= doc_items_usagehelp
,
29 inventory_image
= icon
,
33 paramtype2
= "wallmounted",
34 sunlight_propagates
= true,
35 is_ground_content
= false,
37 liquids_pointable
= false,
43 wall_top
= {-1/16, -1/16, -1/16, 1/16, 0.5, 1/16},
44 wall_bottom
= {-1/16, -0.5, -1/16, 1/16, 1/16, 1/16},
47 node_placement_prediction
= "",
48 on_place
= function(itemstack
, placer
, pointed_thing
)
49 if pointed_thing
.type ~= "node" then
50 -- no interaction possible with entities, for now.
54 local under
= pointed_thing
.under
55 local node
= minetest
.get_node(under
)
56 local def
= minetest
.registered_nodes
[node
.name
]
57 if not def
then return itemstack
end
59 -- Call on_rightclick if the pointed node defines it
60 if placer
and not placer
:get_player_control().sneak
then
61 if minetest
.registered_nodes
[node
.name
] and minetest
.registered_nodes
[node
.name
].on_rightclick
then
62 return minetest
.registered_nodes
[node
.name
].on_rightclick(under
, node
, placer
, itemstack
) or itemstack
66 local above
= pointed_thing
.above
67 local wdir
= minetest
.dir_to_wallmounted({x
= under
.x
- above
.x
, y
= under
.y
- above
.y
, z
= under
.z
- above
.z
})
69 -- Torch placement rules: Disallow placement on some nodes. General rule: Solid, opaque, full cube collision box nodes are allowed.
70 -- Special allowed nodes:
72 -- * end portal frame (TODO)
74 -- * Fence, wall, glass, hopper: Only on top
75 -- * Slab: Only on top if upside down
76 -- * Stairs: Only on top if upside down
78 -- Special forbidden nodes:
81 if not def
.buildable_to
then
82 if node
.name
~= "mcl_nether:soul_sand" and node
.name
~= "mcl_mobspawners:spawner" and
83 ((not def
.groups
.solid
) or (not def
.groups
.opaque
)) then
84 -- Only allow top placement on these nodes
85 if def
.groups
.glass
or node
.name
== "mcl_hoppers:hopper" or node
.name
== "mcl_hoppers:hopper_side" or node
.name
== "mcl_hoppers:hopper_disabled" or node
.name
== "mcl_hoppers:hopper_side_disabled" or def
.groups
.fence
== 1 or def
.groups
.wall
or def
.groups
.slab_top
== 1 or (def
.groups
.stair
== 1 and minetest
.facedir_to_dir(node
.param2
).y
~= 0) then
92 elseif node
.name
== "mesecons_pistons:piston_up_normal_off" or node
.name
== "mesecons_pistons:piston_up_sticky_off" or
93 node
.name
== "mesecons_pistons:piston_normal_off" or node
.name
== "mesecons_pistons:piston_sticky_off" or
94 node
.name
== "mesecons_pistons:piston_down_normal_off" or node
.name
== "mesecons_pistons:piston_down_sticky_off" then
99 local itemstring
= itemstack
:get_name()
100 local fakestack
= ItemStack(itemstack
)
101 local idef
= fakestack
:get_definition()
105 -- Prevent placement of ceiling torches
107 elseif wdir
== 1 then
108 retval
= fakestack
:set_name(itemstring
)
110 retval
= fakestack
:set_name(itemstring_wall
)
117 itemstack
, success
= minetest
.item_place(fakestack
, placer
, pointed_thing
, wdir
)
118 itemstack
:set_name(itemstring
)
120 if success
and idef
.sounds
and idef
.sounds
.place
then
121 minetest
.sound_play(idef
.sounds
.place
, {pos
=under
, gain
=1})
126 if moredef
~= nil then
127 for k
,v
in pairs(moredef
) do
131 minetest
.register_node(itemstring
, floordef
)
133 local groups_wall
= table.copy(groups
)
134 groups_wall
.torch
= 2
141 paramtype2
= "wallmounted",
142 sunlight_propagates
= true,
143 is_ground_content
= false,
145 light_source
= light
,
146 groups
= groups_wall
,
149 type = "wallmounted",
150 wall_top
= {-0.1, -0.1, -0.1, 0.1, 0.5, 0.1},
151 wall_bottom
= {-0.1, -0.5, -0.1, 0.1, 0.1, 0.1},
152 wall_side
= {-0.5, -0.5, -0.1, -0.2, 0.1, 0.1},
156 if moredef
~= nil then
157 for k
,v
in pairs(moredef
) do
161 minetest
.register_node(itemstring_wall
, walldef
)
164 -- Add entry alias for the Help
165 if minetest
.get_modpath("doc") then
166 doc
.add_entry_alias("nodes", itemstring
, "nodes", itemstring_wall
)
171 mcl_torches
.register_torch("torch",
173 "Torches are light sources which can be placed at the side or on the top of most blocks.",
174 [[Torches can generally be placed on full solid opaque blocks. The following exceptions apply:
175 • Glass, fence, wall, hopper: Can only be placed on top
176 • Upside-down slab/stair: Can only be placed on top
177 • Soul sand, mob spawner: Placement possible
178 • Glowstone and pistons: No placement possible]],
179 "default_torch_on_floor.png",
180 "mcl_torches_torch_floor.obj", "mcl_torches_torch_wall.obj",
182 name
= "default_torch_on_floor_animated.png",
183 animation
= {type = "vertical_frames", aspect_w
= 16, aspect_h
= 16, length
= 3.3}
186 {dig_immediate
=3, torch
=1, deco_block
=1},
187 mcl_sounds
.node_sound_wood_defaults(),
188 {_doc_items_hidden
= false})
191 minetest
.register_craft({
192 output
= "mcl_torches:torch 4",
195 { "mcl_core:stick" },