From e42407978debf2df54d7415790999497b6f8d154 Mon Sep 17 00:00:00 2001 From: trans_soup <> Date: Thu, 19 Oct 2023 16:49:36 +0200 Subject: [PATCH] add time control for decomposition. add chat command that changes the rate at which decomposition happens. --- mods/bg_api/init.lua | 2 ++ mods/bg_api/privs.lua | 3 +++ mods/bg_tree/decompose.lua | 31 ++++++++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 mods/bg_api/privs.lua diff --git a/mods/bg_api/init.lua b/mods/bg_api/init.lua index 99a3c8f..c3f7650 100644 --- a/mods/bg_api/init.lua +++ b/mods/bg_api/init.lua @@ -24,4 +24,6 @@ load_file("increasing_abm") load_file("loose_node") load_file("fall_fix") +load_file("privs") + load_file("cleanup") diff --git a/mods/bg_api/privs.lua b/mods/bg_api/privs.lua new file mode 100644 index 0000000..50dd94f --- /dev/null +++ b/mods/bg_api/privs.lua @@ -0,0 +1,3 @@ +local modname = minetest.get_current_modname() + +minetest.register_privilege("control_time", "control the speed at which certain blockgame processes happen.") diff --git a/mods/bg_tree/decompose.lua b/mods/bg_tree/decompose.lua index 55390b6..bb2a04a 100644 --- a/mods/bg_tree/decompose.lua +++ b/mods/bg_tree/decompose.lua @@ -1,6 +1,5 @@ local modname = minetest.get_current_modname() local api = blockgame.tree -local vec = blockgame.vector -- NODE NAMES @@ -9,6 +8,32 @@ local leaves_decomposing = modname .. ":leaves_decomposing" +local decompose_time_speed = 1 +-- TODO: add setting for this as well. +minetest.register_chatcommand(modname .. ":set_decompose_time_speed", { + params = "", + description = "set the speed at which decomposition happens.", + privs = { + control_time = true, + }, + func = function (player_name, speed) + speed = tonumber(speed) + if speed == nil then + minetest.chat_send_player(player_name, "time speed must be a number.") + return + end + if speed < 0 or speed > 256 then + minetest.chat_send_player(player_name, "time speed must be between 0 and 256 (inclusive).") + return + end + + decompose_time_speed = speed + minetest.chat_send_all(player_name .. " set the leaves decomposition time speed to " .. speed .. ".") + end, +}) + + + local decompose_scores = { dirty = 50, leaves_decomposing = 30, @@ -28,7 +53,7 @@ blockgame.register_increasing_abm({ return math.floor(gain / (distance ^ 3)) end) - return data.value + score + return data.value + score * decompose_time_speed end, check = function (pos, node, data) return data.value >= start_decompose_cost @@ -59,7 +84,7 @@ blockgame.register_increasing_abm({ end) score = score + bonus - return data.value + score + return data.value + score * decompose_time_speed end, check = function (pos, node, data) return data.value >= decompose_cost