Page 1 of 1

Code Cleanup: Remove use of '_dict' for items due to Quality

Posted: Sun Jun 29, 2025 5:11 pm
by Barontox
I am trying to create some mods for game startup on Freeplay.
There is an annoying requirement for item_dict in the insert and remove utilities.

remove dict so i can add or delete items based on quality.

for example:


util.insert_safe = function(entity, item_dict)
if not (entity and entity.valid and item_dict) then return end
local items = prototypes.item
local insert = entity.insert
for name, count in pairs (item_dict) do
if items[name] then
insert{name = name, count = count}
else
log("Item to insert not valid: "..name)
end
end
end

util.remove_safe = function(entity, item_dict)
if not (entity and entity.valid and item_dict) then return end
local items = prototypes.item
local remove = entity.remove_item
for name, count in pairs (item_dict) do
if items[name] then
remove{name = name, count = count}
else
log("Item to remove not valid: "..name)
end
end
end



Both of these functions remove quality as an attribute of the item.