AP request: LuaEnity::Mine(entity)

User avatar
Mylon
Filter Inserter
Filter Inserter
Posts: 525
Joined: Sun Oct 23, 2016 11:42 pm
Contact:

AP request: LuaEnity::Mine(entity)

Post 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.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

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

Post 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.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
User avatar
Mylon
Filter Inserter
Filter Inserter
Posts: 525
Joined: Sun Oct 23, 2016 11:42 pm
Contact:

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

Post 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. :(
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

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

Post 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)
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

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

Post 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?
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
User avatar
Mylon
Filter Inserter
Filter Inserter
Posts: 525
Joined: Sun Oct 23, 2016 11:42 pm
Contact:

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

Post 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.
Post Reply

Return to “Implemented mod requests”