Dropping items/modules into machines interacts poorly with LuaSurface#create_entity
Posted: Thu Jun 26, 2025 5:02 pm
I'm working on a custom module-type mod that (for implementation reasons) sometimes requires swapping out a crafting machine with a tweaked version of itself when one of the modded modules is added/removed from it. This can actually be achieved almost perfectly with the built in LuaSurface#create_entity function (kudos to the devs for having such attention to detail!):
There's only one issue I can't seem to solve. Usually when a player drops an item/module into a machine (i.e. by presses "Z"), only 1 item is added to the machine; but if that machine gets fast-replaced, because it's now a different entity, 1 more item gets dropped into it (the same effect as holding "Z" and dragging the cursor across multiple entities). Normally this behavior wouldn't be a problem... but it's an issue when combined with my modded modules. When I drop a single modded module into a machine, it triggers the mod's logic to fast-replace the entity—which causes another module to get dropped into the machine, triggering the fast-replace logic again—and so on until the machine's module slots fill up.
Note: I've only tested entities being fast-replaced by script; I've not tested entities being fast replaced by another player.
This may be too niche an issue to merit addressing. But if it's reasonable, it'd be nice if there were some way for the "don't drop another item into this entity yet" logic to be transferred over to the new entity.
View Code
There's only one issue I can't seem to solve. Usually when a player drops an item/module into a machine (i.e. by presses "Z"), only 1 item is added to the machine; but if that machine gets fast-replaced, because it's now a different entity, 1 more item gets dropped into it (the same effect as holding "Z" and dragging the cursor across multiple entities). Normally this behavior wouldn't be a problem... but it's an issue when combined with my modded modules. When I drop a single modded module into a machine, it triggers the mod's logic to fast-replace the entity—which causes another module to get dropped into the machine, triggering the fast-replace logic again—and so on until the machine's module slots fill up.
Note: I've only tested entities being fast-replaced by script; I've not tested entities being fast replaced by another player.
This may be too niche an issue to merit addressing. But if it's reasonable, it'd be nice if there were some way for the "don't drop another item into this entity yet" logic to be transferred over to the new entity.