From e4a13244386180d70973aa8f705df9fc8ccb5f63 Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Wed, 22 Jan 2020 17:46:33 +0100 Subject: [PATCH] optional quota (default: false) --- README.md | 1 + technic/machines/HV/quarry.lua | 46 ++++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 9a3a158..637703a 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Recommended mods that build on the `technic mod`: # Settings +* **technic.quarry.enable** enable per-player quarry quota (default: false) * **technic.quarry.quota** per-player and second quarry dig limit (default: 10) * **technic.switch_max_range** max cable length (default: 256) * **technic.switch.off_delay_seconds** switching station off delay (default: 300 seconds) diff --git a/technic/machines/HV/quarry.lua b/technic/machines/HV/quarry.lua index 6a32765..1b1b59e 100644 --- a/technic/machines/HV/quarry.lua +++ b/technic/machines/HV/quarry.lua @@ -23,25 +23,28 @@ local quarry_eject_dir = vector.new(0, 1, 0) local quota_map = {} local timer = 0 +local enable_quota = minetest.settings:get_bool("technic.quarry.enable", false) + -- quota reset timer -minetest.register_globalstep(function(dtime) - timer = timer + dtime - if timer < 1 then return end - timer=0 +if enable_quota then + minetest.register_globalstep(function(dtime) + timer = timer + dtime + if timer < 1 then return end + timer=0 - -- reset quota map - quota_map = {} + -- reset quota map + quota_map = {} - -- this many blocks per second - local init_quota = minetest.settings:get("technic.quarry.quota") or 10 - - local players = minetest.get_connected_players() - for i, player in pairs(players) do - local name = player:get_player_name() - quota_map[name] = init_quota - end -end) + -- this many blocks per second + local init_quota = minetest.settings:get("technic.quarry.quota") or 10 + local players = minetest.get_connected_players() + for i, player in pairs(players) do + local name = player:get_player_name() + quota_map[name] = init_quota + end + end) +end local function set_quarry_formspec(meta) local radius = meta:get_int("size") @@ -149,16 +152,21 @@ local function quarry_run(pos, node) meta:set_int("purge_on", 1) end - local digging_allowed = false + local digging_allowed = true local quota = quota_map[owner] - digging_allowed = quota and quota > 0 + + if enable_quota then + digging_allowed = quota and quota > 0 + end if digging_allowed and meta:get_int("enabled") and meta:get_int("HV_EU_input") >= quarry_demand and meta:get_int("purge_on") == 0 then -- decrement quota - quota = quota - 1 - quota_map[owner] = quota + if enable_quota then + quota = quota - 1 + quota_map[owner] = quota + end local pdir = minetest.facedir_to_dir(node.param2) if pdir.y ~= 0 then