Page 1 of 1

AP request: LuaEnity::Mine(entity)

Posted: Fri Oct 28, 2016 12:13 am
by Mylon
Let us call the function to act as if one entity just mined another, including the transfer of inventory, transfer of mining products, etc.

Re: AP request: LuaEnity::Mine(entity)

Posted: Fri Oct 28, 2016 2:58 am
by aubergine18
This can already be achieved with existing API calls, I'm not sure we need a single function for it.

You can already get the inventory of an entity, and even transfer all of them to another entity (spilling on floor if there isn't room), then delete the original entity and insert a stack with it's related item in to the player or mining entity.

Just search API docs for stuff relating to inventory or item or stack, some examples:

* http://lua-api.factorio.com/latest/LuaE ... _inventory
* http://lua-api.factorio.com/latest/LuaE ... _inventory
* http://lua-api.factorio.com/latest/LuaE ... _inventory
* http://lua-api.factorio.com/latest/LuaC ... _inventory
* http://lua-api.factorio.com/latest/LuaC ... t_quickbar
* http://lua-api.factorio.com/latest/LuaC ... can_insert
* http://lua-api.factorio.com/latest/LuaC ... rol.insert
* http://lua-api.factorio.com/latest/LuaC ... ems_inside
* http://lua-api.factorio.com/latest/LuaC ... item_count
* http://lua-api.factorio.com/latest/LuaC ... ems_inside
* http://lua-api.factorio.com/latest/LuaC ... emove_item
* http://lua-api.factorio.com/latest/LuaI ... aInventory -- this one in particular
* http://lua-api.factorio.com/latest/LuaI ... ntory_size
* http://lua-api.factorio.com/latest/LuaI ... _inventory
* http://lua-api.factorio.com/latest/LuaS ... item_stack

As far as I know, the API has full coverage of all things inventory/stack. You can do pretty much everything imaginable with them.

Re: AP request: LuaEnity::Mine(entity)

Posted: Sun Oct 30, 2016 9:48 pm
by Mylon
The API to simulate mining exists, but it's a lot more effort than it's worth. I've already partially recreated it but I've run into some bugs with my implementation.

items on ground are not mined. So mined products, pickup products, and inventory all must be handled separately. Sounds have to be called manually.

Trees, when destroy()'d, don't leave stumps. :(

Re: AP request: LuaEnity::Mine(entity)

Posted: Mon Oct 31, 2016 2:51 am
by Nexela
Mylon wrote: Trees, when destroy()'d, don't leave stumps. :(
Have you tried die()? if that doesn't work then do what the code probably does "destroy the item at x,y, place stump at x,y)

Re: AP request: LuaEnity::Mine(entity)

Posted: Mon Oct 31, 2016 4:40 am
by aubergine18
I must admit, I also had to abandon one of my mods because item-on-ground can't be mined. I thought about having it place as entity, but then it's not possible to pick up with F key. I was hoping to create a situation where picking up would retrieve the existing item, but mining would yield a different item.

Could you elaborate a bit more on what you are trying to achieve?

Re: AP request: LuaEnity::Mine(entity)

Posted: Mon Oct 31, 2016 5:48 pm
by Mylon
aubergine18 wrote: Could you elaborate a bit more on what you are trying to achieve?
This:
https://mods.factorio.com/mods/Mylon/Bluebuild

Auto-demo would be trivial if I could do player.mine(target). Instead I have to get the mined_item, the item inventory, if type = "item-entity" I need to get the item too. Then damage the tool if hardness > 0 (like for trees), play sound, spawn a tree stump, etc.

Also, it seems player.insert(target.get_inventory()) doesn't work if the player's inventory is full, causing items to be deleted! Again, player.mine(target) checks this for me.