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)