Even Distribution


Modifies CTRL + Click Drag to evenly distribute the items over multiple buildings. Also adds Inventory Cleanup hotkey (SHIFT+C) which evenly distributes unneeded items from inventory into nearby machines.

Utilities
5 months ago
0.15 - 2.1
532K

b Non-recoverable SOLUTION while waiting for author

a month ago
(updated 11 days ago)

Until the author updates the mod, I recommend fixing the error by yourself.
Use notepad++.
UPD: this is enough to start the game. Full fix is described by user akobberup in the comments below.
1. Go to appdata\Roaming\Factorio\Mods\
2. Unzip even-distribution_2.1.0.zip. You will get the even-distribution_2.1.0 folder.
3. Open npp
4. Ctrl+Shift+F -> Choose that folder -> subfolders checkbox YES -> Replace fuel_category with fuel_categories -> Replace in files
5. Delete the original even-distribution_2.1.0.zip
6. RMB on folder even-distribution_2.1.0 -> 7zip -> add to even-distribution_2.1.0.zip
7. Delete our folder

a month ago

Bro, you load game after your fix? I did yeasterday same like you and this isn't all what you must do.

a month ago
(updated a month ago)

Bro, you load game after your fix? I did yeasterday same like you and this isn't all what you must do.

Yup. Works fine. Perhaps you saw what I wrote at the very beginning. But i edited my post in ~15 mins after initial one. I made a mistake, as I was reproducing the steps from memory and mixed up CTRL+H (replace) and CTRL+SHIFT+F (find in files) bcuz it must be replaced in several files.

Search "fuel_category" (7 hits in 5 files of 31 searched)
\AppData\Roaming\Factorio\mods\even-distribution_2.1.0\scripts\cleanup.lua (1 hits)
Line 267: if entity.burner and entity.burner.fuel_categories[prototype.fuel_category] and entity:inventory("fuel").can_insert(item) then
\AppData\Roaming\Factorio\mods\even-distribution_2.1.0\scripts\drag.lua (1 hits)
Line 315: elseif entity.burner and entity.burner.fuel_categories[prototype.fuel_category] then
\AppData\Roaming\Factorio\mods\even-distribution_2.1.0\scripts\helpers\LuaControl.lua (1 hits)
Line 169: for __,inferiorFuel in pairs(storage.fuelList[prototype.fuel_category]) do
\AppData\Roaming\Factorio\mods\even-distribution_2.1.0\scripts\helpers.lua (2 hits)
Line 63: ["fuel"] = function(obj) return obj.object_name == "LuaItemStack" and obj.prototype.fuel_category ~= nil or obj.fuel_category ~= nil end,
\AppData\Roaming\Factorio\mods\even-distribution_2.1.0\scripts\setup.lua (2 hits)
Line 49: :groupBy("fuel_category")
Line 297: if item.fuel_category and not defaultTrash[name] then -- fuels default to 2 stacks as desired amount

a month ago
(updated a month ago)

Hello everyone, for as long as the author is away I'm trying to maintain a fork of this Mod, for all those that don't like to dabbel with the code.

https://mods.factorio.com/mod/even-distribution-fork

I'm pretty sure I solved all current issues, if not, hit me up, I try to check the mod portal daily.

a month ago

fiftystars' solution worked for me as well.

a month ago

yeah just 'advertising' here a bit since I abandoned the mod out of fear for dealing with code until I was so fed up that I made a fork lul.

a month ago

And since I actively play I'll also deal with future problems :)

a month ago

Until the author updates the mod, I recommend fixing the error by yourself.
Use notepad++.
1. Go to appdata\Roaming\Factorio\Mods\
2. Unzip even-distribution_2.1.0.zip. You will get the even-distribution_2.1.0 folder.
3. Open npp
4. Ctrl+Shift+F -> Choose that folder -> subfolders checkbox YES -> Replace fuel_category with fuel_categories -> Replace in files
5. Delete the original even-distribution_2.1.0.zip
6. RMB on folder even-distribution_2.1.0 -> 7zip -> add to even-distribution_2.1.0.zip
7. Delete our folder

Thanks for the fix, game starts again !

a month ago

I made a fuller fix for 2.1. Search-and-replace gets the game to start, but fuel distribution into burner machines is still broken. In 2.1, LuaItemPrototype.fuel_categories is an array of strings (nil when the item isn't a fuel). Code like burner.fuel_categories[prototype.fuel_categories] indexes with a table, so it is always nil.

Unzip even-distribution_2.1.0.zip, make the changes below, and zip the folder again (the zip must contain the even-distribution_2.1.0 folder).

1. scripts/util.lua - add these two functions just above function util.enablesRobots(tech):

function util.fuelCategories(prototype)
        return prototype.fuel_categories or {}
end

function util.burnerAccepts(burner, prototype)
        if not burner then return false end

        for __,category in pairs(util.fuelCategories(prototype)) do
                if burner.fuel_categories[category] then return true end
        end

        return false
end

2. scripts/setup.lua, around line 46 - replace the whole storage.fuelList = _(prototypes.item) ... :toPlain() block with:

        storage.fuelList = {}
        for __,prototype in pairs(prototypes.item) do
                for __,category in pairs(util.fuelCategories(prototype)) do
                        storage.fuelList[category] = storage.fuelList[category] or {}
                        table.insert(storage.fuelList[category], prototype)
                end
        end

        for __,fuels in pairs(storage.fuelList) do
                table.sort(fuels, function(a,b)
                        if a.fuel_value ~= b.fuel_value then return a.fuel_value < b.fuel_value end
                        return a.name < b.name
                end)
        end

(The old :sort() never actually sorted anything, because it ran table.sort on the grouped table, which is keyed by category. "Replace inferior fuel" needs the lists in ascending order.)

3. scripts/setup.lua, around line 297:

if item.fuel_category and not defaultTrash[name] then

becomes

if item.fuel_categories and not defaultTrash[name] then

4. scripts/drag.lua, line 315:

elseif entity.burner and entity.burner.fuel_categories[prototype.fuel_category] then

becomes

elseif util.burnerAccepts(entity.burner, prototype) then

5. scripts/cleanup.lua, line 267:

if entity.burner and entity.burner.fuel_categories[prototype.fuel_category] and entity:inventory("fuel").can_insert(item) then

becomes

if util.burnerAccepts(entity.burner, prototype) and entity:inventory("fuel").can_insert(item) then

6. scripts/helpers.lua, line 63 - the "fuel" condition:

["fuel"] = function(obj) return obj.object_name == "LuaItemStack" and obj.prototype.fuel_categories ~= nil or obj.object_name == "LuaItemPrototype" and obj.fuel_categories ~= nil end,

7. scripts/helpers/LuaControl.lua, around line 169 - replace

                for __,inferiorFuel in pairs(storage.fuelList[prototype.fuel_category]) do
                    if inferiorFuel.name == prototype.name or limit <= 0 then break end

with

                local burner = self.burner
                local inferiorFuels = {}
                for __,category in pairs(scripts.util.fuelCategories(prototype)) do
                    if burner and burner.fuel_categories[category] then
                        for __,fuel in pairs(storage.fuelList[category] or {}) do
                            if fuel.name == prototype.name then break end
                            inferiorFuels[#inferiorFuels + 1] = fuel
                        end
                    end
                end

                for __,inferiorFuel in pairs(inferiorFuels) do
                    if limit <= 0 then break end

The rest of that loop stays as it is.

Alternatively, the Even Distribution Fork (2.1.1) says it handles multiple fuel categories, so switching to it is probably easiest until the original is updated.

New response