Skip to content

fix(pump): serialize pump input/output from Factorio 2.0 pipe connections - #433

Open
hashbender wants to merge 1 commit into
JackHopkins:mainfrom
hashbender:fix/pump-serialization-factorio-2
Open

hashbender wants to merge 1 commit into
JackHopkins:mainfrom
hashbender:fix/pump-serialization-factorio-2

Conversation

@hashbender

Copy link
Copy Markdown

Problem

serialize.lua reads a pump's ports like this:

if entity.type == "pump" then
    serialized.input_position = entity.fluidbox.get_connections(1)[1].position
    serialized.output_position = entity.fluidbox.get_connections(2)[1].position
end

In Factorio 2.0, LuaFluidBox.get_connections(i) returns LuaFluidBox[]. A LuaFluidBox has no position (LuaFluidBox doesn't contain key position), and the list is empty for a pump with nothing attached, so [1] is nil. A pump also has only one fluidbox, so index 2 doesn't exist. Every pump therefore fails to serialize:

  • place_entity(Prototype.Pump, ...) places the pump and takes the item from the inventory, then raises while serializing the result.
  • get_entity(Prototype.Pump, ...) raises.
  • get_entities() drops pumps without saying so.

Pumps can be crafted once fluid-handling is researched.

Fix

  • Read the pump's pipe connections with entity.fluidbox.get_pipe_connections(1), inside a pcall.
  • Use each connection's target_position (the tile a pipe connects from) as input_position or output_position, according to its flow_direction. The 2.0 pump prototype has one output connection to the north and one input connection to the south.
  • Pump gets typed input_position / output_position: Optional[Position] fields, so they parse as Position instead of staying a raw dict (the model allows extra fields).

Testing

  • New tests/actions/test_pump.py:
    • test_place_pump_serializes_input_and_output: places a north-facing pump, checks that the item was used, and checks that the input is south of the pump and the output north of it.
    • test_get_entities_returns_placed_pump: get_entities({Prototype.Pump}) returns the pump, and get_entity reads it back.
    • Both need a server and are left to the factorio-test workflow; I haven't run them.
  • Checks I could run:
    • luac -p parses the changed serialize.lua.
    • A server-free check that Pump(...) turns the two dicts into Positions.
    • The pump's pipe_connections (flow_direction and side) were checked against base/prototypes/entity/entities.lua in 2.0.73.
  • ruff 0.11.13 format/check clean.

🤖 Generated with Claude Code

In Factorio 2.0, LuaFluidBox.get_connections returns LuaFluidBox objects,
which have no `position`, and returns nothing for an unconnected pump. So
serializing any pump raised: place_entity(Prototype.Pump) took the item and
then errored, get_entity raised, and get_entities left pumps out.

Read the pump's pipe connections (get_pipe_connections(1)) instead, inside a
pcall, and use each connection's target_position by flow direction. Add typed
input_position/output_position fields to Pump.

Tests: tests/actions/test_pump.py places a pump and reads it back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant