Rotate optics and doors from NodeCore with ease.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
786 B

local minetest, vector, include
= minetest, vector, include
local rotate = include("rotate")
local hud = include("hud")
minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing)
local def = minetest.registered_nodes[node.name]
if def.paramtype2 ~= "facedir" then return end
-- Vector that points away from the punched face.
if (not pointed_thing.above) or (not pointed_thing.under) then return end
local axis = vector.subtract(pointed_thing.above, pointed_thing.under)
-- Rotate clockwise by default.
local degrees = -90
-- If player is sneaking, reverse the rotation.
if minetest.is_player(puncher) and puncher:get_player_control().sneak then degrees = -degrees end
rotate.rotate_node(pos, node, axis, degrees)
end)