Use MT5 set_rotation to allow all rotations of nodes

This commit is contained in:
Pierre-Yves Rollo 2019-03-09 20:24:53 +01:00
parent ec6f742895
commit 17923d5aea

@ -92,36 +92,40 @@ function signs_api.on_place_direction(itemstack, placer, pointed_thing)
local name = itemstack:get_name() local name = itemstack:get_name()
local ndef = minetest.registered_nodes[name] local ndef = minetest.registered_nodes[name]
local bdir = {x = pointed_thing.under.x - pointed_thing.above.x, local bdir = {
x = pointed_thing.under.x - pointed_thing.above.x,
y = pointed_thing.under.y - pointed_thing.above.y, y = pointed_thing.under.y - pointed_thing.above.y,
z = pointed_thing.under.z - pointed_thing.above.z} z = pointed_thing.under.z - pointed_thing.above.z}
local pdir = placer:get_look_dir() local pdir = placer:get_look_dir()
local ndir, test local ndir, test
if ndef.paramtype2 == "facedir" then if ndef.paramtype2 == "facedir" then
if bdir.x == 0 and bdir.z == 0 then -- If legacy mode, only accept upright nodes
if display_api.rotation_restriction and bdir.x == 0 and bdir.z == 0 then
-- Ceiling or floor pointed (facedir chosen from player dir) -- Ceiling or floor pointed (facedir chosen from player dir)
ndir = minetest.dir_to_facedir({x=pdir.x, y=0, z=pdir.z}) ndir = minetest.dir_to_facedir({x=pdir.x, y=0, z=pdir.z})
else else
-- Wall pointed -- Wall pointed or no rotation restriction
ndir = minetest.dir_to_facedir(bdir) ndir = minetest.dir_to_facedir(bdir, not display_api.rotation_restriction)
end end
test = {[0]=-pdir.x, pdir.z, pdir.x, -pdir.z} test = { [0]=-pdir.x, pdir.z, pdir.x, -pdir.z, -pdir.x, [8]=pdir.x }
end end
if ndef.paramtype2 == "wallmounted" then if ndef.paramtype2 == "wallmounted" then
ndir = minetest.dir_to_wallmounted(bdir) ndir = minetest.dir_to_wallmounted(bdir)
if ndir == 0 or ndir == 1 then -- If legacy mode, only accept upright nodes
-- Ceiling or floor if display_api.rotation_restriction and (ndir == 0 or ndir == 1) then
ndir = minetest.dir_to_wallmounted({x=pdir.x, y=0, z=pdir.z}) ndir = minetest.dir_to_wallmounted({x=pdir.x, y=0, z=pdir.z})
end end
test = {0, pdir.z, -pdir.z, -pdir.x, pdir.x} test = { [0]=-pdir.x, -pdir.x, pdir.z, -pdir.z, -pdir.x, pdir.x}
end end
-- Only for direction signs -- Only for direction signs
-- TODO:Maybe improve ground and ceiling placement in every directions
if ndef.signs_other_dir then if ndef.signs_other_dir then
if test[ndir] > 0 then if test[ndir] > 0 then
itemstack:set_name(ndef.signs_other_dir) itemstack:set_name(ndef.signs_other_dir)
@ -135,10 +139,37 @@ function signs_api.on_place_direction(itemstack, placer, pointed_thing)
end end
end end
-- Handles screwdriver rotation. Direction is affected for direction signs -- Handles screwdriver rotation
-- (see "if" block below for rotation restriction mode).
signs_api.on_rotate = function(pos, node, player, mode, new_param2)
-- If rotation mode is 1 and sign is directional, swap direction between
-- each rotation.
if mode == 1 then
local ndef = minetest.registered_nodes[node.name]
if ndef.signs_other_dir then
-- Switch direction
node = {name = ndef.signs_other_dir,
param1 = node.param1, param2 = node.param2}
minetest.swap_node(pos, node)
display_api.update_entities(pos)
-- Rotate only if not "main" sign
-- TODO:Improve detection of "main" direction sign
if ndef.groups and ndef.groups.not_in_creative_inventory then
return display_api.on_rotate(pos, node, player, mode, new_param2)
else
return true
end
end
end
return display_api.on_rotate(pos, node, player, mode, new_param2)
end
-- Legacy mode with rotation restriction
-- TODO:When MT < 5.0 no more in use, to be removed
if display_api.rotation_restriction then
signs_api.on_rotate = function(pos, node, player, mode, new_param2)
-- If rotation mode is 2 and sign is directional, swap direction. -- If rotation mode is 2 and sign is directional, swap direction.
-- Otherwise use display_api's on_rotate function. -- Otherwise use display_api's on_rotate function.
function signs_api.on_rotate(pos, node, player, mode, new_param2)
if mode == 2 then if mode == 2 then
local ndef = minetest.registered_nodes[node.name] local ndef = minetest.registered_nodes[node.name]
if ndef.signs_other_dir then if ndef.signs_other_dir then
@ -148,7 +179,8 @@ function signs_api.on_rotate(pos, node, player, mode, new_param2)
return true return true
end end
end end
return display_api.on_rotate(pos, node, user, mode, new_param2) return display_api.on_rotate(pos, node, player, mode, new_param2)
end
end end
function signs_api.register_sign(mod, name, model) function signs_api.register_sign(mod, name, model)