What I like about your mod is that it fixes a major bottleneck with vanilla roboports while being modular--most other solutions to roboports seem to be integrated into overhaul packs which almost invariably require a core mod with some side effects(eg. moving stuff around and changing vanilla recipes and/or vanilla tech tree). Unfortunately, if you do happen to use this mod with any other mod pertaining to roboports, this mod will replace their roboports with its own. I don't know if this is intentional or not, as it seems to be a side effect of automatically upgrading to the latest roboport. Assuming this isn't intentional, I'd like to propose a fix. The root cause of this is that you wrote your upgradeRoboports and onBuiltEntity functions to act on any entities of type="roboport."
Code: Select all
function upgradeRoboports(upgrade)
local surface = game.players[1].surface
for c in surface.get_chunks() do
--replace all roboports preserving contents
if roboport_auto_replace_method == "both" or roboport_auto_replace_method == "onresearch" then
for _, entity in ipairs(surface.find_entities_filtered({area={{c.x * 32, c.y * 32}, {c.x * 32 + 32, c.y * 32 + 32}}, type="roboport"})) do
local pos = entity.position
local countC = entity.get_inventory(1).get_item_count("construction-robot")
local countL = entity.get_inventory(1).get_item_count("logistic-robot")
local countR = entity.get_inventory(2).get_item_count("repair-pack")
local backerName = entity.backer_name
entity.destroy()
newRobo = surface.create_entity({name=itemList[upgrade+1], position=pos, force="player"})
if countC > 0 then
newRobo.get_inventory(1).insert({name="construction-robot", count=countC})
end
if countL > 0 then
newRobo.get_inventory(1).insert({name="logistic-robot", count=countL})
end
if countR > 0 then
newRobo.get_inventory(2).insert({name="repair-pack", count=countR})
end
newRobo.backer_name = backerName
end
end
--change any roboport assembling machines to have upgraded recipe and convert any old roboports in the output slot to new ones
if roboport_recipe_update then
for _, entity in ipairs(surface.find_entities_filtered({area={{c.x * 32, c.y * 32}, {c.x * 32 + 32, c.y * 32 + 32}}, type="assembling-machine"})) do
if entity.recipe then
if entity.recipe.name == "roboport" or string.sub(entity.recipe.name, 1, 20) == "qcm-roboport-upgrade" then
local itemcount = entity.get_output_inventory().get_item_count(itemList[upgrade+0])
entity.recipe=game.players[1].force.recipes[recipeList[upgrade+1]]
if itemcount > 0 then
entity.get_output_inventory().clear()
entity.get_output_inventory().insert({name=itemList[upgrade+1], count=itemcount})
end
end
end
end
end
end
end
Code: Select all
function onBuiltEntity(event)
local entity = event.created_entity
if entity.type == "roboport" then
local versionNumber = getVersion()
if versionNumber > 0 then
local pos = entity.position
local backerName = entity.backer_name
entity.destroy()
newRobo = game.players[1].surface.create_entity({name=itemList[versionNumber], position=pos, force="player"})
newRobo.backer_name = backerName
end
end
end
A way to fix these, in a way that I think matches your intent, would be to use this condition
Code: Select all
entity.name == "roboport" or string.sub(entity.name, 1, 20) == "qc-roboport-upgrade"
to get the following modified functions:
Code: Select all
function upgradeRoboports(upgrade)
local surface = game.players[1].surface
for c in surface.get_chunks() do
--replace all roboports preserving contents
if roboport_auto_replace_method == "both" or roboport_auto_replace_method == "onresearch" then
for _, entity in ipairs(surface.find_entities_filtered({area={{c.x * 32, c.y * 32}, {c.x * 32 + 32, c.y * 32 + 32}}, type="roboport"})) do
if entity.name == "roboport" or string.sub(entity.name, 1, 20) == "qc-roboport-upgrade" then
local pos = entity.position
local countC = entity.get_inventory(1).get_item_count("construction-robot")
local countL = entity.get_inventory(1).get_item_count("logistic-robot")
local countR = entity.get_inventory(2).get_item_count("repair-pack")
local backerName = entity.backer_name
entity.destroy()
newRobo = surface.create_entity({name=itemList[upgrade+1], position=pos, force="player"})
if countC > 0 then
newRobo.get_inventory(1).insert({name="construction-robot", count=countC})
end
if countL > 0 then
newRobo.get_inventory(1).insert({name="logistic-robot", count=countL})
end
if countR > 0 then
newRobo.get_inventory(2).insert({name="repair-pack", count=countR})
end
newRobo.backer_name = backerName
end
end
end
--change any roboport assembling machines to have upgraded recipe and convert any old roboports in the output slot to new ones
if roboport_recipe_update then
for _, entity in ipairs(surface.find_entities_filtered({area={{c.x * 32, c.y * 32}, {c.x * 32 + 32, c.y * 32 + 32}}, type="assembling-machine"})) do
if entity.recipe then
if entity.recipe.name == "roboport" or string.sub(entity.recipe.name, 1, 20) == "qcm-roboport-upgrade" then
local itemcount = entity.get_output_inventory().get_item_count(itemList[upgrade+0])
entity.recipe=game.players[1].force.recipes[recipeList[upgrade+1]]
if itemcount > 0 then
entity.get_output_inventory().clear()
entity.get_output_inventory().insert({name=itemList[upgrade+1], count=itemcount})
end
end
end
end
end
end
end
Code: Select all
function onBuiltEntity(event)
local entity = event.created_entity
if entity.name == "roboport" or string.sub(entity.name, 1, 20) == "qc-roboport-upgrade" then
local versionNumber = getVersion()
if versionNumber > 0 then
local pos = entity.position
local backerName = entity.backer_name
entity.destroy()
newRobo = game.players[1].surface.create_entity({name=itemList[versionNumber], position=pos, force="player"})
newRobo.backer_name = backerName
end
end
end
There was also a reference to entity.name ~= "roboport" in the uninstall portion of your code which may need to be changed for compatibility with other mods, so that you don't replace other people's roboports with vanilla roboports when your mod is uninstalled, but I didn't actually check to see when that gets called.
I hope that these suggestions are helpful and welcome, and I apologize if this was intentional behavior or if criticism is unwelcome, or if this is the wrong way to communicate this, and I mean absolutely no offense.