From c672602edfe2307bdea51aa168cc5458ce82d5ea Mon Sep 17 00:00:00 2001 From: hashbender <561911+hashbender@users.noreply.github.com> Date: Mon, 9 Nov 2026 18:10:00 -0800 Subject: [PATCH] fix(can_place_entity): allow offshore pumps on land at the shore (Factorio 2.0) can_place_entity refused an offshore pump unless the tile at the position was water. In 2.0 the pump stands on land at the edge of water, so every valid spot was refused, while place_entity (which already searches land tiles next to water) placed the pump fine. Ask surface.can_place_entity instead, with the entity's direction, and say in the error that the pump goes at the edge of water. Update the manual line. Tests: test_can_place_offshore_pump_at_shore places a pump with place_entity, picks it up and checks can_place_entity accepts the same position. Co-Authored-By: Claude Opus 5.5 --- fle/env/tools/agent/can_place_entity/agent.md | 2 +- .../tools/agent/can_place_entity/server.lua | 14 ++++++++++---- tests/actions/test_can_place.py | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/fle/env/tools/agent/can_place_entity/agent.md b/fle/env/tools/agent/can_place_entity/agent.md index 726bf7e5b..e1d1bf91e 100644 --- a/fle/env/tools/agent/can_place_entity/agent.md +++ b/fle/env/tools/agent/can_place_entity/agent.md @@ -49,5 +49,5 @@ else: 3. Special Cases -- Offshore pumps require water tiles +- Offshore pumps are placed on land at the edge of water (Factorio 2.0), not on water tiles - Some entities have specific placement requirements diff --git a/fle/env/tools/agent/can_place_entity/server.lua b/fle/env/tools/agent/can_place_entity/server.lua index c2e481107..577b400e3 100644 --- a/fle/env/tools/agent/can_place_entity/server.lua +++ b/fle/env/tools/agent/can_place_entity/server.lua @@ -50,11 +50,17 @@ storage.actions.can_place_entity = function(player_index, entity, direction, x, error("Cannot place the entity at the specified location due to collision with other entities.") end - -- Additional checks for specific entities like offshore-pump + -- Factorio 2.0: an offshore pump stands on land at the edge of water, so the tile + -- under it is usually not water. Let the game's placement rules decide. if entity == "offshore-pump" then - local tile = player.surface.get_tile(x, y) - if not tile.prototype.name:match("water") then - error("Cannot place the entity at the specified position due to lack of water.") + local can_place = player.surface.can_place_entity{ + name = entity, + force = player.force, + position = position, + direction = direction_enum + } + if not can_place then + error("Cannot place the offshore pump at the specified position: it must be placed at the edge of water.") end end diff --git a/tests/actions/test_can_place.py b/tests/actions/test_can_place.py index 3bcb58ddd..9586c7c9f 100644 --- a/tests/actions/test_can_place.py +++ b/tests/actions/test_can_place.py @@ -34,3 +34,22 @@ def test_can_place_over_player_large(game): game.place_entity( Prototype.SteamEngine, position=Position(x=0, y=0), direction=Direction.UP ) + + +def test_can_place_offshore_pump_at_shore(configure_game): + game = configure_game( + inventory={"offshore-pump": 2}, merge=True, reset_position=True + ) + water = game.nearest(Resource.Water) + game.move_to(water) + pump = game.place_entity(Prototype.OffshorePump, position=water) + position = pump.position + assert game.pickup_entity(pump) + + # Factorio 2.0: the pump stands on land next to the water, not on a water tile + assert any( + game.can_place_entity( + Prototype.OffshorePump, direction=direction, position=position + ) + for direction in (Direction.UP, Direction.RIGHT, Direction.DOWN, Direction.LEFT) + )