Change minable result run-time

Place to get help with not working mods / modding interface.
Post Reply
BuilderOfAges
Inserter
Inserter
Posts: 35
Joined: Thu Aug 02, 2018 3:02 pm
Contact:

Change minable result run-time

Post by BuilderOfAges »

I'm working on a mod that changes which entities / resources can be mined, and what results you get from mining, based on which tool is in your tool inventory.

E.g.: when there's no tool in your tool slot you can only mine trees, and they give "wood-stick" rather than "raw-wood". When you put a stick in your tool slot you can also mine stone, but it gives "jagged-rock" rather than "stone".

Overriding the result of mining an entity is pretty simple: listen for on_player_mined_entity events and replace event.buffer with the result you want.

But as far as I can tell, there's no way to override what mining a resource like stone results in: on_pre_player_mined_item doesn't give the result at all, and on_player_mined_item has item_stack but writing to it does nothing.

The best solution I've been able to come up with is to remove the original result from the player and insert the result I want:

Code: Select all

script.on_event(defines.events.on_player_mined_item, function(e)
    if e.item_stack.name == "stone" then
        game.players[e.player_index].remove_item(e.item_stack)
        game.players[e.player_index].insert({name = "jagged-rock", count = 1})
    end
end)
This works reasonable well, but it doesn't prevent the little alert next to the player character at the moment mining is done from saying "+1 stone (0)". Does anyone know of a better way to do this?

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

Re: Change minable result run-time

Post by Rseding91 »

I changed it for 0.17 so mining resources also dispatches player_mined_entity.
If you want to get ahold of me I'm almost always on Discord.

BuilderOfAges
Inserter
Inserter
Posts: 35
Joined: Thu Aug 02, 2018 3:02 pm
Contact:

Re: Change minable result run-time

Post by BuilderOfAges »

That solves it nicely. Thank you!

Post Reply

Return to “Modding help”