Expand LuaEntity(Prototype) to view Mod Interactions as a Read Only Variable

Post Reply
AlienX
Fast Inserter
Fast Inserter
Posts: 103
Joined: Wed May 17, 2017 7:13 pm
Contact:

Expand LuaEntity(Prototype) to view Mod Interactions as a Read Only Variable

Post by AlienX »

Hi,
For a project i have in my head, I would find it really useful if modders could grab the data of what mods have touched what items, and in what order during game play.

For example, if you wanted to make a whitelist/blacklist mod, which disables placement of a certain mods buildings depending on certain critera during control.lua scripts, this would make it much easier.


Take this from the tooltip as an example:
mod_req_a.png
mod_req_a.png (22.4 KiB) Viewed 3045 times


Perhaps something like:

Code: Select all

entity.modInteractions - Table of mod interactions that have modified this entity prototype and in what order
Then you could see via something like:

Code: Select all

game.print(entity.modInteractions[1]) = "Krastorio" for example
You could also expand Item prototypes to do the same thing, again from the data on the tooltip:
mod_req_b.png
mod_req_b.png (115.73 KiB) Viewed 3045 times
Last edited by AlienX on Wed Sep 11, 2019 6:57 pm, edited 2 times in total.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: Expand LuaEntity(Prototype) to view Mod Interactions as a Read Only Variable

Post by Deadlock989 »

+10000000.

In a perfect world, this table would be available globally during the data stage as well, so you could tell if another mod has altered a prototype yet, it's not always enough to know that another mod is simply installed, when any third mod you don't know about could be changing loading order by requiring it as a dependency. Possibly as a field in every prototype that's discarded at the end of the data stage? No clue how the yellow mod names data on the tooltip is kept and built up though.
Image

AlienX
Fast Inserter
Fast Inserter
Posts: 103
Joined: Wed May 17, 2017 7:13 pm
Contact:

Re: Expand LuaEntity(Prototype) to view Mod Interactions as a Read Only Variable

Post by AlienX »

Agree with deadlock, any more areas where this data is available to us, the better.
While a long shot, i would love to have this before a stable release.

AlienX
Fast Inserter
Fast Inserter
Posts: 103
Joined: Wed May 17, 2017 7:13 pm
Contact:

Re: Expand LuaEntity(Prototype) to view Mod Interactions as a Read Only Variable

Post by AlienX »

As requested by Rseding91, here is a screenie of our convo for memory purposes.
convo.png
convo.png (672.98 KiB) Viewed 2985 times

Rseding91
Factorio Staff
Factorio Staff
Posts: 13175
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Expand LuaEntity(Prototype) to view Mod Interactions as a Read Only Variable

Post by Rseding91 »

What's the use-case in wanting to know if another mod has changed some part of something in the data stage?

With that being said, what's the use-case for having it runtime as well? I read what you posted but it just gives a vague idea and not something that's really convincing at the moment.

What I'm concerned with is a mod or group of mods adding in spiteful code when they detect specific mod(s) have altered parts of their mods and I just don't want to enable people to do that.
If you want to get ahold of me I'm almost always on Discord.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2915
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: Expand LuaEntity(Prototype) to view Mod Interactions as a Read Only Variable

Post by Optera »

Rseding91 wrote:
Sat Sep 21, 2019 5:26 am
What's the use-case in wanting to know if another mod has changed some part of something in the data stage?

With that being said, what's the use-case for having it runtime as well? I read what you posted but it just gives a vague idea and not something that's really convincing at the moment.

What I'm concerned with is a mod or group of mods adding in spiteful code when they detect specific mod(s) have altered parts of their mods and I just don't want to enable people to do that.
Invalid argument, you can already do that easily in data stage with

Code: Select all

if mods["mod-i-dislike"] then
  --mess with it
end
I like to think our Factorio modding community is above such pettiness.
Having a read only string or better array containing all mods having touched a prototype in order, could slim down compatibility codes.
For example if you have a mod that needs to behave differently depending on options in 2 or more mods, say boblogistics and ir, the possible variants of prototypes touched by both grows rapidly.
Instead of combing through the settings of previous mods and checking if a setting would result in a change you need to overwrite, you could directly look at the prototype to see if it got changed.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5148
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Expand LuaEntity(Prototype) to view Mod Interactions as a Read Only Variable

Post by Klonan »

