diff --git a/enchants.lua b/enchants.lua new file mode 100644 index 0000000..37b393e --- /dev/null +++ b/enchants.lua @@ -0,0 +1,35 @@ +-- TODO: +-- Make sure enchantment is an enchantment +-- Make sure level is a number +function tool_level_enchanting.set_enchantment(itemstack,enchantment_name,level) + local itemmeta = itemstack:get_meta() + itemmeta:set_string(enchantment_name,level) + return itemstack +end +-- Unbreaking +-- 10% chance per level of not using durability each use +-- (Level 10, tool takes no durability usage) +-- This function is used in tool_level_enchanting.on_use +function tool_level_enchanting.unbreaking_proc(enchant_level) + local rand_num = math.random(1,10) + if tonumber(enchant_level) >= tonumber(rand_num) then + return false + else + return true + end +end + +-- Fortune +-- 10% Chance per level of doubling ore +-- 5% Chance per level of doubling uses +-- Max level 10 + +-- Silk Touch +-- Return block mined +-- No idea how to implient yet + +-- Auto Repair +-- Auto repairs every few seconds +-- Max Level 5 +-- Will work simularly to a compass/clock does +-- Not sure how much per level to repair yet \ No newline at end of file diff --git a/init.lua b/init.lua index fc8d66a..f2876aa 100644 --- a/init.lua +++ b/init.lua @@ -1,12 +1,13 @@ - +local path = minetest.get_modpath('tool_level_enchanting') local S = minetest.get_translator("tool_level_enchanting") tool_level_enchanting = {} +dofile(path .. '/enchants.lua') level_divide_by = tonumber(minetest.settings:get("tool_level_enchanting_level_divide_by")) or 50 --- function to calculate levels (+150 uses per level) +-- function to calculate levels function tool_level_enchanting.get_level(uses) - local uses_number = tonumber(uses) or 0 + --local uses_number = tonumber(uses) or 0 if uses < 50 then return 1 else @@ -31,22 +32,27 @@ function tool_level_enchanting.on_use(itemstack, user, node, digparams) local itemdesc = itemdef.original_description or "" local dugnodes = tonumber(itemmeta:get_string("dug")) or 0 local pname = user:get_player_name() - if not pname then return itemstack end -- Make sure play exists + -- Enchant Variables + local unbreaking = tonumber(itemmeta:get_string("unbreaking")) or 0 + -- Make sure play exists + if not pname then return itemstack end + + -- if digparams.wear > 0 then dugnodes = dugnodes + 1 - itemmeta:set_string("dug", dugnodes) -- Is this for description? + itemmeta:set_string("dug", dugnodes) end if itemstack:get_wear() > 60135 then --FIXME: Make this proc earlier? minetest.chat_send_player(user:get_player_name(), S("Your tool is about to break!")) end - print("Dug " .. dugnodes .. "\nLevel" .. tool_level_enchanting.get_level(dugnodes)) itemmeta:set_string("description", tool_level_enchanting.create_description(itemdesc, dugnodes)) --FIXME: Add Unbreaking here? idk - itemstack:add_wear(digparams.wear) - + if tool_level_enchanting.unbreaking_proc(unbreaking) then + itemstack:add_wear(digparams.wear) + end return itemstack end