mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-10 00:43:27 +02:00
module to set requests in logi chests to blueprint total costs
This commit is contained in:
parent
f26efb12c3
commit
f121bbd8ca
34
modules/blueprint_requesting.lua
Normal file
34
modules/blueprint_requesting.lua
Normal file
@ -0,0 +1,34 @@
|
||||
--module by Hanakocz
|
||||
local Event = require 'utils.event'
|
||||
|
||||
local function on_gui_closed(event)
|
||||
local entity = event.entity
|
||||
if not entity or not entity.valid then return end
|
||||
if entity.name == 'logistic-chest-requester' or entity.name == 'logistic-chest-buffer' then
|
||||
local inventory = entity.get_inventory(defines.inventory.chest)
|
||||
if not inventory or not inventory.valid then return end
|
||||
if inventory.get_item_count('blueprint') > 0 then
|
||||
local items = {}
|
||||
for i = 1, #inventory, 1 do
|
||||
if inventory[i].valid_for_read and inventory[i].is_blueprint then
|
||||
local cost = inventory[i].cost_to_build
|
||||
for name, amount in pairs(cost) do
|
||||
items[name] = (items[name] or 0) + amount
|
||||
end
|
||||
end
|
||||
end
|
||||
if entity.request_slot_count > 0 then
|
||||
for slot = 1, entity.request_slot_count, 1 do
|
||||
entity.clear_request_slot(slot)
|
||||
end
|
||||
end
|
||||
local slot_index = 1
|
||||
for item, amount in pairs(items) do
|
||||
entity.set_request_slot({name = item, count = amount}, slot_index)
|
||||
slot_index = slot_index + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_gui_closed, on_gui_closed)
|
Loading…
Reference in New Issue
Block a user