From 7764d7bc7aecd74426eab8055ffd75e80add109d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9o=20Rebert?= Date: Tue, 31 May 2022 18:21:51 +0200 Subject: [PATCH] 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. --- .../danger_ores/modules/banned_entities.lua | 23 ++++++++++++++++++- .../shared/entity_placement_restriction.lua | 6 +++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/map_gen/maps/danger_ores/modules/banned_entities.lua b/map_gen/maps/danger_ores/modules/banned_entities.lua index 8933b103..e6564402 100644 --- a/map_gen/maps/danger_ores/modules/banned_entities.lua +++ b/map_gen/maps/danger_ores/modules/banned_entities.lua @@ -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 diff --git a/map_gen/shared/entity_placement_restriction.lua b/map_gen/shared/entity_placement_restriction.lua index e4616fd2..6bd1a7db 100644 --- a/map_gen/shared/entity_placement_restriction.lua +++ b/map_gen/shared/entity_placement_restriction.lua @@ -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 array of string entity names +function Public.get_allowed() + return allowed_entities +end + --- Adds to the list of allowed entities -- @param ents
array of string entity names function Public.add_allowed(ents)