From 5443195296f7205a7181c045fcb197fe2d536c4e Mon Sep 17 00:00:00 2001 From: flux <25628292+fluxionary@users.noreply.github.com> Date: Sat, 8 Apr 2023 15:19:43 -0700 Subject: [PATCH] use staminoid if available --- .luacheckrc | 1 + mod.conf | 1 + modules/anvil/anvil.lua | 6 ++---- modules/doorlike/api.lua | 16 ++++++---------- modules/pitchfork/tool.lua | 6 ++---- modules/straw/quern.lua | 6 ++---- modules/straw/threshing.lua | 6 ++---- util.lua | 11 +++++++++++ 8 files changed, 27 insertions(+), 26 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index a5e1731..820e458 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -669,6 +669,7 @@ stds.cottages = { "player_monoids", "stairs", "stamina", + "staminoid", "unified_inventory", }, } diff --git a/mod.conf b/mod.conf index c82317c..8f6c5d9 100644 --- a/mod.conf +++ b/mod.conf @@ -21,6 +21,7 @@ player_monoids, stairs, stairsplus, stamina, +staminoid, technic, unified_inventory, wool, diff --git a/modules/anvil/anvil.lua b/modules/anvil/anvil.lua index bb86ad6..fca2e8b 100644 --- a/modules/anvil/anvil.lua +++ b/modules/anvil/anvil.lua @@ -17,9 +17,9 @@ local v_sub = vector.subtract local get_safe_short_description = cottages.util.get_safe_short_description local resolve_item = cottages.util.resolve_item +local exhaust_player = cottages.util.exhaust_player local has_broken_tools = cottages.has.broken_tools -local has_stamina = cottages.has.stamina local repair_amount = cottages.settings.anvil.repair_amount local hammer_wear = cottages.settings.anvil.hammer_wear @@ -199,9 +199,7 @@ function anvil.use_anvil(pos, puncher) update_hud(puncher, tool) - if has_stamina then - stamina.exhaust_player(puncher, stamina_use, "cottages:anvil") - end + exhaust_player(puncher, stamina_use, "cottages:anvil") else -- tell the player when the job is done, but only once if meta:get_int("informed") > 0 then diff --git a/modules/doorlike/api.lua b/modules/doorlike/api.lua index b40748b..f715f24 100644 --- a/modules/doorlike/api.lua +++ b/modules/doorlike/api.lua @@ -1,8 +1,10 @@ local S = cottages.S +local exhaust_player = cottages.util.exhaust_player + local api = cottages.doorlike + local stamina_use = cottages.settings.doorlike.stamina -local has_stamina = cottages.has.stamina -- propagate shutting/closing of window shutters to window shutters below/above this one local offsets = { @@ -43,16 +45,12 @@ end function api.shutter_open(pos, puncher) api.shutter_operate(pos, "cottages:window_shutter_closed", "cottages:window_shutter_open") - if has_stamina then - stamina.exhaust_player(puncher, stamina_use, "cottages:shutter") - end + exhaust_player(puncher, stamina_use, "cottages:shutter") end function api.shutter_close(pos, puncher) api.shutter_operate(pos, "cottages:window_shutter_open", "cottages:window_shutter_closed") - if has_stamina then - stamina.exhaust_player(puncher, stamina_use, "cottages:shutter") - end + exhaust_player(puncher, stamina_use, "cottages:shutter") end function api.is_night() @@ -141,9 +139,7 @@ function api.register_hatch(nodename, description, texture, receipe_item, def) fixed = { -0.5, -0.55, -0.5, 0.5, -0.45, 0.5 }, }, on_rightclick = function(pos, node, puncher) - if has_stamina then - stamina.exhaust_player(puncher, stamina_use, nodename) - end + exhaust_player(puncher, stamina_use, nodename) minetest.swap_node(pos, { name = node.name, param2 = new_facedirs[node.param2 + 1] }) end, diff --git a/modules/pitchfork/tool.lua b/modules/pitchfork/tool.lua index bac05f4..f922a0f 100644 --- a/modules/pitchfork/tool.lua +++ b/modules/pitchfork/tool.lua @@ -1,6 +1,6 @@ local S = cottages.S -local has_stamina = cottages.has.stamina +local exhaust_player = cottages.util.exhaust_player local stamina_use = cottages.settings.pitchfork.stamina minetest.register_node("cottages:pitchfork", { @@ -91,9 +91,7 @@ local function override_on_dig(node_name, replacement) minetest.swap_node(pos, { name = replacement }) minetest.swap_node(pos_above, { name = "cottages:hay_mat", param2 = math.random(2, 25) }) - if has_stamina then - stamina.exhaust_player(digger, stamina_use, "cottages:pitchfork") - end + exhaust_player(digger, stamina_use, "cottages:pitchfork") return true end, diff --git a/modules/straw/quern.lua b/modules/straw/quern.lua index 0bb8975..b4c110d 100644 --- a/modules/straw/quern.lua +++ b/modules/straw/quern.lua @@ -7,8 +7,8 @@ local FS = function(...) end local get_safe_short_description = cottages.util.get_safe_short_description +local exhaust_player = cottages.util.exhaust_player -local has_stamina = cottages.has.stamina local stamina_use = cottages.settings.straw.quern_stamina local quern_min_per_turn = cottages.settings.straw.quern_min_per_turn local quern_max_per_turn = cottages.settings.straw.quern_max_per_turn @@ -125,9 +125,7 @@ function straw.use_quern(pos, player) minetest.sound_play({ name = cottages.sounds.use_quern }, { pos = pos, gain = 1, pitch = 0.25 }, true) - if has_stamina then - stamina.exhaust_player(player, stamina_use, "cottages:quern") - end + exhaust_player(player, stamina_use, "cottages:quern") return true end diff --git a/modules/straw/threshing.lua b/modules/straw/threshing.lua index f8ce2bc..c678762 100644 --- a/modules/straw/threshing.lua +++ b/modules/straw/threshing.lua @@ -7,8 +7,8 @@ local FS = function(...) end local get_safe_short_description = cottages.util.get_safe_short_description +local exhaust_player = cottages.util.exhaust_player -local has_stamina = cottages.has.stamina local stamina_use = cottages.settings.straw.threshing_stamina local threshing_min_per_punch = cottages.settings.straw.threshing_min_per_punch local threshing_max_per_punch = cottages.settings.straw.threshing_max_per_punch @@ -166,9 +166,7 @@ function straw.use_threshing(pos, player) minetest.sound_play({ name = cottages.sounds.use_thresher }, { pos = particle_pos, gain = 1, pitch = 0.5 }, true) - if has_stamina then - stamina.exhaust_player(player, stamina_use, "cottages:quern") - end + exhaust_player(player, stamina_use, "cottages:threshing") return true end diff --git a/util.lua b/util.lua index b9d88f3..73db7fa 100644 --- a/util.lua +++ b/util.lua @@ -314,4 +314,15 @@ else end end +local has_stamina = cottages.has.stamina +local has_staminoid = cottages.has.staminoid + +function util.exhaust_player(player, amount, reason) + if has_stamina then + stamina.exhaust_player(player, amount, reason) + elseif has_staminoid then + staminoid.exhaust(player, 1, reason) + end +end + cottages.util = util