Auto Resource Extra Support


This mod collect and distribute most resources automatically, just like play classic RTS game. Don't need tons of belt/inserter/pipe anymore :), hacked to add extra support for mods

Overhaul
1 year, 2 months ago
1.1
543
Logistics Storage Cheats

i some modifications i did here

4 months ago
(updated 4 months ago)

I moded some code in control.lua for better performance.

in this function:


function do_lab(player,entity)
if not is_lab(entity) then
return false
end

local inv=entity.get_inventory(defines.inventory.lab_input)
for i,v in ipairs(Ksp) do
    local n=inv.get_item_count(v)
    if n<2 then
        try_put_to_entity(player,entity,v,1,inv)
    end
end
return true

end


i changed
if n<1 then
to
if n<2 then
because i had a blinking issue with labs when they work with some stutters, because it runed out for some science pack and script did not get another one before it.

The another is made by chatgpt and it worked as intended. I decided to add a delay for "show" function, becouse it updated too fast, when i wanted to get some resource, by clicking on it, but when you have some resources in "zero zone", the icons start moving prety fast and i needed to do "icon hunting". Here is the solution from chatgpt:


local lastTick = 0
local delayTicks = 60 -- Adjust the delay as needed (60 ticks = 1 second)

function show()
if game.tick - lastTick < delayTicks then
return
end

lastTick = game.tick

for k, v in ipairs(game.connected_players) do
    local f = function()
        return "entity " .. entity_size_str(v.index)
    end

    local res = reslist[v.index]

    if nil == v.gui.top["furnace_type"] then
        create_gui(v.gui.top, v.index)
    end

    if nil == gui[v.index] then
        gui[v.index] = {}
        gui[v.index].restable = v.gui.top["restable"]
        gui[v.index].entityinfo = v.gui.top["entityinfo"]
    end

    for k1, v1 in pairs(res) do
        local g = gui[v.index].restable[k1]
        g.tooltip = v1.count
        if not is_fluid(k1) then
            g.tooltip = g.tooltip .. k1 .. ". Click to get.[Left=1 Right=5 Shift+L=Stack Shift+R=Half stack]"
        end
        g.number = v1.count
        if reslist[1][k1].count == 0 and settings.global["show-resources-with-0"].value == false then
            g.visible = false
        else
            g.visible = true
        end
    end

    gui[v.index].entityinfo.caption = f()
end

end


4 months ago
(updated 4 months ago)

Also, i asked chatgpt to modify a function which fill machines with resources, to not do so, if output inventory of it is not empty, to don't clutter the output of resorces. Prety useful, when you want to debug your production performance.

here is It's answer:


To interrupt the harvest_feed_entity function if the inventory is not empty after processing the recipe.products loop, you can add a condition to check whether the output inventory is empty. If it's not empty, you can exit the function early. Here's the modified code:

lua
Copy code
function harvest_feed_entity(player, e)
local entity = e.entity
--print_inventory(entity)

do_ssp(player, entity)

if do_chest(player, entity) then
    return
end
if do_lab(player, entity) then
    return
end

if do_furnace(player, e) then
    return
end
do_fuel(player, entity)
if false == is_machine(entity) then
    return
end

local recipe = entity.get_recipe()
if recipe == nil then
    return
end

for k, v in ipairs(recipe.products) do
    try_get_from_entity(player, entity, v.name, 9999, entity.get_output_inventory())
end

-- Check if the output inventory is not empty, and if so, exit the function
if not is_inventory_empty(entity.get_output_inventory()) then
    return
end

for k, v in ipairs(recipe.ingredients) do
    local inv = entity.get_inventory(defines.inventory.furnace_source)
    local n = read_entity(entity, v.name)
    local m = v.amount / (recipe.energy / entity.crafting_speed) * 2
    --game.print(v.name.." "..v.amount.." "..recipe.energy.." "..n.." "..m)
    if m < v.amount then
        m = v.amount * 2
    end
    if n < m then
        try_put_to_entity(player, entity, v.name, m - n, inv)
    end
end

end

-- Helper function to check if an inventory is empty
function is_inventory_empty(inv)
for _, stack in pairs(inv.get_contents()) do
if stack > 0 then
return false
end
end
return true
end
I added a check using the is_inventory_empty helper function after the loop processing recipe.products. If the output inventory is not empty, the function will return early. Adjust the condition inside is_inventory_empty as needed based on your inventory structure.


New response