Mining results not dropping from tree when .mine is called

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2541
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Mining results not dropping from tree when .mine is called

Post by FuryoftheStars »

https://lua-api.factorio.com/latest/Lua ... ntity.mine
The result of mining the entity (the item(s) it produces when mined) will be dropped on the ground if they don't fit into the provided inventory.
Yet, when I call .mine with no parameters (on a tree, at least), this does not appear to happen. Do I need to define an inventory in order for it to work, and if so, how do I get it to... well... not put it in an inventory and just drop to the ground?

Edit: Yeah, so when I give it a valid inventory to insert to, it will insert the mining results to that inventory, and if that inventory is full, it'll drop to the ground at the tree's location. But I want to accomplish this without an inventory....
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Mining results not dropping from tree when .mine is called

Post by Klonan »

It should be pretty easy to add another parameter like 'force_spill', I will move this to modding interface requests

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2541
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Mining results not dropping from tree when .mine is called

Post by FuryoftheStars »

Klonan wrote:
Wed Jun 01, 2022 3:37 pm
It should be pretty easy to add another parameter like 'force_spill', I will move this to modding interface requests
Thanks, Klonan.

Question, though: I was able to get it to force spilling by giving it a valid entity that I call get_inventory() on, but then gave it an invalid inventory for the entity type. eg:

Code: Select all

tree.mine{inventory = steel_chest[1].get_inventory(defines.inventory.fuel), force = true}
where steel_chest[1] is a steel-chest entity:

Code: Select all

local steel_chest = surface.find_entities_filtered{name = "steel-chest"}
(this is a test map, so it's small with only 3 entities... 2 trees and a steel chest).

To my understanding of the get_inventory() command, it should return nil in this case. Yet, leaving "inventory = ..." out, or making it equal nil does not have the same effect.
Return values

:: LuaInventory?

The inventory or nil if none with the given index was found.
I don't know which would be easier, adding a new force_spill parameter, or making it so leaving the inventory parameter blank/making it nil gives the same behavior as a valid entity with a full or invalid inventory? IMO, calling this with no parameters, if I didn't want spillage, I'd just use .destroy() instead? I may not be aware of some use cases and thus why I'm thinking that way, but just wanted to put it out there.

Edit: Ah, never mind, the result of steel_chest[1].get_inventory(defines.inventory.fuel) isn't actually nil. It is returning a table, with some data in it, but likely that key parts are nil (serpent.block() isn't breaking it down enough for me to see. Just a __self = "userdata" and a bunch of __self = 0).

Edit2: :? Ok... so no matter what defines.inventory value I feed the get_inventory() command, it returns with the actual chest's inventory, and as I had the chest full during these test, it just automatically worked. Is this a bug? Should I make a bug report on this?
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2541
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Mining results not dropping from tree when .mine is called

Post by FuryoftheStars »

Well, I seem to have found something for a workaround for now.

Create a container in the data stage that has an inventory_size of 0. Then when I need to mine something and have its mining results spill at its location, I spawn the fake chest, get its inventory, then feed that for the inventory parameter on .mine{}. Once done, destroy the fake chest.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Mining results not dropping from tree when .mine is called

Post by Klonan »

FuryoftheStars wrote:
Wed Jun 01, 2022 6:38 pm
Create a container in the data stage that has an inventory_size of 0. Then when I need to mine something and have its mining results spill at its location, I spawn the fake chest...
You can create a script inventory instead of spawning and destroying an entity:
https://lua-api.factorio.com/latest/Lua ... _inventory

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2541
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Mining results not dropping from tree when .mine is called

Post by FuryoftheStars »

Klonan wrote:
Wed Jun 01, 2022 6:54 pm
FuryoftheStars wrote:
Wed Jun 01, 2022 6:38 pm
Create a container in the data stage that has an inventory_size of 0. Then when I need to mine something and have its mining results spill at its location, I spawn the fake chest...
You can create a script inventory instead of spawning and destroying an entity:
https://lua-api.factorio.com/latest/Lua ... _inventory
*gasps*

Wonderful! That helps, thank you!!
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

Post Reply

Return to “Modding interface requests”