Repository navigation
fix(place_entity_next_to): consume the item, never place for free - #425
Open
hashbender wants to merge 2 commits into
Open
hashbender wants to merge 2 commits into
hashbender wants to merge 2 commits into
Conversation
place_entity_next_to created the entity first and then removed the item only if `get_main_inventory().can_insert(item)`. That checks for room, not for the item, so a character holding none of the item could still place it (and keep placing it), and when there was no room it raised after the entity had already been built. Check that the character holds the item before placing, remove it with player.remove_item like place_entity does, and destroy the new entity if the removal fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The test placed a boiler without holding one and only passed because place_entity_next_to did not consume items. 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
place_entity_next_tobuilds entities the character doesn't have:Calling it in a loop with 5 wooden chests in the inventory kept placing chests after the 5th, all for free.
Root cause
place_entity_next_to/server.lua:533creates the entity first.:547-549then removes the item onlyif player.get_main_inventory().can_insert(item_stack). That checks whether there is room for the item, not whether the character holds it, andremoveof a missing item just removes 0.place_entitygets this right:validate_inventory()before placing, thenplayer.remove_item.Fix
No <item> in inventory. Current inventory: ...(the same message asplace_entity) before placing if the character holds none.player.remove_item{name = entity, count = 1}, asplace_entitydoes.Testing
Run against a Factorio 2.0.73 headless server:
test_place_next_to_without_item_places_nothingfails onmain("DID NOT RAISE") and passes with the fix. Newtest_place_next_to_consumes_itempasses on both.main(the loop's cap) and exactly 5 with the fix, which then raised "No wooden-chest in inventory".tests/actions/test_place_entity_next_to.pyandtest_place_next_to_and_rotate.py: no new failures.test_adjacent_electric_mining_drills,test_collision_resolution_with_helpful_errorsandtest_belt_smart_collision_avoidancefail onmaintoo on this map.can_insertpass), so it's covered by reading the code rather than by a test.🤖 Generated with Claude Code