From 0037cf4e3f3389aa7c0f331ea255f7e88c5c35f7 Mon Sep 17 00:00:00 2001 From: copygirl Date: Thu, 26 Oct 2023 12:05:36 +0200 Subject: [PATCH] Automatically register ALL doors Fixes brick-based doors not being rotatable. --- init.lua | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index 6a9ad9f..197a140 100755 --- a/init.lua +++ b/init.lua @@ -18,6 +18,7 @@ local update_rotating_state = nc_extended_rotating.state.update_rotating_state local get_rotating_state = nc_extended_rotating.state.get_rotating_state -- TODO: Fix HUD showing rotation hint when we wouldn't / can't rotate. +-- TODO: Simplify registration and `on_rightclick` replacement into one call. -- TODO: Add some more comments. nodecore.register_playerstep({ @@ -56,8 +57,14 @@ do for _, prism_state in ipairs({ "", "_on", "_gated" }) do register_rotatable("nc_optics:prism" .. prism_state, PRISM_FILTERED_LOOKUP) end - register_rotatable("nc_doors:panel_plank" , PANEL_FILTERED_LOOKUP) - register_rotatable("nc_doors:panel_cobble", PANEL_FILTERED_LOOKUP) + -- Register all existing door panels. + nodecore.register_on_register_item({ + retroactive = true, + func = function(name, def) + if def.groups and def.groups.door_panel and (not def.groups.door) + then register_rotatable(name, PANEL_FILTERED_LOOKUP) end + end, + }) end local function handle_rightclick(pos, node, clicker) @@ -91,8 +98,17 @@ do for _, lens_state in ipairs({ "", "_on", "_gated" }) do replace_optics_on_rightclick("nc_optics:prism" .. lens_state) end - replace_panel_on_rightclick("nc_doors:panel_plank" , "nc_woodwork:staff") - replace_panel_on_rightclick("nc_doors:panel_cobble", "nc_lode:rod_tempered") + -- Replace `on_rightclick` for all existing doors' panels. + nodecore.register_on_register_item({ + retroactive = true, + func = function(name, def) + if def.groups and def.groups.door then + local panel = def.drop_in_place -- The panel version of the door. + local pin = def.drop -- Dropped item is the door's pin. + replace_panel_on_rightclick(panel.name, pin.name) + end + end, + }) end -- Override `nc_scaling`'s default empty hand right-click behavior so we can use it