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
3 months ago
0.15 - 2.1
527K

b Crash

11 days ago

When i load in my world, game crashing to main menu and give this error:
Error while running event even-distribution::on_init()
LuaItemPrototype doesn't contain key fuel_category.
stack traceback:
[C]: in function 'index'
__even-distribution
/scripts/setup.lua:297: in function 'generateTrashItemList'
even-distribution/scripts/setup.lua:16: in function 'func'
even-distribution/framework.lua:49: in function 'handleEvent'
even-distribution/framework.lua:58: in function <even-distribution/framework.lua:58>

11 days ago

It's not updated yet for the latest experimental release that just came out a few hours ago (2.1.20).

11 days ago

2.1.20 Modding System: An important change has been made to the game code, fuel_category replacing the original field with fuel_categories.
I changed 'fuel category' to 'fuel categories' in some of the mod's files, and it works.

10 days ago

Frank, that will keep it from crashing the game but it certainly doesn't work after. From example using CTRL+drag over entities does nothing. So seems like that change impacted something else aside from just the name.

10 days ago

It really works for me.
https://imgur.com/a/2MW7asM

10 days ago

Okay oddly enough it started working for me too, but I needed to use NEW coal, not coal that was already in my inventory from before the update to 2.1.20. As such it seems like there is some migration issue between 2.1.19 and 2.1.20 that doesn't change something on the fuel in your inventory causing the issue.

10 days ago
10.031 Error ServerMultiplayerManager.cpp:85: MultiplayerManager failed: "The mod Even Distribution (2.1.0) caused a non-recoverable error.
Please report this error to the mod author.
Error while running event even-distribution::on_configuration_changed
10 days ago

same here, also on 2.1.20
The mod Even Distribution (2.1.0) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event even-distribution::on_init()
LuaItemPrototype doesn't contain key fuel_category.
stack traceback:
[C]: in function 'index'
__even-distribution
/scripts/setup.lua:297: in function 'generateTrashItemList'
even-distribution/scripts/setup.lua:16: in function 'func'
even-distribution/framework.lua:49: in function 'handleEvent'
even-distribution/framework.lua:58: in function <even-distribution/framework.lua:58>

10 days ago

Opus 5.5 response:
Root cause and full fix for 2.1.20 (fuel_category → fuel_categories)

Following up on Frank_ACE and MechBFP: a straight rename stops the crash, but CTRL+drag then does nothing for fuel. In 2.1.20 the new field has a different shape depending on the object:

LuaItemPrototype.fuel_categories is array[string]?, e.g. {"chemical"}. It is nil when the item isn't a fuel.
LuaBurner.fuel_categories is dictionary[string → true], e.g. {chemical = true}.
So entity.burner.fuel_categories[prototype.fuel_categories] never matches. Looping over the item's categories with pairs() doesn't match either, because it yields the indices 1, 2, … rather than the category names.

Six places need changing:

  1. scripts/helpers.lua:63 (the "fuel" condition): a plain rename is enough here, since it only checks for nil.
    ["fuel"] = function(obj) return obj.object_name == "LuaItemStack" and obj.prototype.fuel_categories ~= nil or obj.fuel_categories ~= nil end,

  2. scripts/setup.lua:297 (generateTrashItemList, the crash in this thread): a plain rename.
    if item.fuel_categories and not defaultTrash[name] then

  3. scripts/setup.lua:49 (the fuel upgrade list): groupBy("fuel_category") can't be a string key any more. The helper calls a function key as key(k, v), and after :toArray() the k is a number, so the item is the second argument:
    :groupBy(function(__, item)
    return item.fuel_categories and item.fuel_categories[1]
    end)

  4. scripts/drag.lua:315 (why CTRL+drag stops working):
    elseif entity.burner and prototype.fuel_categories and (function()
    for __,category in ipairs(prototype.fuel_categories) do
    if entity.burner.fuel_categories[category] then return true end
    end
    return false
    end)() then

  5. scripts/cleanup.lua:267 (SHIFT+C): the same pattern.
    local burnerAccepts = false
    if entity.burner and prototype.fuel_categories then
    for __,category in ipairs(prototype.fuel_categories) do
    if entity.burner.fuel_categories[category] then burnerAccepts = true break end
    end
    end
    if burnerAccepts and entity:inventory("fuel").can_insert(item) then

  6. scripts/helpers/LuaControl.lua:169 (replacing lower-tier fuel): this is easy to miss. It doesn't crash on load, only the first time the mod tries to swap out lower-tier fuel.
    for __,inferiorFuel in pairs(storage.fuelList[prototype.fuel_categories[1]] or {}) do

