1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-03-03 14:53:01 +02:00

Change on_destroy message on danger_ores (#1322)

Before, the message was hardcoded. Now, the message is generated from the list
of entities actually whitelisted, and prints the list of icons.
This commit is contained in:
Cléo Rebert 2022-05-31 18:21:51 +02:00 committed by GitHub
parent b5f3de51dc
commit 7764d7bc7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -29,7 +29,28 @@ return function(allowed_entities, message)
local function on_destroy(event)
local p = event.player
if p and p.valid then
p.print(message or 'You cannot build that on top of ores, only belts, mining drills, and power poles are allowed.')
if message then
p.print(message)
return
end
local items = {}
local len = 0
local entities = RestrictEntities.get_allowed()
for k in pairs(entities) do
local entity = game.entity_prototypes[k]
for _, v in pairs(entity.items_to_place_this) do
if not items[v.name] then --- Avoid duplication for straight-rail and curved-rail, which both use rail
items[v.name] = v
len = len + 1
end
end
end
local str = "You cannot build that on top of ores, only "
local strs = {};
for k in pairs(items) do
table.insert(strs, "[img=item." .. k .."]")
end
p.print(str..table.concat(strs, " "))
end
end

View File

@ -311,6 +311,12 @@ function Public.remove_anti_grief_callback()
primitives.anti_grief_callback = nil
end
--- Get the list of allowed entities
-- @return allowed_entities <table> array of string entity names
function Public.get_allowed()
return allowed_entities
end
--- Adds to the list of allowed entities
-- @param ents <table> array of string entity names
function Public.add_allowed(ents)