generated from jasonl8446/minetest-boilerplate
Added Tool Levels
This commit is contained in:
parent
817a573734
commit
c034d2dc58
3
README.md
Normal file
3
README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#Tool Level Enchanting
|
||||||
|
|
||||||
|
Based on the idea of toolranks, I though of adding enchanting based on how much you use the tool.
|
@ -0,0 +1 @@
|
|||||||
|
default
|
64
init.lua
64
init.lua
@ -0,0 +1,64 @@
|
|||||||
|
|
||||||
|
local S = minetest.get_translator("tool_level_enchanting")
|
||||||
|
tool_level_enchanting = {}
|
||||||
|
|
||||||
|
level_divide_by = tonumber(minetest.settings:get("tool_level_enchanting_level_divide_by")) or 50
|
||||||
|
|
||||||
|
-- function to calculate levels (+150 uses per level)
|
||||||
|
function tool_level_enchanting.get_level(uses)
|
||||||
|
local uses_number = tonumber(uses) or 0
|
||||||
|
if uses < 50 then
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
return math.floor((25 + math.sqrt(625 + 100 * uses))/level_divide_by)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function tool_level_enchanting.create_description(name, uses)
|
||||||
|
local level = tool_level_enchanting.get_level(tonumber(uses) or 0)
|
||||||
|
local newdesc = S(
|
||||||
|
'@1\nLevel @2\nUses: @3',
|
||||||
|
name,
|
||||||
|
level,
|
||||||
|
(type(uses) == "number" and uses or 0)
|
||||||
|
)
|
||||||
|
return newdesc
|
||||||
|
end
|
||||||
|
|
||||||
|
function tool_level_enchanting.on_use(itemstack, user, node, digparams)
|
||||||
|
local itemmeta = itemstack:get_meta()
|
||||||
|
local itemdef = itemstack:get_definition()
|
||||||
|
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
|
||||||
|
|
||||||
|
if digparams.wear > 0 then
|
||||||
|
dugnodes = dugnodes + 1
|
||||||
|
itemmeta:set_string("dug", dugnodes) -- Is this for description?
|
||||||
|
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)
|
||||||
|
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
|
||||||
|
function tool_level_enchanting.add_tool(name)
|
||||||
|
print(name)
|
||||||
|
local desc = ItemStack(name):get_definition().description
|
||||||
|
minetest.override_item(name, {
|
||||||
|
original_description = desc,
|
||||||
|
description = tool_level_enchanting.create_description(desc),
|
||||||
|
after_use = tool_level_enchanting.on_use
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
tool_level_enchanting.add_tool("default:pick_wood")
|
||||||
|
tool_level_enchanting.add_tool("default:pick_diamond")
|
Loading…
x
Reference in New Issue
Block a user