diff --git a/filter-injector.lua b/filter-injector.lua index 1b81e27..334951f 100644 --- a/filter-injector.lua +++ b/filter-injector.lua @@ -439,6 +439,9 @@ for _, data in ipairs({ return count end, tube = {connect_sides = {right = 1}}, + _update_formspec = function(pos) + set_filter_formspec(data, core.get_meta(pos)) + end, } if data.digiline then diff --git a/fs_helpers.lua b/fs_helpers.lua index 30e476a..13c1f26 100644 --- a/fs_helpers.lua +++ b/fs_helpers.lua @@ -4,7 +4,7 @@ local insert = table.insert local has_mcl = core.get_modpath("mcl_formspec") local has_i3 = core.get_modpath("i3") -local fs_helpers = {} +local fs_helpers = {version = 2} pipeworks.fs_helpers = fs_helpers -- Pipeworks formspec standard: @@ -152,6 +152,26 @@ function fs_helpers.inv_list(x, y, w, h, list, desc) return table.concat(fs) end +core.register_on_mods_loaded(function() + local nodenames = {} + local update_functions = {} + for name, def in pairs(core.registered_nodes) do + if type(def._update_formspec) == "function" then + insert(nodenames, name) + update_functions[name] = def._update_formspec + end + end + core.register_lbm({ + label = "Pipeworks Formspec Update", + name = ":pipeworks:fs_update_v"..fs_helpers.version, + nodenames = nodenames, + run_at_every_load = false, + action = function(pos, node) + update_functions[node.name](pos) + end, + }) +end) + -- Deprecated, but kept for compatibility pipeworks.button_off = { text = "", diff --git a/trashcan.lua b/trashcan.lua index ae7d450..1478398 100644 --- a/trashcan.lua +++ b/trashcan.lua @@ -1,6 +1,13 @@ local S = core.get_translator("pipeworks") local fs_helpers = pipeworks.fs_helpers +local formspec = table.concat({ + fs_helpers.prepends(10.25, 8.5), + fs_helpers.node_label("pipeworks:trashcan", S("Trash Can")), + fs_helpers.inv_list(4.625, 1.25, 1, 1, "trash"), + fs_helpers.player_inv(0.25, 3.5), +}) + core.register_node("pipeworks:trashcan", { description = S("Trash Can"), drawtype = "normal", @@ -24,13 +31,7 @@ core.register_node("pipeworks:trashcan", { }, on_construct = function(pos) local meta = core.get_meta(pos) - local fs = table.concat({ - fs_helpers.prepends(10.25, 8.5), - fs_helpers.node_label("pipeworks:trashcan"), - fs_helpers.inv_list(4.625, 1.25, 1, 1, "trash"), - fs_helpers.player_inv(0.25, 3.5), - }) - meta:set_string("formspec", fs) + meta:set_string("formspec", formspec) meta:set_string("infotext", S("Trash Can")) meta:get_inventory():set_size("trash", 1) end, @@ -39,5 +40,8 @@ core.register_node("pipeworks:trashcan", { on_metadata_inventory_put = function(pos, listname, index, stack, player) core.get_meta(pos):get_inventory():set_stack(listname, index, ItemStack("")) end, + _update_formspec = function(pos) + core.get_meta(pos):set_string("formspec", formspec) + end, }) pipeworks.ui_cat_tube_list[#pipeworks.ui_cat_tube_list+1] = "pipeworks:trashcan" diff --git a/tubes/signal.lua b/tubes/signal.lua index 97dfe1e..89f7c69 100644 --- a/tubes/signal.lua +++ b/tubes/signal.lua @@ -118,6 +118,9 @@ if digiline_enabled and pipeworks.enable_digiline_detector_tube then rules = pipeworks.digilines_rules }, }, + _update_formspec = function(pos) + core.get_meta(pos):set_string("formspec", formspec) + end, }, }) diff --git a/tubes/sorting.lua b/tubes/sorting.lua index eddb25e..8c93578 100644 --- a/tubes/sorting.lua +++ b/tubes/sorting.lua @@ -124,6 +124,7 @@ if pipeworks.enable_mese_tube then return 0 end end, + _update_formspec = update_formspec, }, }) end diff --git a/tubes/tags.lua b/tubes/tags.lua index 45ebf0b..7ad1628 100644 --- a/tubes/tags.lua +++ b/tubes/tags.lua @@ -120,5 +120,6 @@ pipeworks.register_tube("pipeworks:tag_tube", { can_dig = function(pos, player) return true end, + _update_formspec = update_formspec, }, }) diff --git a/tubes/teleport.lua b/tubes/teleport.lua index 95c8af2..b157006 100644 --- a/tubes/teleport.lua +++ b/tubes/teleport.lua @@ -321,6 +321,9 @@ local def = { end, on_receive_fields = receive_fields, on_destruct = remove_tube, + _update_formspec = function(pos) + update_meta(core.get_meta(pos)) + end, } if has_digilines then diff --git a/tubes/vacuum.lua b/tubes/vacuum.lua index 995264e..e1a8fe5 100644 --- a/tubes/vacuum.lua +++ b/tubes/vacuum.lua @@ -113,6 +113,9 @@ if pipeworks.enable_mese_sand_tube then meta:set_string("infotext", S("Adjustable Vacuuming Tube (@1m)", dist)) end, on_punch = has_vislib and show_area or nil, + _update_formspec = function(pos) + core.get_meta(pos):set_string("formspec", formspec) + end, }, }) end diff --git a/wielder.lua b/wielder.lua index f477f62..7c03261 100644 --- a/wielder.lua +++ b/wielder.lua @@ -215,6 +215,9 @@ function pipeworks.register_wielder(def) end core.get_meta(pos):set_string("channel", fields.channel) end, + _update_formspec = function(pos) + set_wielder_formspec(def, core.get_meta(pos)) + end, }) end table.insert(pipeworks.ui_cat_tube_list, def.name.."_off")