|
|
|
local minetest, vector, include
|
|
|
|
= minetest, vector, include
|
|
|
|
|
|
|
|
local rotate = include("rotate")
|
|
|
|
|
|
|
|
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)
|