Mod Loading Hadling.

User avatar
Andrey01
Member
 
Posts: 2338
Joined: Wed Oct 19, 2016 15:18
Location: Russia, Moscow
GitHub: Andrey2470T
In-game: Andrey01

Mod Loading Hadling.

by Andrey01 » Thu Aug 08, 2019 21:15

Is it possible anyhow to handle with a mod handling that what order mods should be loaded in? In my case, I want a certain mod to being loaded after all mods have been loaded.
 

ShadMOrdre
Member
 
Posts: 556
Joined: Mon Dec 29, 2014 08:07
Location: USA
GitHub: ShadMOrdre
In-game: shadmordre

Re: Mod Loading Hadling.

by ShadMOrdre » Thu Aug 08, 2019 23:34

Andrey,

There is, in v5.0, a function (minetest.on_mods_loaded) that runs code after all mods have been loaded.

Not sure if this will solve your issue, but other than depending on the dependency tree, there is no sure fire way to determine or influence the order in which mods are loaded.
MY MODS: lib_ecology lib_materials lib_clouds lib_node_shapes ---- Inspired By: Open Source Virtual World Simulator Opensimulator.
 

User avatar
Yvanhoe
Member
 
Posts: 131
Joined: Fri Jul 05, 2019 03:18
Location: Japan

Re: Mod Loading Hadling.

by Yvanhoe » Fri Aug 09, 2019 02:18

Andrey01 wrote:Is it possible anyhow to handle with a mod handling that what order mods should be loaded in? In my case, I want a certain mod to being loaded after all mods have been loaded.

If you add a line
Code: Select all
depends = moda,modb,modc

in the mod.conf file at the root of your mod, your will only be loaded after moda, modb and modc were loaded.
 

User avatar
Andrey01
Member
 
Posts: 2338
Joined: Wed Oct 19, 2016 15:18
Location: Russia, Moscow
GitHub: Andrey2470T
In-game: Andrey01

Re: Mod Loading Hadling.

by Andrey01 » Fri Aug 09, 2019 17:19

ShadMOrdre wrote:Andrey,

There is, in v5.0, a function (minetest.on_mods_loaded) that runs code after all mods have been loaded.

Not sure if this will solve your issue, but other than depending on the dependency tree, there is no sure fire way to determine or influence the order in which mods are loaded.

Well, that means the certain mod that I mentioned also will be loaded together with other, not separately. And there`s no a function like minetest.load_mod() that would implement loading of that mod inside minetest.register_on_mods_loaded(), as far as I know.

Yvanhoe wrote:
Andrey01 wrote:Is it possible anyhow to handle with a mod handling that what order mods should be loaded in? In my case, I want a certain mod to being loaded after all mods have been loaded.

If you add a line
Code: Select all
depends = moda,modb,modc

in the mod.conf file at the root of your mod, your will only be loaded after moda, modb and modc were loaded.

This method doesn`t fit also. It`s unknown what and what amount of mods a user maintains.
 

neoh4x0r
Member
 
Posts: 69
Joined: Wed Aug 29, 2018 20:16
GitHub: neoh4x0r

Re: Mod Loading Hadling.

by neoh4x0r » Fri Aug 09, 2019 19:24

Andrey01 wrote:there`s no a function like minetest.load_mod() that would implement loading of that mod inside minetest.register_on_mods_loaded(), as far as I know.


TL;DR
You need a new feature to be added to minetest to dynamically load mods.

This is non-trivial and would require a lot of work to properly sort the decency tree (and having more than one mod attempting to be loaded last would cause a race condition).

This means that it would be very buggy and cumbersome to code and maintain.

The real question here would be to know why you need your mod to be the final one loaded.
(ie are you trying to override an item definition, etc -- if that is the case then you can override the def in minetest.register_on_mods_loaded())





==================================================
Minetest does, not yet, provide any mechanism to do this.

Eg the following in mod_xyz/mod.conf:
Code: Select all
depends = moda, modb, modc


Only works to ensure that mod_xyz is loaded after, moda, modb, modc
But does not, and cannot, ensure that mod_xyz is the last one loaded (after all other mods).


Really what you are asking is for an enhancement / feature to be added to minetest that allows the dynamic loading of a mod -- which incidentally would require another mod to be installed to define the body of the minetest.register_on_mods_loaded() method to dynamically load mod_xyz.

