1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-11-27 22:38:18 +02:00
Files
ComfyFactorio/modules/rocks_broken_paint_tiles.lua

76 lines
1.8 KiB
Lua
Raw Normal View History

2019-02-10 05:47:52 +01:00
--Mining or breaking a rock paints the tiles underneath
local Event = require 'utils.event'
2019-02-10 05:47:52 +01:00
local valid_entities = {
2024-09-25 23:25:57 +02:00
['big-rock'] = true,
['huge-rock'] = true,
['big-sand-rock'] = true
2019-02-10 05:47:52 +01:00
}
2020-10-28 05:18:02 +01: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'
2020-10-28 05:18:02 +01:00
}
2019-02-14 15:44:12 +01:00
2019-02-23 15:11:49 +01:00
local coords = {
2024-09-25 17:00:40 +01:00
{ 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 09:56:23 +01:00
2019-02-23 15:11:49 +01:00
local function on_pre_player_mined_item(event)
local entity = event.entity
if not valid_entities[entity.name] then
return
end
local tiles = {}
for i = 1, #coords do
local p = coords[i]
2024-09-25 17:00:40 +01:00
local pos = { x = entity.position.x + p.x, y = entity.position.y + p.y }
local tile = entity.surface.get_tile(pos)
2024-09-25 17:00:40 +01:00
if not tile.collides_with('player') then
if replacement_tiles[tile.name] and math.random(1, 2) == 1 then
2024-09-25 17:00:40 +01:00
table.insert(tiles, { name = replacement_tiles[tile.name], position = pos })
end
end
end
if #tiles == 0 then
return
end
entity.surface.set_tiles(tiles, true)
2019-02-10 05:47:52 +01:00
end
local function on_entity_died(event)
local entity = event.entity
if not entity or not entity.valid then
return
end
local cause = event.cause
if cause and cause.valid and cause.force.index == 2 then
return
end
on_pre_player_mined_item(event)
2019-02-10 05:47:52 +01:00
end
Event.add(defines.events.on_entity_died, on_entity_died)
Event.add(defines.events.on_pre_player_mined_item, on_pre_player_mined_item)