Page 1 of 1

New on_pre_player_mine Event

Posted: Tue Jan 08, 2019 2:24 am
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.

Re: New on_pre_player_mine Event

Posted: Tue Jan 08, 2019 7:54 pm
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.

Re: New on_pre_player_mine Event

Posted: Tue Jan 08, 2019 8:37 pm
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.

Re: New on_pre_player_mine Event

Posted: Tue Jan 08, 2019 9:44 pm
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.

Re: New on_pre_player_mine Event

Posted: Wed Jan 09, 2019 12:47 am
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.