Infinite Research Supply MK4

by arenio

This mod adds a craftable chest that contains an infinite supply of science packs. 0.18.x Patch. Simply adds a new chest that also produces space science.

Content
2 years ago
1.1
1.40K
Storage Cheats

g more optimal way to do things

2 years ago
  1. Use the Infinity Chest prototype, set with None as the show gui option.
  2. In control, set the filters.
  3. Read the science pack information from the lab prototypes. This would allow the mod to work with ALL future mods that add additional science packs.

--control.lua

-- create a list of all Chests
script.on_init(function()
global.infiniteResearchContainers={}
initialize_science_packs()
end)

script.on_configuration_changed(function(data)
initialize_science_packs()
for uid,chest in pairs(global.infiniteResearchContainers) do --for each force that has built chests
if not chest.valid then -- delete chest if not valid
global.infiniteResearchContainers[uid]=nil
else
set_infinity_container_filters(chest)
end
end
end)

function set_infinity_container_filters(chest)
local index = 1
for name, count in pairs(global.science_packs) do
chest.set_infinity_container_filter(index, {name=name, count=count, mode="exactly", index=index})
index = index + 1
end
end

function initialize_science_packs()
global.science_packs = {}

-- Blacklist all science packs by default.  Any mod that wishes to not blacklist a science pack will need to use the remote interface to remove the blacklist entry.
for _, lab in pairs(game.get_filtered_entity_prototypes{{filter="type", type="lab"}}) do
    for _, science_pack in pairs(lab.lab_inputs) do
        global.science_packs[science_pack] = game.item_prototypes[science_pack].stack_size
    end
end

end

-- add new Chests to list
script.on_event({defines.events.on_built_entity,defines.events.on_robot_built_entity},
function(e)
--this is reaction to our entities being built
local en=e.created_entity
--first we check if it's our entity
if en.name=='infinite-research-container' then
local uid=en.unit_number --many entities have this field, which is guaranteed to be unique
global.infiniteResearchContainers[uid]=en --we store the reference to our receivers on per-force basis
set_infinity_container_filters(en)
end
end
)

New response