New on_pre_player_mine Event

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
Rythe
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Sat Jul 18, 2015 3:25 am
Contact:

New on_pre_player_mine Event

Post by Rythe »

I'm making this a formal request as it wasn't directly answered in the other thread before it got locked.

But are we getting an event that fires before a player begins to mine an entity with an optional flag to cancel that attempt as invalid or the like?

Per API docs, there's currently only an event for when a player finishes the mining process but before the entity is removed whereas robots have an event that happens before they begin the mining process.

The need for this is that it's the appropriate time to figure out if a player can mine an entity (canceling before a player spends time on futility, based on variable and entity specific conditions), and is also the time where the mod would be able to dynamically determine the character's mining speed against the entity being mined. Which is something that can augment the new mining categories feature being added with 0.17.

Also completeness sake, since robots have it and such.

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

Re: New on_pre_player_mine Event

Post by Rseding91 »

Currently the game doesn't support canceling any events and I don't see that changing any time soon.

Also a minor point: robots don't have anything different from players. Robots simply don't respect mining time so they go directly from starting to finishing.
If you want to get ahold of me I'm almost always on Discord.

Rythe
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Sat Jul 18, 2015 3:25 am
Contact:

Re: New on_pre_player_mine Event

Post by Rythe »

So what would happen if the player's mining categories were updated during this event to make the mining attempt invalid/valid where the opposite was previously true?

That's not canceling the event, just setting the data to be used right after the event when mining begins.

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

Re: New on_pre_player_mine Event

Post by Rseding91 »

Rythe wrote:
Tue Jan 08, 2019 8:37 pm
So what would happen if the player's mining categories were updated during this event to make the mining attempt invalid/valid where the opposite was previously true?

That's not canceling the event, just setting the data to be used right after the event when mining begins.
Currently you can't do that. If support to change mining categories is added then it would stop mining.
If you want to get ahold of me I'm almost always on Discord.

Rythe
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Sat Jul 18, 2015 3:25 am
Contact:

Re: New on_pre_player_mine Event

Post by Rythe »

Rseding91 wrote:
Tue Jan 08, 2019 9:44 pm
Rythe wrote:
Tue Jan 08, 2019 8:37 pm
So what would happen if the player's mining categories were updated during this event to make the mining attempt invalid/valid where the opposite was previously true?

That's not canceling the event, just setting the data to be used right after the event when mining begins.
Currently you can't do that. If support to change mining categories is added then it would stop mining.
We're talking about the player here. The idea is to have 'em stop mining if that category changes to disallow it. We're also talking about an event that happens before mining begins. So it's more: about to start -> can't after all so don't actually start.

event.preventDefault() basically, one way or another. Plus the opposite of: about to try to mine invalid target -> target becomes valid so do actually start.

Post Reply

Return to “Modding interface requests”