The trouble here is one of a race condition where if more then one mod attempts to be loaded last, then it is unclear which mod would actually be the last one loaded -- in fact it will probably be different on each world load (as it will depend on when register_on_mods_loaded actually gets called per mod).

This race condition makes adding that new feature, fundamentally unworkable.

Even if the mod loading system had a priority value added, where higher priorities get loaded at the bottom -- there would still be a race condition for mods that had the same priority (they could be sorted based on their dependency tree, but it still becomes a non-trivial matter).
==================================================
 

ThorfinnS
Member
 
Posts: 214
Joined: Mon Feb 25, 2019 22:05
GitHub: ThorfinnS

Re: Mod Loading Hadling.

by ThorfinnS » Fri Aug 09, 2019 19:31

There's also minetest.register_on_joinplayer, but that doesn't prevent another mod from doing the same thing, and minetest doing them in whatever order it does them. But there are things you can't do there. And its a little buggy. But from my minimal testing, it seems to handle this after minetest.on_mods_loaded. At least I'm able to do some overwrites without having a soft dependency.

But maybe that wasn't what you were asking, either... ;)
 

User avatar
AiTechEye
Member
 
Posts: 747
Joined: Fri May 29, 2015 21:14
Location: ¯\_(ツ)_/¯
GitHub: AiTechEye

Re: Mod Loading Hadling.

by AiTechEye » Fri Aug 09, 2019 19:52

try to name the mod to zzzz, if minetest reads mods from a to z, and the more z it maybe becomes more chance to be the last one
 

User avatar
Andrey01
Member
 
Posts: 2338
Joined: Wed Oct 19, 2016 15:18
Location: Russia, Moscow
GitHub: Andrey2470T
In-game: Andrey01

Re: Mod Loading Hadling.

by Andrey01 » Fri Aug 09, 2019 20:05

Why I`m asking for it is I need to override 'node_def' tables of all nodes of any mods that enabled, because they need additional properties. That`s why I need to load this mod after all.
 

User avatar
AiTechEye
Member
 
Posts: 747
Joined: Fri May 29, 2015 21:14
Location: ¯\_(ツ)_/¯
GitHub: AiTechEye
 

neoh4x0r
Member
 
Posts: 69
Joined: Wed Aug 29, 2018 20:16
GitHub: neoh4x0r

Re: Mod Loading Hadling.

by neoh4x0r » Fri Aug 09, 2019 21:05

Andrey01 wrote:Why I`m asking for it is I need to override 'node_def' tables of all nodes of any mods that enabled, because they need additional properties. That`s why I need to load this mod after all.


See this thread: viewtopic.php?f=6&t=3045

cornernote wrote:Heres a quick function (hack) based on your solution to make main code a little cleaner:

Code: Select all
minetest.registered = function(case,name)
    local params = {}
    local list
    if case == "item" then list = minetest.registered_items end
    if case == "node" then list = minetest.registered_nodes end
    if case == "craftitem" then list = minetest.registered_craftitems end
    if case == "tool" then list = minetest.registered_tools end
    if case == "entity" then list = minetest.registered_entities end
    if list then
        for k,v in pairs(list[name]) do
            params[k] = v
        end
    end
    return params
end




What about this code ?

Code: Select all
minetest.register_on_mods_loaded(override_nodes)

local function override_nodes()
   local list = minetest.registered_nodes
   if list then
      for name,node in pairs(list) do
         node.after_place_node =
            function(pos)
               -- get the actual node that was placed
               placed_node = minetest.get_node(pos)

               -- do something with placed_node
               if placed_node.some_property == nil
                  local some_value = {} -- alter as needed
                  placed_node.some_property = some_value
               end

               -- set the updated node
               minetest.set_node(pos, placed_node)
            end
       end
   end
end
 

User avatar
AiTechEye
Member
 
Posts: 747
Joined: Fri May 29, 2015 21:14
Location: ¯\_(ツ)_/¯
GitHub: AiTechEye

Re: Mod Loading Hadling.

by AiTechEye » Fri Aug 09, 2019 21:20

Edit:

this is maybe the solution:

Code: Select all
for i,v in pairs(minetest.registered_items) do
  v.light_source = 10
  minetest.override_item(i, v)
end

local a = minetest.register_node
minetest.register_node = function(name,def)
   def.light_source = 10
end
 


Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 3 guests