Repository navigation
fix(can_place_entity): check the requested direction - #437
Open
hashbender wants to merge 1 commit into
Open
hashbender wants to merge 1 commit into
hashbender wants to merge 1 commit into
Conversation
The client sent `direction.value + 1` and the action mapped it with its own get_entity_direction: `cardinals[direction % 4]`. With Factorio 2.0 directions (0, 4, 8, 12) that is 1, 5, 9 or 13, so every non-inserter was checked facing north and every inserter facing east, whatever direction was asked for. The final check (avoid_entity) mapped the same shifted value through storage.utils.get_entity_direction and got yet another direction. So can_place_entity could say yes for a position place_entity then refused in that direction, and no for one it would build. Send the Factorio direction, as place_entity does, and map it with storage.utils.get_entity_direction, the mapping place_entity uses, so the answer is for the orientation place_entity builds. Swap the collision area's width and height for east/west. Remove the file's global get_entity_direction, which nothing else used. Tests: a server-free run of the action in Lua (lupa) for all four directions plus the client's encoding, and tests/actions: a steam engine blocked only when facing UP. 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
can_place_entityignores the direction it is given, for every entity.The client sends the direction shifted by one:
and
can_place_entity/server.luamaps it with its own global helper:With Factorio 2.0 directions (north 0, east 4, south 8, west 12) the value that arrives is 1, 5, 9 or 13.
% 4is always 1, so every non-inserter is checked facing north and every inserter facing east, whatever was asked for. The final check,storage.utils.avoid_entity, maps the same shifted value throughstorage.utils.get_entity_direction(the mappingplace_entityuses), which doesn't match any of its cases and falls through to a default. The collision area is also always the north-facing footprint.So
can_place_entity(Prototype.SteamEngine, Direction.RIGHT, pos)answers for an engine facing UP. It can say yes whereplace_entitythen refuses that direction, and no whereplace_entitywould build.shift_entityusescan_place_entity, so it inherits the same error.Fix
can_place_entity/client.py: sendDirectionInternal.to_factorio_direction(direction), the same encodingplace_entitysends.can_place_entity/server.lua: map the direction withstorage.utils.get_entity_direction, asplace_entitydoes, so the answer is for the orientationplace_entitybuilds. Swap the collision area's width and height for east/west. Remove the file's globalget_entity_direction; nothing else uses it.can_place_entity/agent.md: one line saying the check is for the given direction.Testing
tests/unit/test_can_place_entity_direction.py(server-free): runs the action in Lua (lupa, already a dependency) against a stub surface, for all four directions, and checks the direction that reachessurface.can_place_entityand the collision area's footprint (3x5 for UP/DOWN, 5x3 for RIGHT/LEFT). It also checks that the client sends 0, 4, 8, 12. Onmain, 3 of these 5 tests fail; with the fix all 5 pass.test_can_place_depends_on_directionintests/actions/test_can_place.py: puts a pipe inside a steam engine's vertical footprint only. Then it checks that UP is refused and RIGHT is accepted. It needs a server and is left to thefactorio-testworkflow; I haven't run it.🤖 Generated with Claude Code