From 52097be0841a41983e9f976fa3d9542afe7dc183 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 2 Jul 2022 16:36:39 +0200 Subject: [PATCH] Add screwdriver support --- init.lua | 40 +++++++++++++++++++++++++++++++++------- mod.conf | 2 +- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/init.lua b/init.lua index 0a21de9..3e91d4f 100644 --- a/init.lua +++ b/init.lua @@ -144,8 +144,29 @@ minetest.register_node( "pride_flags:lower_mast", { type = "fixed", fixed = { { -3/32, -1/2, -3/32, 3/32, 1/2, 3/32 } }, }, + + on_rotate = function(pos, node, user, mode, new_param2) + if mode == screwdriver.ROTATE_AXIS then + return false + end + end, } ) +local function rotate_flag_by_param2( flag, param2 ) + local facedir_to_yaw = { + [0] = rad_90, + [1] = 0, + [2] = -rad_90, + [3] = rad_180, + } + local baseyaw = facedir_to_yaw[ param2 ] + if not baseyaw then + minetest.log("warning", "[pride_flags] Unsupported flag pole node param2: "..tostring(param2)) + return + end + flag:set_yaw( baseyaw - rad_180 ) +end + local function spawn_flag( pos ) local node_idx = minetest.hash_node_position( pos ) local param2 = minetest.get_node( pos ).param2 @@ -156,17 +177,11 @@ local function spawn_flag( pos ) [3] = { x = 0.1, y = 0.6, z = 0 }, } - local facedir_to_yaw = { - [0] = rad_90, - [1] = 0, - [2] = -rad_90, - [3] = rad_180, - } local flag_pos = vector.add( pos, vector.multiply( facedir_to_pos[ param2 ], 1 ) ) local obj = minetest.add_entity( flag_pos, "pride_flags:wavingflag" ) obj:get_luaentity( ).node_idx = node_idx - obj:set_yaw( facedir_to_yaw[ param2 ] - rad_180 ) + rotate_flag_by_param2( obj, param2 ) active_flags[ node_idx ] = obj return obj @@ -220,4 +235,15 @@ minetest.register_node( "pride_flags:upper_mast", { active_flags[ node_idx ]:remove( ) end end, + + on_rotate = function(pos, node, user, mode, new_param2) + if mode == screwdriver.ROTATE_AXIS then + return false + end + local node_idx = minetest.hash_node_position( pos ) + local aflag = active_flags[ node_idx ] + if aflag then + rotate_flag_by_param2( aflag, new_param2 ) + end + end, } ) diff --git a/mod.conf b/mod.conf index d2b396f..01122a5 100644 --- a/mod.conf +++ b/mod.conf @@ -2,5 +2,5 @@ name = pride_flags title = Pride Flags author = sorcerykid license = LGPL-3.0 -optional_depends = default +optional_depends = default, screwdriver