aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Yves Rollo <dev@pyrollo.com>2019-03-09 20:24:53 +0100
committerPierre-Yves Rollo <dev@pyrollo.com>2019-03-09 20:24:53 +0100
commit17923d5aea8c29db1c2726d830a587e46dbb1ce4 (patch)
treef9250257ce66b6bf7945c9bd58c6628de76a864e
parentec6f742895da8e9470e8ada333d8feedf71b25d3 (diff)
downloaddisplay_modpack_no_craft-17923d5aea8c29db1c2726d830a587e46dbb1ce4.tar.gz
display_modpack_no_craft-17923d5aea8c29db1c2726d830a587e46dbb1ce4.zip
Use MT5 set_rotation to allow all rotations of nodes
-rw-r--r--init.lua72
1 files changed, 52 insertions, 20 deletions
diff --git a/init.lua b/init.lua
index 6c9079e..4b20486 100644
--- a/init.lua
+++ b/init.lua
@@ -92,36 +92,40 @@ function signs_api.on_place_direction(itemstack, placer, pointed_thing)
local name = itemstack:get_name()
local ndef = minetest.registered_nodes[name]
- local bdir = {x = pointed_thing.under.x - pointed_thing.above.x,
- y = pointed_thing.under.y - pointed_thing.above.y,
- z = pointed_thing.under.z - pointed_thing.above.z}
+ local bdir = {
+ x = pointed_thing.under.x - pointed_thing.above.x,
+ y = pointed_thing.under.y - pointed_thing.above.y,
+ z = pointed_thing.under.z - pointed_thing.above.z}
+
local pdir = placer:get_look_dir()
local ndir, test
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)
ndir = minetest.dir_to_facedir({x=pdir.x, y=0, z=pdir.z})
else
- -- Wall pointed
- ndir = minetest.dir_to_facedir(bdir)
+ -- Wall pointed or no rotation restriction
+ ndir = minetest.dir_to_facedir(bdir, not display_api.rotation_restriction)
end
- test = {[0]=-pdir.x, pdir.z, pdir.x, -pdir.z}
- end
+ test = { [0]=-pdir.x, pdir.z, pdir.x, -pdir.z, -pdir.x, [8]=pdir.x }
+ end
if ndef.paramtype2 == "wallmounted" then
ndir = minetest.dir_to_wallmounted(bdir)
- if ndir == 0 or ndir == 1 then
- -- Ceiling or floor
+ -- If legacy mode, only accept upright nodes
+ 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})
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
-- Only for direction signs
+ -- TODO:Maybe improve ground and ceiling placement in every directions
if ndef.signs_other_dir then
if test[ndir] > 0 then
itemstack:set_name(ndef.signs_other_dir)
@@ -135,20 +139,48 @@ function signs_api.on_place_direction(itemstack, placer, pointed_thing)
end
end
--- Handles screwdriver rotation. Direction is affected for direction signs
--- If rotation mode is 2 and sign is directional, swap direction.
--- Otherwise use display_api's on_rotate function.
-function signs_api.on_rotate(pos, node, player, mode, new_param2)
- if mode == 2 then
+-- 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
- minetest.swap_node(pos, {name = ndef.signs_other_dir,
- param1 = node.param1, param2 = node.param2})
+ -- Switch direction
+ node = {name = ndef.signs_other_dir,
+ param1 = node.param1, param2 = node.param2}
+ minetest.swap_node(pos, node)
display_api.update_entities(pos)
- return true
+ -- 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.
+ -- Otherwise use display_api's on_rotate function.
+ if mode == 2 then
+ local ndef = minetest.registered_nodes[node.name]
+ if ndef.signs_other_dir then
+ minetest.swap_node(pos, {name = ndef.signs_other_dir,
+ param1 = node.param1, param2 = node.param2})
+ display_api.update_entities(pos)
+ return true
+ end
end
+ return display_api.on_rotate(pos, node, player, mode, new_param2)
end
- return display_api.on_rotate(pos, node, user, mode, new_param2)
end
function signs_api.register_sign(mod, name, model)