Skip to content

fix(pickup_entity): return the contents of every inventory, not only index 1 - #436

Open
hashbender wants to merge 1 commit into
JackHopkins:mainfrom
hashbender:fix/pickup-entity-all-inventories
Open

hashbender wants to merge 1 commit into
JackHopkins:mainfrom
hashbender:fix/pickup-entity-all-inventories

Conversation

@hashbender

Copy link
Copy Markdown

Problem

Before destroying an entity, pickup_entity/server.lua returns only defines.inventory.chest (index 1) to the character:

if ent.get_inventory(defines.inventory.chest) then
    -- insert chest contents ...
end
...
table.insert(items_to_insert, {name=ent.name, count=1})
...
ent.destroy{...}

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:

  • a furnace's source (ore) and result (plates);
  • an assembler's ingredients, products and modules;
  • a lab's science packs.

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 the rail item places a straight-rail, so picking up a rail would insert a straight-rail item, which doesn't exist.

Fix

  • Loop over 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.
  • Return the entity's prototype.items_to_place_this[1] (name and count), falling back to ent.name.
  • Belt contents and ground-item pickup are unchanged.

Testing

  • New test_pickup_furnace_returns_its_input in tests/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 the factorio-test workflow; I haven't run it.
  • luac -p parses the changed Lua. ruff 0.11.13 format/check clean.

Notes

  • Contents are counted by name (get_contents_compat), as the chest path already did. Durability (lab packs) and quality are not carried over.
  • An inserter's held item is still not returned.

🤖 Generated with Claude Code

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant