Improve rotation

More general function, checks for falling.
This commit is contained in:
Jude Melton-Houghton 2022-01-27 10:35:38 -05:00
parent 6fc8c6a2c0
commit 64c104b68d
2 changed files with 20 additions and 16 deletions

View File

@ -6,6 +6,25 @@ function mesecon.move_node(pos, newpos)
minetest.get_meta(pos):from_table(meta)
end
-- An on_rotate callback for mesecons components.
function mesecon.on_rotate(pos, node, user, mode, new_param2)
minetest.swap_node(pos, {name = "air"})
mesecon.on_dignode(pos, node)
node.param2 = new_param2
minetest.swap_node(pos, node)
mesecon.on_placenode(pos, node)
minetest.check_for_falling(pos)
return true
end
-- An on_rotate callback for components which stay horizontal.
function mesecon.on_rotate_horiz(pos, node, user, mode, new_param2)
if not minetest.global_exists("screwdriver") or mode ~= screwdriver.ROTATE_FACE then
return false
end
return mesecon.on_rotate(pos, node, user, mode, new_param2)
end
-- Rules rotation Functions:
function mesecon.rotate_rules_right(rules)
local nr = {}
@ -452,22 +471,6 @@ function mesecon.swap_node_force(pos, name, update_light)
end
end
-- An on_rotate callback for components which stay horizontal.
function mesecon.on_rotate_horiz(pos, node, user, mode, new_param2)
if not minetest.global_exists("screwdriver") then
return false
end
if mode ~= screwdriver.ROTATE_FACE then
return false
end
minetest.swap_node(pos, {name = "air"})
mesecon.on_dignode(pos, node)
node.param2 = new_param2
minetest.swap_node(pos, node)
mesecon.on_placenode(pos, node)
return true
end
-- Autoconnect Hooks
-- Nodes like conductors may change their appearance and their connection rules
-- right after being placed or after being dug, e.g. the default wires use this

View File

@ -270,5 +270,6 @@ function mesecon.buttonlike_onrotate(pos, node, user, mode, new_param2)
minetest.swap_node(pos, node)
mesecon.on_placenode(pos, node)
mesecon.receiver_place(pos)
minetest.check_for_falling(pos)
return true
end