Notes:

Items with more than one fuel category go into the upgrade list under their first category only. That matches the old behaviour, where each item had exactly one category.
If you unzip the mod to patch it, rezip it with the top-level even-distribution_2.1.0/ folder inside. Also rename or remove the original zip: if both are in the mods folder, Factorio keeps loading the original zip and your patched copy is ignored.
API references: LuaItemPrototype::fuel_categories, LuaBurner::fuel_categories

9 days ago

Opus 5.5 response:
Root cause and full fix for 2.1.20 (fuel_category → fuel_categories)

Following up on Frank_ACE and MechBFP: a straight rename stops the crash, but CTRL+drag then does nothing for fuel. In 2.1.20 the new field has a different shape depending on the object:

LuaItemPrototype.fuel_categories is array[string]?, e.g. {"chemical"}. It is nil when the item isn't a fuel.
LuaBurner.fuel_categories is dictionary[string → true], e.g. {chemical = true}.
So entity.burner.fuel_categories[prototype.fuel_categories] never matches. Looping over the item's categories with pairs() doesn't match either, because it yields the indices 1, 2, … rather than the category names.

Six places need changing:

  1. scripts/helpers.lua:63 (the "fuel" condition): a plain rename is enough here, since it only checks for nil.
    ["fuel"] = function(obj) return obj.object_name == "LuaItemStack" and obj.prototype.fuel_categories ~= nil or obj.fuel_categories ~= nil end,

  2. scripts/setup.lua:297 (generateTrashItemList, the crash in this thread): a plain rename.
    if item.fuel_categories and not defaultTrash[name] then

  3. scripts/setup.lua:49 (the fuel upgrade list): groupBy("fuel_category") can't be a string key any more. The helper calls a function key as key(k, v), and after :toArray() the k is a number, so the item is the second argument:
    :groupBy(function(__, item)
    return item.fuel_categories and item.fuel_categories[1]
    end)

  4. scripts/drag.lua:315 (why CTRL+drag stops working):
    elseif entity.burner and prototype.fuel_categories and (function()
    for __,category in ipairs(prototype.fuel_categories) do
    if entity.burner.fuel_categories[category] then return true end
    end
    return false
    end)() then

  5. scripts/cleanup.lua:267 (SHIFT+C): the same pattern.
    local burnerAccepts = false
    if entity.burner and prototype.fuel_categories then
    for __,category in ipairs(prototype.fuel_categories) do
    if entity.burner.fuel_categories[category] then burnerAccepts = true break end
    end
    end
    if burnerAccepts and entity:inventory("fuel").can_insert(item) then

  6. scripts/helpers/LuaControl.lua:169 (replacing lower-tier fuel): this is easy to miss. It doesn't crash on load, only the first time the mod tries to swap out lower-tier fuel.
    for __,inferiorFuel in pairs(storage.fuelList[prototype.fuel_categories[1]] or {}) do

Notes:

Items with more than one fuel category go into the upgrade list under their first category only. That matches the old behaviour, where each item had exactly one category.
If you unzip the mod to patch it, rezip it with the top-level even-distribution_2.1.0/ folder inside. Also rename or remove the original zip: if both are in the mods folder, Factorio keeps loading the original zip and your patched copy is ignored.
API references: LuaItemPrototype::fuel_categories, LuaBurner::fuel_categories

This seems to work

7 days ago

It works for me too, thanks !

New response