Skip to content

Entity Replacement System (Ongoing work, do not merge)#98

Draft
nicholasgower wants to merge 30 commits into
mainfrom
rocket-lift-multiplier
Draft

Entity Replacement System (Ongoing work, do not merge)#98
nicholasgower wants to merge 30 commits into
mainfrom
rocket-lift-multiplier

Conversation

@nicholasgower

Copy link
Copy Markdown
Collaborator

Description

This PR allows developers to quickly create planet-exclusive entity variants. For example, one could give chemical plants on one planet two additional module slots.

If one were to abuse this system to its limit, they could copy every entity in the game, double the heating energy of each entity, and effectively double the heat required by every entity in the game on a particular planet. The possible performance issues of doing that are currently unknown.

Adding this system required combining rocket silo code and the new entity-replacement code into one event function. I have tested rocket silos to confirm that they still work as they did beforehand.

I would like to see one other developer make a mod with this system before pushing it to the mod portal.

This PR is step one towards adding a "rocket-lift-multiplier" variable to planets that would create variants of rocket silos with different lift capacities for different planets, using a currently-unavailable 2.1 feature.

Checklist

  • Changes have been tested
  • Changes do not break backwards compatibility
  • changelog.txt has been updated
  • README.md has been updated (documentation section and/or Contributors list)

Testing Notes

To test this system, I've made this test mod that creates chemical plant variants for every planet except Nauvis. github.com/nicholasgower/PlanetsLib-testing

@nicholasgower nicholasgower changed the title Entity Replacement System Entity Replacement System (Ongoing work, do not merge) Jun 11, 2026
Comment thread prototypes/override-final/planet-entity-variants.lua Outdated
Comment thread prototypes/override-final/planet-entity-variants.lua Outdated
Comment thread lib/add-entity-replacement.lua
Comment thread lib/add-entity-replacement.lua
local is_ghost = entity.name == "entity-ghost"
local name = is_ghost and entity.ghost_name or entity.name

local is_space = not not surface.platform

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My new favorite lua-ism

Comment on lines +64 to +83
new_entity.copy_settings(entity)

if not is_ghost then
local modules = entity.get_module_inventory().get_contents()
for _, item in pairs(modules) do
local inserted_count = new_entity.insert(item)
if inserted_count < item.count then
item.count = item.count - inserted_count
surface.spill_item_stack {
position = entity.position,
stack = item,
enable_looted = true,
force = entity.force_index,
allow_belts = false
}
end
end
end

entity.destroy()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AIUI, these should all be unnecessary if you use fast_replace = true in the surface.create_entity call. Note that this does mean that entity will be immediately invalid, so any data needed from it would need to be retrieved beforehand.

Comment thread scripts/entity-replacement.lua Outdated

end

--Function called to replace PlanetsLib planet-exclusive entity replacements with original versions. Keeping blueprints in a stable state feels like a safer choice than allowing people to

@JFletcher94 JFletcher94 Jun 12, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can take a look at how Rigor Module does this, in the sanitize_blueprint_entities function:

  • Logic uses bplib.
  • Logic is skipped for cut/paste to preserve external wire connections. Unfortunately, the only way I could figure out how to implement this was to track which players are currently holding the cut tool in storage, because once the blueprint event is fired, the player is now holding the blueprint item, and that information is lost.

Comment thread scripts/entity-replacement.lua Outdated
@danielmartin0 danielmartin0 marked this pull request as draft June 12, 2026 13:34
@nicholasgower

Copy link
Copy Markdown
Collaborator Author

I've requested a feature from Wube to assist in this PR to simplify the removal of entity variants. https://forums.factorio.com/viewtopic.php?t=133940

@nicholasgower

Copy link
Copy Markdown
Collaborator Author

I've implemented an initial version of the rocket lift multiplier system. This is accomplished via a new special_properties field of PlanetsLib:extend and PlanetsLib:update, which is used to pass arbitrary data to a mod-data object. During data-final-fixes, the special properties rocket_part_multiplier and rocket_lift_multiplier (Will be implemented in 2.1) are taken into account to generate a variant of the vanilla rocket silo for every planet. Currently, there seems to be a conflict with Maraxsis, which also replaces the vanilla rocket silo. Right now, script-raised builds are not targeted by PlanetsLib's entity replacement system, since doing so created an infinite loop. I need to find a way to fix that infinite loop.

@nicholasgower

Copy link
Copy Markdown
Collaborator Author

PlanetsLib:extend and PlanetsLib:update now throw an error when called during data-final-fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants