Page 1 of 1

on_preplayer_mined_item is not fired at right time.

Posted: Tue Aug 30, 2016 2:31 am
by devilwarriors
Hi,

The api clearly say that on_preplayer_mined_item fire when the player start mining something
"Called when the player starts mining something"
http://lua-api.factorio.com/latest/even ... mined_item
Yet it actually fire on the same tick # as on_preplayer_mined_item, right before the entity is deleted.

so it's goes like this
- item start being mined
- mining progress bar reach 100%
- [...]
- tick begin
- [...]
- on_preplayer_mined_item is fired with the entity as a parameter
- entity is removed from the memory by the c++ logic.
- on_player_mined_item is fired with the result item_stack as a parameter
- [...]
- tick end
- [...]

Is this a bug or really a very niche case event with a wrong description? if it's not a bug can we get a proper event that fire when the player start mining something so we can do stuff like setting entity.minable to false and stop the mining. Or maybe remove the mining-tool from the tool_inventory. Something like that.

forum post where I'm describing what i'm trying to achieve -> viewtopic.php?f=25&t=31853

Thanks!

Re: on_preplayer_mined_item is not fired at right time.

Posted: Tue Aug 30, 2016 2:34 am
by Rseding91
The docs are just wrong.

As for your other comments: just set the entity to not minable to begin with if the player shouldn't be able to mine it.

Re: on_preplayer_mined_item is not fired at right time.

Posted: Tue Aug 30, 2016 2:36 am
by devilwarriors
Rseding91 wrote:The docs are just wrong.

As for your other comments: just set the entity to not minable to begin with if the player shouldn't be able to mine it.
But I wan't those entity to be mineable, just not by that particular mining-tool :(

Re: on_preplayer_mined_item is not fired at right time.

Posted: Tue Aug 30, 2016 2:47 am
by Rseding91
devilwarriors wrote:
Rseding91 wrote:The docs are just wrong.

As for your other comments: just set the entity to not minable to begin with if the player shouldn't be able to mine it.
But I wan't those entity to be mineable, just not by that particular mining-tool :(
Then use the hardness property of entities and mining tools. You can set it up so a give entity isn't minable by a given tool but other tools can mine it.

Re: on_preplayer_mined_item is not fired at right time.

Posted: Tue Aug 30, 2016 3:03 am
by devilwarriors
oh nice, completely missed that, thanks!

Re: on_preplayer_mined_item is not fired at right time.

Posted: Tue Aug 30, 2016 3:31 am
by devilwarriors
so it's the damage that the mining-tool deal that decide what hardness it can mine?? how does the math work?

Re: on_preplayer_mined_item is not fired at right time.

Posted: Tue Aug 30, 2016 12:47 pm
by devilwarriors
it's not the damage, and there really nothing else in the doc about hardness or how it work beside setting a ressources hardness.. so what am I looking for??

Re: on_preplayer_mined_item is not fired at right time.

Posted: Tue Aug 30, 2016 12:50 pm
by posila
Fixed the documentation for 0.14.2.
Any entity can have "minable" property, which is table that can contain: mining_time, result/results, mining_particle, mining_trigger and hardness
Mining tool has property speed.
As I understand it, mining progress is multiplied by (speed - hardness), and if speed < hardness you won't be able to mine the entity.

Moved to Modding help.

Re: on_preplayer_mined_item is not fired at right time.

Posted: Tue Aug 30, 2016 1:26 pm
by devilwarriors
posila wrote:Fixed the documentation for 0.14.2.
Any entity can have "minable" property, which is table that can contain: mining_time, result/results, mining_particle, mining_trigger and hardness
Mining tool has property speed.
As I understand it, mining progress is multiplied by (speed - hardness), and if speed < hardness you won't be able to mine the entity.

Moved to Modding help.
ah too bad that mean I can't use this for what I'm trying to achieve since what I want is a high speed mining tool that can only mine wood.

anyway, thx for updating the doc about this.