Optera wrote:
Sat Sep 21, 2019 6:11 am
Invalid argument, you can already do that easily in data stage with

Code: Select all

if mods["mod-i-dislike"] then
  --mess with it
end
That is different slightly, you only know the mod exists, not that it has been messing with your items.
I can easily see someone blanket doing:

Code: Select all

local item = data.raw.item["klonans-cool-item"]
if item.mod_interactions > 1 then
  error("Some other mod has adjusted my item, please remove this mod and try to load again")
end

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2915
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: Expand LuaEntity(Prototype) to view Mod Interactions as a Read Only Variable

Post by Optera »

Klonan wrote:
Sat Sep 21, 2019 7:39 am
Optera wrote:
Sat Sep 21, 2019 6:11 am
Invalid argument, you can already do that easily in data stage with

Code: Select all

if mods["mod-i-dislike"] then
  --mess with it
end
That is different slightly, you only know the mod exists, not that it has been messing with your items.
I can easily see someone blanket doing:

Code: Select all

local item = data.raw.item["klonans-cool-item"]
if item.mod_interactions > 1 then
  error("Some other mod has adjusted my item, please remove this mod and try to load again")
end
In some modding communities this might be a valid point, but so far Factorios modding community is friendly and respectful.
I've talked to a few new mod authors engaging in final-fixes wars with my mods and in the end they always realized it was bad practice and took my advice on how to write compatible mods.

If Wube officially recognizes toxicity in the community by rejecting feature requests for the sole reason of it being abused. This will plant the idea of our community being toxic in our heads leaving a bad undertone to every constructive criticism and we really will need to have that kind of moderation like a self fullfilling prophecy.
So lets not go down that path and instead focus on how we can use it to improve Factorio and its mods.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: Expand LuaEntity(Prototype) to view Mod Interactions as a Read Only Variable

Post by Deadlock989 »

I would purely use this as a debugging tool. It is not a "must have", it would be a "nice to have".

For example, my current big mod is enforcing a strict recipe unlocking order in the tech tree hierarchy. Because any individual mod has very limited control over the loading order of other mods, it is impossible to cover all situations of all 4000-odd mods on the portal that may or may not change unlocks/prerequirements either before or after my mod does. It would be extremely useful to know exactly which mod has changed a technology prototype at the moment any problem is detected, instead of having to figure it out by deduction. That information would be useful for me when I want to provide explicit built-in support for other mods, and it would be useful for other modders who want their mods to be compatible with mine.

I can think of several other uses, none as immediately useful as the one above, but all of them also being about getting debugging information rather than triggers for any kind of action.
Image

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Expand LuaEntity(Prototype) to view Mod Interactions as a Read Only Variable

Post by eradicator »

Klonan wrote:
Sat Sep 21, 2019 7:39 am

Code: Select all

local item = data.raw.item["klonans-cool-item"]
if item.mod_interactions > 1 then
  error("Some other mod has adjusted my item, please remove this mod and try to load again")
end
Being a pessimist i actually share the "every herd has some black sheep" sentiment. I've seen SpaceExploration actually do this with any mod that doesn't share the authors "vision" of "proper balance" (based on a hardcoded list of names in addition to "!" dependencies). But i'm also a pessimist towards user behavior, and think that most users just see the error window as a "buch of tech babble" and not actually read what's written there past the name of the mod (if that far). So any mod author would hopefully just be killing their own mod if they did this.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Expand LuaEntity(Prototype) to view Mod Interactions as a Read Only Variable

Post by eradicator »

Edge-casey usecases:

1 ) In a large mod pack it's difficult to automatically match "groups" of entities. I.e. automatically finding the matching underground belt from a straight belt if several mods add belts tiers of the same speed. Access to the mod interactions would allow me to make a better guess regarding the "owning" mod of an item, because it would be the first entry in the list.

2) In mod guis it would allow showing recipes sorted by the mod that created them. (Again, nice for large modpacks).

Admittedly for both these cases the first entry of the mod interactions would be sufficient.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Bilka
Factorio Staff
Factorio Staff
Posts: 3123
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Expand LuaEntity(Prototype) to view Mod Interactions as a Read Only Variable

Post by Bilka »

This information was added some time ago. It is visible in the prototype explorer (open with CTRL + SHIFT + E or CTRL + SHIFT + F) and via a runtime method: https://lua-api.factorio.com/latest/cla ... pe_history.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Post Reply

Return to “Implemented mod requests”