generated from jasonl8446/minetest-boilerplate
Adjusted auto repair to be more what I want
This commit is contained in:
parent
f76558b7fd
commit
425b08f591
30
enchants.lua
30
enchants.lua
@ -1,9 +1,9 @@
|
|||||||
local modname = minetest.get_current_modname()
|
local modname = minetest.get_current_modname()
|
||||||
local S = minetest.get_translator(modname)
|
local S = minetest.get_translator(modname)
|
||||||
|
|
||||||
-- TODO:
|
-- TODO:
|
||||||
-- Make sure enchantment is an enchantment
|
-- Make sure enchantment is an enchantment
|
||||||
-- Make sure level is a number
|
-- Make sure level is a number
|
||||||
|
-- Make sure enchantment is possible (correct tool)
|
||||||
function tool_level_enchanting.set_enchantment(itemstack,enchantment_name,level)
|
function tool_level_enchanting.set_enchantment(itemstack,enchantment_name,level)
|
||||||
local itemmeta = itemstack:get_meta()
|
local itemmeta = itemstack:get_meta()
|
||||||
local itemdef = itemstack:get_definition()
|
local itemdef = itemstack:get_definition()
|
||||||
@ -94,22 +94,24 @@ function minetest.handle_node_drops(pos, drops, digger)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Auto Repair
|
-- Auto Repair
|
||||||
-- Auto repairs every few seconds
|
-- Auto repairs every time ingame time changes
|
||||||
-- Max Level 5
|
-- Max Level 5
|
||||||
-- Will work simularly to a compass/clock does
|
local last_time = 0
|
||||||
-- Not sure how much per level to repair yet
|
local auto_repair_multiplier = tonumber(minetest.settings:get("tool_level_enchanting_auto_repair_multiplier")) or 20
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
local players = minetest.get_connected_players()
|
local players = minetest.get_connected_players()
|
||||||
for i,player in ipairs(players) do
|
if (last_time ~= minetest.get_gametime()) then
|
||||||
local has_autorepair = false
|
last_time = minetest.get_gametime()
|
||||||
local stack_idx = 0
|
for i,player in ipairs(players) do
|
||||||
if player:get_inventory() then
|
local has_autorepair = false
|
||||||
for i,stack in ipairs(player:get_inventory():get_list("main")) do
|
local stack_idx = 0
|
||||||
local auto_repair_level = tonumber(stack:get_meta():get_string("auto_repair")) or 0
|
if player:get_inventory() then
|
||||||
if auto_repair_level > 0 and (math.floor(minetest.get_timeofday() * 1000) % 5) == 0
|
for i,stack in ipairs(player:get_inventory():get_list("main")) do
|
||||||
then
|
local auto_repair_level = tonumber(stack:get_meta():get_string("auto_repair")) or 0
|
||||||
stack:add_wear(-20 + -5 * auto_repair_level)
|
if auto_repair_level > 0 then
|
||||||
player:get_inventory():set_stack("main",i,stack)
|
stack:add_wear(-1 * auto_repair_multiplier * auto_repair_level)
|
||||||
|
player:get_inventory():set_stack("main",i,stack)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user