generated from jasonl8446/minetest-boilerplate
Adjusted auto repair to be more what I want
This commit is contained in:
parent
f76558b7fd
commit
425b08f591
16
enchants.lua
16
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,26 +94,28 @@ 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()
|
||||
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 and (math.floor(minetest.get_timeofday() * 1000) % 5) == 0
|
||||
then
|
||||
stack:add_wear(-20 + -5 * auto_repair_level)
|
||||
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
|
||||
end
|
||||
end)
|
||||
|
||||
-- Sharpness?
|
||||
|
Loading…
x
Reference in New Issue
Block a user