Mini Machines Mod

by Kryzeth

Miniature versions of assemblers, electric furnaces, etc. Full integration with all of Bobs mods and ShinyBobGFX/ShinyAngelGFX, Industrial Revolution, Factorio Extended Plus (FXP), Gotlag's Electric Furnaces, AAI Industry, Fantario, and One More Tier. (independently, not necessarily simultaneously)

Content
11 days ago
0.13 - 2.0
11.7K
Manufacturing

g [Not a bug] A question about this mod

4 years ago

Just a short question, it's somewhat unrelated to the mod but still related enough to ask here, how do you do the scaling for your machines in this mod? I can't find any good way of resizing vanilla machines especially with many different image layers and still have the offsets work properly.
I would really appreciate any kind of help or even pointer on how to go about stuff like that, but if you can't help that's ok.

4 years ago
(updated 4 years ago)

The current method used in this mod was actually developed by Kirazy, another user on the mod portal and forums. (EDIT: Also a modmaker! Check his mods here!) Though his method is somewhat of a more refined and efficient version of the manual way I was doing it before.

The short version, is that the code runs through every entity that I tell it to (defined in data-final-fixes.lua, which changes depending on the current modlist), and then checks for specific fields within that entity (such as shift, scale, hr_version, etc) and modifies those values by 2/3 for 3x3 entities, and 3/5 for the 5x5 entities.

The ratios might seem arbitrary, but basically the base size of 3 multiplied by the ratio of (2/3) cancels out the three's, and leaves the two, turning 3x3 sprites into 2x2 sprites. Same for turning 5x5 sprites into 3x3 sprites.

The longer explanation, if you open up the latest version of my mod, and check the func.lua file; lines 468-531 contains the entire code provided by Kirazy (where the "magic" happens) which references a few tables defined near the top of the file (fields and ignored_fields).

From what I remember, rescale_entity() is a recursive function, which starts with taking the table value of the entity in question (ex: data.raw.["assembling-machine"]["assembling-machine-2"] ) and then running itself on every table within that entity.

If the sub-table matches a field defined in the fields table, then it multiplies the relevant values within that table by the scalar (the 2/3 or 3/5 ratio mentioned above). Otherwise, it runs itself again on that sub-table; moving into the sub-sub-tables of the entity in question, and continues until it runs out of tables to check, and values to modify.

If the sub-table matches a field defined in the ignored_fields table, then it (of course), ignores those fields. These fields consist of fluid_boxes, energy_source, etc and have to be manually defined (due to not being formulaic, and dependent on the type of machine being resized).

If you want to look at the older versions of the mod (anything before 7.1.0 will work, such as 7.0.6), then you can open those up and see how I was doing most of that logic manually. Instead of a recursive function that checked through every table and magically changed every value; I was manually defining EVERY value that needed to be changed in the function itself, and basically telling it to do the same resizing function. Resulting in hundreds of lines that were incredibly similar.

I believe Kirazy would be okay if you "borrowed" the magic rescaling function he provided (which I would find fairly difficult to build from scratch), and under the license of this mod, you would just have to provide them a bit of credit for the function (and of course, no commercial distribution, lol). You can also check my old logic, if you really want to build it yourself, by hand, the... painstakingly difficult way.

And I would be totally happy to help explain anything in that wall of text above, if you like! :D

4 years ago

Thanks for the help! I'll see what I can do now with this knowledge, probably get rescaling to work properly. And i think I understand everything so no need for further explaining.

New response