Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
minetest.register_on_placenode(function (pos, newnode, placer, oldnode, itemstack, pointed_thing)
if newnode.name ~= "default:torch" then
return
end
-- minetest.chat_send_all(oldnode.name .. " was replaced with " .. newnode.name .. " at " .. minetest.serialize(pos))
pos.y = pos.y+1
local nodeover = minetest.env:get_node(pos)
local name2 = nodeover.name
pos.y = pos.y-2
local nodeunder = minetest.env:get_node(pos)
local name = nodeunder.name
-- minetest.chat_send_all("A node under that is at " .. minetest.serialize(pos) .. " and that is " .. name)
pos.y = pos.y+1
if name ~= "air" then -- ugly hack, fails to filter out things like grass
if name ~= "torches:torch_bottom" then
newnode.name = "torches:torch_bottom"
end
elseif name2 ~= "air" then
if name2 ~= "default:torch" and name2 ~= "torches:torch_ceiling" then
newnode.name = "torches:torch_ceiling"
end
else
-- adjust rotation for placement on wall
local apos = pointed_thing.above
local upos = pointed_thing.under
local dir = { x = upos.x - apos.x, y = upos.y - apos.y, z = upos.z - apos.z }
local facedir = minetest.dir_to_facedir(dir)
newnode.param2 = facedir
end
minetest.swap_node(pos, newnode)
end
)