Mining drill real output slot

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
sparr
Smart Inserter
Smart Inserter
Posts: 1327
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Mining drill real output slot

Post by sparr »

I'd like a way to access the item that the drill is holding to output to the ground, when there's already an item sitting on the ground blocking it.

sparr
Smart Inserter
Smart Inserter
Posts: 1327
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: Mining drill real output slot

Post by sparr »

I still want this for Belt Overflow mod

robot256
Filter Inserter
Filter Inserter
Posts: 596
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Mining drill real output slot

Post by robot256 »

This suggestion, or something similar, would allow resolution of a years-old bug in Auto Deconstruct, so I didn't want to create a duplicate thread.

I am following up on a thread from 2018 viewtopic.php?f=7&t=63135 and report to the Auto Deconstruct mod author https://mods.factorio.com/mod/AutoDecon ... 000b9aa0ff. Since I have taken on maintenance of Auto Deconstruct, I would like to raise this issue again as was suggested in the 2018 thread.

The Problem

To summarize, the symptom is that the following events occur in order:
  1. Mining drill performs a mining action, decrementing its last targeted resource entity and adding the ore item to a hidden internal inventory. (Note: when the mining drill drop target is blocked or full, sometimes decrementing the resource is delayed until space is available, but often it occurs immediately regardless of drop status.)
  2. Event on_resource_depleted fires for the resource entity, triggering the Auto Deconstruct code.
  3. Auto Deconstruct reads the type of the depleted resource, and marks the mining drill for deconstruction, which prevents it from dropping the ore item in the hidden internal inventory. At this time, entity.mining_progress and entity.bonus_mining_progress are small nonzero values indicating a progress of "1 tick" even though there is no resource to be mined.
  4. The depleted resource entity is destroyed automatically. entity.mining_target becomes invalid, and it is no longer possible to determine the type of resource that might be held in the mining drill's internal inventory.
  5. A player or robot mines the mining drill, and the ore item that was still inside the drill is lost.
  6. If instead of mining the marked drill, the player removes the deconstruction marker, the drill will output its final ore. It is this final ore that we are interested in preserving.
The same thing happens if you manually mine a drill that is waiting for space in the drop target--the internal mined item is lost. There is **no way to determine via script** if the miner currently holds an item in its internal inventory. If there were, then marking for deconstruction could be delayed until the miner is empty, or the item could be spilled on the ground as part of the deconstruction process.

The Possible Hacks With Existing API

I have tried the following ways to determine if the miner holds an ore item internally:
  • Check all the possible entity.get_inventory(x) values. This does not work because mining drills do not have official output inventories, as explained by Rseding in viewtopic.php?p=187063#p187063.
  • Check entity.mining_state. This also does not work, because it is only valid for characters, not mining drills.
  • Check entity.mining_progress and entity.bonus_mining_progress. These both give a small nonzero number (e.g. 0.0041667) when the last resource has been depleted, regardless of whether the last item has been dropped yet.
  • Check entity.drop_target.can_insert({name="iron-ore"}). If the output is a chest, this will tell you if there would be space for the item to drop if you let the mining drill remain active for another tick. If the output is a belt or the ground, this always returns true, even if the belt is full and the mining drill status is "Waiting for space in destination".
  • Check entity.mining_target. This is nil after the on_resource_depleted event concludes, even if the miner still holds an item in its internal inventory.
Here are the options I have to resolve the issue at present:
  1. Assume the mining drill always contains 1 ore item when on_resource_depleted is called, and spill it on the ground for a robot to pick up. This could produce either too many items (if for some reason it had already been dropped), or too few items (if a bonus item were produced in the same tick that the resource was depleted). This also means resources have to be retrieved from the logistic network instead of the intended belt.
  2. Wait a fixed number of ticks before marking the drill for deconstruction. This will still produce too few items if the drop target is full for a long time.
  3. Come up with code to watch the drop target belt / ground / whatever, and wait until they definitely have space for something, and time to drop it, before marking the drill for deconstruction. On crowded belts, this will increase overhead as drills are constantly polled until the rest of the patch dries up. This also somewhat defeats the purpose of the mod.
None of these are very good options.

The Request

Here are some possible mod interface changes that would fully resolve my issues:
  1. Provide a LuaInventory or LuaItemStack handle for the item(s) that the drill removed from the resource entity but has not dropped yet.
  2. Provide a boolean flag or operating state code indicating whether the drill is waiting to drop any items.
  3. Change the mining behavior so that decrementing/depleting the resource entity is always delayed until the drill is able to drop the products of the last mining operation. (This could even be considered the root cause and an actual bug, given Rseding's assertion that drills do not have output inventories at all but the miner appears to hold an item for some time within itself.)

Rseding91
Factorio Staff
Factorio Staff
Posts: 13204
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Mining drill real output slot

Post by Rseding91 »

I've fixed the drill so it won't delete the last item it is trying to output if mined before it happens (for the next release). Other changes can also be done but that is the root issue that I'm seeing.
If you want to get ahold of me I'm almost always on Discord.

robot256
Filter Inserter
Filter Inserter
Posts: 596
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Mining drill real output slot

Post by robot256 »

Rseding91 wrote:
Thu Dec 29, 2022 4:04 pm
I've fixed the drill so it won't delete the last item it is trying to output if mined before it happens (for the next release). Other changes can also be done but that is the root issue that I'm seeing.
Thank you for the quick response! I will wait to see how it behaves with that fix in place.

sparr
Smart Inserter
Smart Inserter
Posts: 1327
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: Mining drill real output slot

Post by sparr »

Rseding91 wrote:
Thu Dec 29, 2022 4:04 pm
I've fixed the drill so it won't delete the last item it is trying to output if mined before it happens (for the next release). Other changes can also be done but that is the root issue that I'm seeing.
That might help with robot256' use case, but it doesn't address mine. I need to detect the ore so I can drop it on the ground when the output location is blocked.

Zaflis
Filter Inserter
Filter Inserter
Posts: 417
Joined: Sun Apr 24, 2016 12:51 am
Contact:

Re: Mining drill real output slot

Post by Zaflis »

Rseding91 wrote:
Thu Dec 29, 2022 4:04 pm
I've fixed the drill so it won't delete the last item it is trying to output if mined before it happens (for the next release). Other changes can also be done but that is the root issue that I'm seeing.
So is this why depleted mining drills are still holding ore in them? Maybe they shouldn't go forever silent before they empty?

Post Reply

Return to “Modding interface requests”