Factorissimo 2 - notnotmelon fork 🍴


A fork of Factorissimo 2 focused on improving performance by implementing several 1.1 features. Can improve performance by 10X or higher. Also fixes several bugs from the original version.

Content
1 year, 3 months ago
1.1
53.9K
Logistics

b [1.2.3] balanced logistic chest blinks contents

1 year, 1 month ago
(updated 1 year, 1 month ago)

hi, I have a strange issue so wanted to ask if there is an alternate for this.

I have a factorissimo building. I have a request chest outside, and passive provider inside, linked. the requester outside has lets say 10 gear.
inside factory I have let's say belt (anything that can consume). bots and logistic network is setup just fine.

the weird issue is about "some" items. for example I have around ten items requested in the requester chest outside, and one of the requests is 10 gear. the problem is balanced mode. I do not want an (input) direction because otherwise the requester chest content shall be emptied into the factory (passive provider). so I use balanced. in this setup the item (gear) blinks in requester chest. chest requests 10 gear but every second it becomes 0 and then 10 and then 0 and so on. the further problem is the bots putting more gear on the chest because if it is 0 then bots shall put gear into the chest. and of course the bots inside factory cannot pick the gear because it is 0 for the bots. interestingly I use this setup for four example chests and they all seem to work, except one chest which blinks a specific item. (game is modded and it blinks on repair pack but I hope you got the idea)

any idea how to solve it?

what are alternates for that problem (to send items into factory using logistic network without flooding unnecessary count)? I thought balanced mode would do that, and actually it works in general, except one specific case which is strange.

1 year, 1 month ago

I am having the same issue, but it's not consistent.

Sometimes, if I set a limit on the inside chest (to say, 4 slots) and the outside is open to all slots, it'll blink until it's got more than the limit of the inside. Then it'll even out and stop blinking. This sometimes is forced to stop the blinking when the inside limit is cleared and then changed again to something lower than the total available.

Not sure when this error was introduced. It worked fine months ago and I've only recently come back to play Factorio.

1 year, 1 month ago
(updated 1 year, 1 month ago)

** I played around in the code for version 1.2.3 and I'm happy with the outcome, but not sure if it's a proper fix...

I decided to look at the code and found the balance() function in chest.lua.

Items with metadata get moved by stack, so the count of stacks versus count of items is required. Doesn't matter if science packs differ by 40, the stack count is only off by one. Moving "40 science packs" could end up moving 100 because it's the first stack found when balancing. That plus the while loop checks for count > 0, and the count is decremented by only 0 because the swapped stacks replace each other; the value removed from count will always be 0 from the empty stack retrieved from the destination inventory.

Hope this helps for a real fix.

local function move_item(item, count, input_inv, output_inv)
if check_for_basic_item(item) then
-- basic item being transfered
local inserted_count = output_inv.insert{name = item, count = count}
if inserted_count > 0 then
input_inv.remove{name = item, count = inserted_count}
end
else
-- advanced item being transfered, need to preserve tags, durablity, ect
-- not safe to "split" the stack here, may result in some item sloshing
while count > 0 do
local stack = input_inv.find_item_stack(item)
local empty_slot, i = output_inv.find_empty_stack(item)
if not stack or not empty_slot then break end
if output_inv.supports_bar() and output_inv.get_bar() == i then break end
if not stack.swap_stack(empty_slot) then break end
-- Changed stack to empty_slot
count = count - empty_slot.count
end
output_inv.sort_and_merge()
end
end

-- Added function to just add stacks of items
local function move_advanced_item(item, count, input_inv, output_inv)
while count > 0 do
local stack = input_inv.find_item_stack(item)
local empty_slot, i = output_inv.find_empty_stack(item)
if not stack or not empty_slot then break end
if output_inv.supports_bar() and output_inv.get_bar() == i then break end
if not stack.swap_stack(empty_slot) then break end
count = count - 1
end
output_inv.sort_and_merge()
end

local floor = math.floor
local function balance(outside_inv, inside_inv)
outside_inv.sort_and_merge()
inside_inv.sort_and_merge()
local outside_contents = outside_inv.get_contents()
local inside_contents = inside_inv.get_contents()
for item, count in pairs(outside_contents) do
if check_for_basic_item(item) then
local count2 = inside_contents[item] or 0
local diff = count - count2
if diff > 1 then
move_item(item, floor(diff / 2), outside_inv, inside_inv)
elseif diff < -1 then
move_item(item, floor(-diff / 2), inside_inv, outside_inv)
end
else
-- Non-basic items will be balanced by stacks instead
local stack = outside_inv.find_item_stack(item)
local stack_size = stack.prototype.stack_size
local stack_count = floor(count/stack_size)
local stack_count2 = floor((inside_contents[item] or 0)/stack_size)
local diff = stack_count - stack_count2
if diff > 1 then
move_advanced_item(item, floor(diff / 2), outside_inv, inside_inv)
elseif diff < -1 then
move_advanced_item(item, floor(-diff / 2), inside_inv, outside_inv)
end
end
end
for item, count in pairs(inside_contents) do
if check_for_basic_item(item) then
if count > 1 and not outside_contents[item] then
move_item(item, floor(count / 2), inside_inv, outside_inv)
end
else
-- Non-basic items will be balanced by stacks instead
local stack = inside_inv.find_item_stack(item)
local stack_size = stack.prototype.stack_size
local stack_count = floor(count/stack_size)
if stack_count > 1 and not outside_contents[item] then
move_advanced_item(item, floor(stack_count / 2), inside_inv, outside_inv)
end
end
end
end

6 months ago

I'm having this exact issue with my game, as stated by sgtdubious. Logistics chests on medium size factory, but doesn't always seem to be re-createable.

To save time, if you're interested in nailing this down I can provide a link for the mod developer to my save game file. Just let me know :)

6 months ago
(updated 6 months ago)

This is intended. Splitting the stack would cause tons of issues such as deleting metadata from items, and dupe glitches from resetting science pack durability. In the original factorissimo you can dupe with this.

5 months ago

Aaaah, gotcha. I see now, it's only items with durability... makes sense why this would cause dupes. Thanks :)

New response