minetest-mods / unified_inventory

An extensible inventory mod which allows searching crafting and browsing for recipes in the same dialogue.
Other
50 stars 38 forks source link

Don't use mod_origin #190

Closed JordanL2 closed 2 years ago

JordanL2 commented 2 years ago

Unified Inventory uses the mod_origin field to get the name of the mod that added the item.

The problem with that, is that sometimes items need to be added to the game outside of the mod's init phase, for example via a callback created with minetest.register_on_mods_loaded. They might need to do this as the items they add to the game depend on what other items are in the game. An example is if you wanted to add a new type of wooden item to the game, which can be crafted with any type of wood, and has a different name and texture depending on the wood it was crafted with. Arguably the easiest way to do this, is to wait till all mods are loaded and then look at the wood group for a list of all the wood types.

minetest.register_on_mods_loaded(function()
  for nodename, nodedef in pairs(minetest.registered_nodes) do
    if nodedef.groups and nodedef.groups.wood then
      -- code here creating a new gate, table, whatever with this wood type
    end
  end
end)

Because register_on_mods_loaded runs after the mod's init phase, the new item doesn't count as having been created by the mod itself, so it's mod_origin field is "??", and this is visible in UI. The only way round this, is with this hack to override mod_origin:

    minetest.register_on_prejoinplayer(
        function()
            minetest.override_item(item_name, {
                mod_origin = 'this_mod',
            })
        end
    )

Basically there are valid reasons why an item's mod_origin might not actually say the mod it came from. I'd argue while mod_origin is useful for debugging, it's not necessarily the best thing to display in UI's tooltips. Instead the mod name can be found just by parsing the item name.

SmallJoker commented 2 years ago

I also don't think this information is necessary at all. The mod name can already be seen in the recipe dialogue if the formspec is big enough to display the text.

This will undo the idea of #118. (@Unarelith)

Suggested changes. What do you think about this?

diff --git a/internal.lua b/internal.lua
index 76a277d..6449979 100644
--- a/internal.lua
+++ b/internal.lua
@@ -238,9 +238,8 @@ local function formspec_add_item_browser(player, formspec, ui_peruser)
                                        ui_peruser.btn_size, ui_peruser.btn_size,
                                        name, button_name
                                )
-                               formspec[n + 1] = ("tooltip[%s;%s \\[%s\\]]"):format(
-                                       button_name, minetest.formspec_escape(item.description),
-                                       item.mod_origin or "??"
+                               formspec[n + 1] = ("tooltip[%s;%s]"):format(
+                                       button_name, minetest.formspec_escape(item.description)
                                )
                                n = n + 2
                                list_index = list_index + 1
JordanL2 commented 2 years ago

If you were asking me, makes sense to me.

SmallJoker commented 2 years ago

64b0248