Repository navigation
fix(pump): serialize pump input/output from Factorio 2.0 pipe connections - #433
Open
hashbender wants to merge 1 commit into
Open
hashbender wants to merge 1 commit into
hashbender wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
serialize.luareads a pump's ports like this:In Factorio 2.0,
LuaFluidBox.get_connections(i)returnsLuaFluidBox[]. ALuaFluidBoxhas noposition(LuaFluidBox doesn't contain key position), and the list is empty for a pump with nothing attached, so[1]isnil. 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
entity.fluidbox.get_pipe_connections(1), inside apcall.target_position(the tile a pipe connects from) asinput_positionoroutput_position, according to itsflow_direction. The 2.0 pump prototype has oneoutputconnection to the north and oneinputconnection to the south.Pumpgets typedinput_position/output_position: Optional[Position]fields, so they parse asPositioninstead of staying a raw dict (the model allows extra fields).Testing
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, andget_entityreads it back.factorio-testworkflow; I haven't run them.luac -pparses the changedserialize.lua.Pump(...)turns the two dicts intoPositions.pipe_connections(flow_directionand side) were checked againstbase/prototypes/entity/entities.luain 2.0.73.🤖 Generated with Claude Code