1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-08 00:39:30 +02:00
ComfyFactorio/modules/rocks_broken_paint_tiles.lua

50 lines
1.4 KiB
Lua
Raw Normal View History

2019-02-10 06:47:52 +02:00
--Mining or breaking a rock paints the tiles underneath
local event = require 'utils.event'
local valid_entities = {
["rock-big"] = true,
["rock-huge"] = true,
["sand-rock-big"] = true
}
2020-10-28 06:18:02 +02:00
local replacement_tiles = {
["nuclear-ground"] = "dirt-7",
["dirt-7"] = "dirt-6",
["dirt-6"] = "dirt-5",
["dirt-5"] = "dirt-4",
["dirt-4"] = "dirt-3",
["dirt-3"] = "dirt-2"
}
2019-02-14 16:44:12 +02:00
2019-02-23 16:11:49 +02:00
local coords = {
{x = 0, y = 0},{x = -1, y = -1},{x = 1, y = -1},
{x = 0, y = -1},{x = -1, y = 0},{x = -1, y = 1},
{x = 0, y = 1},{x = 1, y = 1},{x = 1, y = 0},
{x = 2, y = 0},{x = -2, y = 0},{x = 0, y = 2},{x = 0, y = -2}
}
2019-02-10 10:56:23 +02:00
2019-02-23 16:11:49 +02:00
local function on_pre_player_mined_item(event)
2019-02-10 06:47:52 +02:00
local entity = event.entity
2019-02-23 16:11:49 +02:00
if not valid_entities[entity.name] then return end
local tiles = {}
for _, p in pairs(coords) do
local pos = {x = entity.position.x + p.x, y = entity.position.y + p.y}
local tile = entity.surface.get_tile(pos)
if not tile.collides_with("player-layer") then
if replacement_tiles[tile.name] and math.random(1,2) == 1 then
table.insert(tiles, {name = replacement_tiles[tile.name], position = pos})
end
end
2019-02-10 06:47:52 +02:00
end
2019-02-23 16:11:49 +02:00
if #tiles == 0 then return end
entity.surface.set_tiles(tiles, true)
2019-02-10 06:47:52 +02:00
end
local function on_entity_died(event)
if not event.entity.valid then return end
2019-02-23 16:11:49 +02:00
on_pre_player_mined_item(event)
2019-02-10 06:47:52 +02:00
end
event.add(defines.events.on_entity_died, on_entity_died)
2019-02-23 16:11:49 +02:00
event.add(defines.events.on_pre_player_mined_item, on_pre_player_mined_item)