Page 1 of 1

[1.1.76] LuaControl.mine_entity(entity, force?) doesn't check if mined_result can't be added to inventory if force=false

Posted: Sat Jan 28, 2023 1:10 am
by LeonSkills
LuaControl.mine_entity(entity, force?) mentions it will fail if it can't place the items of the entity into the inventory of the LuaControl when force is set to false. (Or at least, that behaviour is implied by the description of when force is true).

These items it checks do not include the mined_result of the entity, only its inventories.

How to reproduce:
Run this in the console with a full inventory while standing near some mineable entities.

Code: Select all

/c for _, entity in pairs(game.player.surface.find_entities_filtered{position=game.player.position, radius=10}) do
  game.player.mine_entity(entity, false)
end
Expected behaviour is that an entity is not mined if their mined result can not be stored in the player inventory, and the method returns false.
Current behaviour is that the entity is mined, if the mined result can not be stored in the player inventory it is spilled on the ground (the expected behaviour of when force is set to true).

It does seem to work as expected for item-on-ground entities, it returns false for them and doesn't reshuffle them around like what happens when force is true. (But they are already on the ground anyway, so doesn't really matter for that entity.)

Re: [1.1.76] LuaControl.mine_entity(entity, force?) seems to ignore the force parameter

Posted: Sat Jan 28, 2023 4:08 am
by lyvgbfh
Does it behave the same if force is nil (unspecified)?

Re: [1.1.76] LuaControl.mine_entity(entity, force?) seems to ignore the force parameter

Posted: Sat Jan 28, 2023 4:22 pm
by LeonSkills
lyvgbfh wrote: Sat Jan 28, 2023 4:08 am Does it behave the same if force is nil (unspecified)?
Default behaviour is equal to force=false

Re: [1.1.76] LuaControl.mine_entity(entity, force?) seems to ignore the force parameter

Posted: Sat Jan 28, 2023 4:24 pm
by LeonSkills
As someone has pointed out on discord, force applies to the items within the inventories of the to be mined entity, not the mined result of it.

If that is the desired behaviour then I guess the documentation should be updated to reflect that. However I still think the mined result should be included in the force check.

Re: [1.1.76] LuaControl.mine_entity(entity, force?) seems to ignore the force parameter

Posted: Sat Jan 28, 2023 5:58 pm
by Rseding91
LeonSkills wrote: Sat Jan 28, 2023 4:24 pm As someone has pointed out on discord, force applies to the items within the inventories of the to be mined entity, not the mined result of it.
That is how it works.

Re: [1.1.76] LuaControl.mine_entity(entity, force?) seems to ignore the force parameter

Posted: Sat Jan 28, 2023 6:00 pm
by Rseding91
LeonSkills wrote: Sat Jan 28, 2023 4:24 pm If that is the desired behaviour then I guess the documentation should be updated to reflect that. However I still think the mined result should be included in the force check.
Due to the nature of Factorio inventories and items knowing "can this set of items fit into this inventory" is currently only possible to know by actually trying to put it into the inventory. Because of that; we don't attempt to check if the mined results of an entity fit into the destination and instead just try to put them in. If that fails we put the items on the ground.