From 3b4328d57495459fedad50cf5408d78a4dc14655 Mon Sep 17 00:00:00 2001 From: HybridDog Date: Sun, 17 Dec 2023 15:30:58 +0100 Subject: [PATCH] Add a setting to allow incomplete lighting I have also changed the description of the other setting because torches are only a special case. --- init.lua | 18 ++++++++++++++---- settingtypes.txt | 7 ++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/init.lua b/init.lua index dd63bd0..d71b278 100644 --- a/init.lua +++ b/init.lua @@ -109,7 +109,7 @@ local function search_positions(startpos, maxlight, pname) end, moves_vi_near) -- Do not return the positions if the search has found too many, to avoid -- fragmented lighting - return num_found <= max_positions and num_found > 0 and found + return found, num_found <= max_positions end -- Lights up a cave @@ -137,9 +137,19 @@ local function place_torches(startpos, maxlight, player) return false, "You need a node emitting light (enough light)." end -- Get possible positions - local ps = search_positions(startpos, maxlight, player:get_player_name()) - if not ps then - return false, "It doesn't seem to be dark there or the cave is too big." + local ps, found_all = search_positions(startpos, maxlight, + player:get_player_name()) + if #ps == 0 then + return false, "Found no potential placement positions." + end + if not found_all then + local allow_incomplete_lighting = minetest.settings:get_bool( + "cave_lighting.allow_incomplete_lighting", false) + if not allow_incomplete_lighting then + return false, "The cave is too big." + end + inform(player:get_player_name(), + "The cave is too big, so it is lit only partially.") end inform(player:get_player_name(), ('Collected %d potential placement positions. Placing "%s"s at some ' .. diff --git a/settingtypes.txt b/settingtypes.txt index dbfb4f7..f5bad1d 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -1,3 +1,8 @@ # A limit on the number of positions which are traversed to search places for -# torch placement +# the placement of light-source nodes (e.g. torches) cave_lighting.maximum_search_positions (Maximum number of search positions) int 8000000 1 100000000000 + +# If enabled, place light-source nodes even if the limit specified in +# cave_lighting.maximum_search_positions has been reached, +# which causes caves to be partially-lit. +cave_lighting.allow_incomplete_lighting (Allow incomplete lighting) bool false