mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-01-18 03:21:47 +02:00
Using Template for is_diggy_rock
This commit is contained in:
parent
84ab83644f
commit
2a9d89accd
@ -87,7 +87,7 @@ DiggyCaveCollapse.events = {
|
||||
]]
|
||||
on_collapse = script.generate_event_name()
|
||||
}
|
||||
local collapse_rocks = {'sand-rock-big', 'rock-big', 'rock-big'}
|
||||
local collapse_rocks = Template.diggy_rocks
|
||||
local collapse_rocks_size = #collapse_rocks
|
||||
|
||||
local function create_collapse_template(positions, surface)
|
||||
@ -113,7 +113,7 @@ local function create_collapse_template(positions, surface)
|
||||
|
||||
if do_insert then
|
||||
entity_count = entity_count + 1
|
||||
entities[entity_count] = {position = position, name = collapse_rocks[random(1, collapse_rocks_size)]}
|
||||
entities[entity_count] = {position = position, name = collapse_rocks[random(collapse_rocks_size)]}
|
||||
end
|
||||
end
|
||||
|
||||
@ -246,7 +246,7 @@ local function on_mined_entity(event)
|
||||
local strength = support_beam_entities[name]
|
||||
if strength then
|
||||
local player_index
|
||||
if name ~= 'sand-rock-big' and name ~= 'rock-huge' and name ~= 'rock-big' then
|
||||
if not Template.is_diggy_rock(name) then
|
||||
player_index = event.player_index
|
||||
end
|
||||
stress_map_add(entity.surface, entity.position, strength, false, player_index)
|
||||
@ -259,7 +259,7 @@ local function on_entity_died(event)
|
||||
local strength = support_beam_entities[name]
|
||||
if strength then
|
||||
local player_index
|
||||
if name ~= 'sand-rock-big' and name ~= 'rock-huge' and name ~= 'rock-big' then
|
||||
if not Template.is_diggy_rock(name) then
|
||||
local cause = event.cause
|
||||
player_index = cause and cause.player and cause.player.index or nil
|
||||
end
|
||||
@ -369,7 +369,7 @@ function DiggyCaveCollapse.register(cfg)
|
||||
Event.add(defines.events.on_marked_for_deconstruction, function (event)
|
||||
local entity = event.entity
|
||||
local name = entity.name
|
||||
if name == 'sand-rock-big' or name == 'rock-huge' and name ~= 'rock-big' then
|
||||
if Template.is_diggy_rock(name) then
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -130,7 +130,7 @@ function DiggyHole.register(config)
|
||||
Event.add(defines.events.on_entity_died, function (event)
|
||||
local entity = event.entity
|
||||
local name = entity.name
|
||||
if name ~= 'sand-rock-big' and name ~= 'rock-huge' and name ~= 'rock-big' then
|
||||
if not Template.is_diggy_rock(name) then
|
||||
return
|
||||
end
|
||||
diggy_hole(entity)
|
||||
@ -147,7 +147,7 @@ function DiggyHole.register(config)
|
||||
return
|
||||
end
|
||||
|
||||
if name ~= 'sand-rock-big' and name ~= 'rock-huge' and name ~= 'rock-big' then
|
||||
if not Template.is_diggy_rock(name) then
|
||||
return
|
||||
end
|
||||
|
||||
@ -159,7 +159,7 @@ function DiggyHole.register(config)
|
||||
local entity = event.entity
|
||||
local name = entity.name
|
||||
|
||||
if name ~= 'sand-rock-big' and name ~= 'rock-huge' and name ~= 'rock-big' then
|
||||
if not Template.is_diggy_rock(name) then
|
||||
return
|
||||
end
|
||||
|
||||
@ -190,7 +190,7 @@ function DiggyHole.register(config)
|
||||
Event.add(defines.events.on_player_mined_entity, function (event)
|
||||
local entity = event.entity
|
||||
local name = entity.name
|
||||
if name ~= 'sand-rock-big' and name ~= 'rock-huge' and name ~= 'rock-big' then
|
||||
if not Template.is_diggy_rock(name) then
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -18,7 +18,7 @@ local do_spawn_tile = Token.register(function(params)
|
||||
Template.insert(params.surface, {params.tile}, {})
|
||||
end)
|
||||
|
||||
local rocks_lookup = {'sand-rock-big', 'rock-huge', 'rock-big'}
|
||||
local rocks_lookup = Template.diggy_rocks
|
||||
|
||||
local do_mine = Token.register(function(params)
|
||||
local surface = params.surface
|
||||
|
@ -155,4 +155,12 @@ function Template.resources(surface, resources)
|
||||
end
|
||||
end
|
||||
|
||||
Template.diggy_rocks = {'sand-rock-big', 'rock-big', 'rock-big'}
|
||||
|
||||
---Returns true if the entity name is that of a diggy rock.
|
||||
---@param entity_name string
|
||||
function Template.is_diggy_rock(entity_name)
|
||||
return entity_name == 'sand-rock-big' or entity_name == 'rock-big' or entity_name == 'rock-huge'
|
||||
end
|
||||
|
||||
return Template
|
||||
|
Loading…
Reference in New Issue
Block a user