Change minable result run-time
Posted: Sun Aug 26, 2018 5:32 pm
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:
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?
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)