From a3ae65833f2134226676e6757b23efd083638377 Mon Sep 17 00:00:00 2001 From: Benjie <31968410+BenjieFiftysix@users.noreply.github.com> Date: Tue, 21 Feb 2023 00:28:27 +0000 Subject: [PATCH] Add configuration options, with changed default behaviour --- README.md | 12 ++++++++++ init.lua | 61 +++++++++++++++++++++++++++++++++++++++++------- settingtypes.txt | 10 ++++++++ 3 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 settingtypes.txt diff --git a/README.md b/README.md index 22894fa..c1e3810 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,15 @@ This will cause them to become soggy, so to use them again they have to be cooke * If sponges have cleared more than 3 nodes of liquid, they become soggy sponges. * Removing a sponge or soggy sponge will turn a 9x9x9 cube of air-like nodes back into air, as long as they are not in the area of another sponge. *(Air-like nodes can be removed in protection by removing a sponge outside the protection, they are not meant to be permanent)* + +### Options: +**Replace air nodes**: boolean, default true +Causes sponges not to replace air with water blocking airlike nodes. Disabling this may cause unusual behaviour with flowing water. + +**Group list**: list, default: water +List of group names as group1,group2,... (common groups are water, liquid and lava) +See "Group list type" (sponge_group_list_type) for the behaviour of this list. + +**Group list type**: multi-choice, default whitelist_source +If the groups in the group list should be treated as a whitelist or blacklist for removing liquids. +The *_source variants will remove all flowing liquids regardless of the list. diff --git a/init.lua b/init.lua index d1bfa6e..4678c8c 100644 --- a/init.lua +++ b/init.lua @@ -15,10 +15,26 @@ removing a sponge or soggy sponge will turn a 9x9x9 cube of air-like nodes back (air-like nodes can be removed in protection by removing a sponge outside the protection, they are not meant to be permanent) ]]-- + +local modname = minetest.get_current_modname() + local area = 4 -- The "radius" (of the cube) to clear water local keep_dry = 3 -- The maximum amount of water cleared where the sponge doesn't turn soggy -local modname = minetest.get_current_modname() +-- Load configurable options +local replace_air_nodes = minetest.settings:get_bool("sponge_replace_air_nodes", true) +local group_list = minetest.settings:get("sponge_group_list", false) or "water" +local group_list_type = minetest.settings:get("sponge_group_list_type") or "whitelist_source" + +-- returns true if groups contains anything in list +local compare_groups = function(list, groups) + for group in list:gmatch("([^,]+)") do + if groups[group] and groups[group] > 0 then + return true + end + end + return false +end -- called by after_destruct() @@ -71,17 +87,46 @@ local construct = function(pos, placer, itemstack, pointed_thing) for x = pos.x-area, pos.x+area do for y = pos.y-area, pos.y+area do for z = pos.z-area, pos.z+area do + local p = {x=x, y=y, z=z} - local n = minetest.get_node({x=x, y=y, z=z}).name + local n = minetest.get_node(p).name local def = minetest.registered_nodes[n] - if def ~= nil and (n == "air" or def["drawtype"] == "liquid" or def["drawtype"] == "flowingliquid") then - local p = {x=x, y=y, z=z} - if not minetest.is_protected(p, playername) then - if n ~= "air" then - count = count + 1 -- counting liquids + local replace = false + if def == nil or minetest.is_protected(p, playername) then + -- replace = false + elseif replace_air_nodes and n == "air" then + replace = true + elseif def["drawtype"] == "flowingliquid" then + if group_list_type == "whitelist" then + if compare_groups(group_list, def.groups or {}) then + replace = true end - minetest.set_node(p, {name=modname..":liquid_stop"}) + elseif group_list_type == "blacklist" then + if not compare_groups(group_list, def.groups or {}) then + replace = true + end + else + replace = true end + elseif def["drawtype"] == "liquid" then + if group_list_type == "whitelist" or group_list_type == "whitelist_source" then + if compare_groups(group_list, def.groups or {}) then + replace = true + end + elseif group_list_type == "blacklist" or group_list_type == "blacklist_source" then + if not compare_groups(group_list, def.groups or {}) then + replace = true + end + else + replace = true + end + end + + if replace then + if n ~= "air" then + count = count + 1 -- counting liquids + end + minetest.set_node(p, {name=modname..":liquid_stop"}) end end end diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..40d9192 --- /dev/null +++ b/settingtypes.txt @@ -0,0 +1,10 @@ +# Causes sponges not to replace air with water blocking airlike nodes. Disabling this may cause unusual behaviour with flowing water. +sponge_replace_air_nodes (Replace air nodes) bool true + +# List of group names as group1,group2,... (common groups are water, liquid and lava) +# See "Group list type" (sponge_group_list_type) for the behaviour of this list. +sponge_group_list (Group list) string water + +# If the groups in the group list should be treated as a whitelist or blacklist for removing liquids. +# The *_source variants will remove all flowing liquids regardless of the list. +sponge_group_list_type (Group list type) enum whitelist_source whitelist,whitelist_source,blacklist,blacklist_source,ignored