From 99a719309559b632af65756f380496aa269d4b4a Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 1 Oct 2022 21:19:42 +0200 Subject: [PATCH] Teach screwdriver to rotate 4dir nodes (#2992) --- mods/screwdriver/init.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mods/screwdriver/init.lua b/mods/screwdriver/init.lua index 48684cfb..e7227bf0 100644 --- a/mods/screwdriver/init.lua +++ b/mods/screwdriver/init.lua @@ -60,6 +60,19 @@ end screwdriver.rotate.colorfacedir = screwdriver.rotate.facedir +screwdriver.rotate["4dir"] = function(pos, node, mode) + if mode ~= screwdriver.ROTATE_FACE then + -- Can only rotate 4dir nodes in face mode + return nil + end + local rotation = node.param2 % 4 -- get first 2 bits + local other = node.param2 - rotation + rotation = (rotation + 1) % 4 + return rotation + other +end + +screwdriver.rotate["color4dir"] = screwdriver.rotate["4dir"] + local wallmounted_tbl = { [screwdriver.ROTATE_FACE] = {[2] = 5, [3] = 4, [4] = 2, [5] = 3, [1] = 0, [0] = 1}, [screwdriver.ROTATE_AXIS] = {[2] = 5, [3] = 4, [4] = 2, [5] = 1, [1] = 0, [0] = 3} @@ -113,6 +126,10 @@ screwdriver.handler = function(itemstack, user, pointed_thing, mode, uses) local new_param2 if fn then new_param2 = fn(pos, node, mode) + if not new_param2 then + -- rotation refused + return itemstack + end else new_param2 = node.param2 end