From 425b08f5917aeb84c5c9d3f8db67c17a6f77bc2b Mon Sep 17 00:00:00 2001 From: jasonl8446 Date: Tue, 16 Apr 2024 13:35:29 -0400 Subject: [PATCH] Adjusted auto repair to be more what I want --- enchants.lua | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/enchants.lua b/enchants.lua index f89fdd9..127cae6 100644 --- a/enchants.lua +++ b/enchants.lua @@ -1,9 +1,9 @@ local modname = minetest.get_current_modname() local S = minetest.get_translator(modname) - -- TODO: -- Make sure enchantment is an enchantment -- Make sure level is a number +-- Make sure enchantment is possible (correct tool) function tool_level_enchanting.set_enchantment(itemstack,enchantment_name,level) local itemmeta = itemstack:get_meta() local itemdef = itemstack:get_definition() @@ -94,22 +94,24 @@ function minetest.handle_node_drops(pos, drops, digger) end -- Auto Repair --- Auto repairs every few seconds +-- Auto repairs every time ingame time changes -- Max Level 5 --- Will work simularly to a compass/clock does --- Not sure how much per level to repair yet +local last_time = 0 +local auto_repair_multiplier = tonumber(minetest.settings:get("tool_level_enchanting_auto_repair_multiplier")) or 20 minetest.register_globalstep(function(dtime) local players = minetest.get_connected_players() - for i,player in ipairs(players) do - local has_autorepair = false - local stack_idx = 0 - if player:get_inventory() then - for i,stack in ipairs(player:get_inventory():get_list("main")) do - local auto_repair_level = tonumber(stack:get_meta():get_string("auto_repair")) or 0 - if auto_repair_level > 0 and (math.floor(minetest.get_timeofday() * 1000) % 5) == 0 - then - stack:add_wear(-20 + -5 * auto_repair_level) - player:get_inventory():set_stack("main",i,stack) + if (last_time ~= minetest.get_gametime()) then + last_time = minetest.get_gametime() + for i,player in ipairs(players) do + local has_autorepair = false + local stack_idx = 0 + if player:get_inventory() then + for i,stack in ipairs(player:get_inventory():get_list("main")) do + local auto_repair_level = tonumber(stack:get_meta():get_string("auto_repair")) or 0 + if auto_repair_level > 0 then + stack:add_wear(-1 * auto_repair_multiplier * auto_repair_level) + player:get_inventory():set_stack("main",i,stack) + end end end end