Repository navigation
fix(pickup_entity): return the contents of every inventory, not only index 1 - #436
Open
hashbender wants to merge 1 commit into
Open
hashbender wants to merge 1 commit into
hashbender wants to merge 1 commit into
Conversation
pickup_entity only returned inventory index 1 (defines.inventory.chest) before destroying the entity. In Factorio 2.0 that is only a chest's contents or a burner's fuel: a furnace's ore and plates, an assembler's ingredients, products and modules, and a lab's packs live in other inventories and were lost. Loop over 1..get_max_inventory_index() instead, and give back the item that places the entity (items_to_place_this) rather than an item named after the entity, which differs for e.g. rails. Tests: test_pickup_furnace_returns_its_input. 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
Before destroying an entity,
pickup_entity/server.luareturns onlydefines.inventory.chest(index 1) to the character:In Factorio 2.0, index 1 is a chest's contents or a burner's fuel. Everything else lives in other inventories and is destroyed with the entity:
So picking up a furnace gives back its fuel and loses the ore and plates.
Separately, the entity is returned as an item named
ent.name. That is wrong whenever the item that places an entity has a different name. In 2.0 therailitem places astraight-rail, so picking up a rail would insert astraight-railitem, which doesn't exist.Fix
1..ent.get_max_inventory_index()and return the contents of every inventory the entity has. The inventory-full check runs on the whole list before anything is inserted or destroyed, as before.prototype.items_to_place_this[1](name and count), falling back toent.name.Testing
test_pickup_furnace_returns_its_inputintests/actions/test_pickup_entity.py: puts 10 iron ore in an unfuelled stone furnace, picks it up, and checks that the 10 ore and the furnace are back in the inventory. It needs a server and is left to thefactorio-testworkflow; I haven't run it.luac -pparses the changed Lua. ruff 0.11.13 format/check clean.Notes
get_contents_compat), as the chest path already did. Durability (lab packs) and quality are not carried over.🤖 Generated with Claude Code