add time control for decomposition.

add chat command that changes the rate at which decomposition happens.
This commit is contained in:
trans_soup 2023-10-19 16:49:36 +02:00
parent 400c27c021
commit e42407978d
3 changed files with 33 additions and 3 deletions

View file

@ -24,4 +24,6 @@ load_file("increasing_abm")
load_file("loose_node")
load_file("fall_fix")
load_file("privs")
load_file("cleanup")

3
mods/bg_api/privs.lua Normal file
View file

@ -0,0 +1,3 @@
local modname = minetest.get_current_modname()
minetest.register_privilege("control_time", "control the speed at which certain blockgame processes happen.")

View file

@ -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 = "<value>",
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