Skip to content

Commit

Permalink
fix tool description for old and unused tools (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
OgelGames authored Jun 20, 2020
1 parent 17994ed commit d000b4b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ If so, to support this mod, add this code to your mod, after your tool's code:
if minetest.get_modpath("toolranks") then
minetest.override_item("mymod:mytool", {
original_description = "My Tool",
description = toolranks.create_description("My Tool", 0, 1),
description = toolranks.create_description("My Tool"),
after_use = toolranks.new_afteruse
})
end
Expand Down
25 changes: 14 additions & 11 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,34 @@ function toolranks.get_tool_type(description)
elseif string.find(d, "sword") then
return "sword"
else
return "tool"
return "tool"
end
end
end

function toolranks.create_description(name, uses, level)
function toolranks.get_level(uses)
if type(uses) == "number" and uses > 0 then
return math.min(max_level, math.floor(uses / level_digs))
end
return 0
end

function toolranks.create_description(name, uses)
local description = name
local tooltype = toolranks.get_tool_type(description)
local newdesc = S(
"@1@2\n@3Level @4 @5\n@6@Node dug: @7",
toolranks.colors.green,
description,
toolranks.colors.gold,
(level or 1),
toolranks.get_level(uses),
S(tooltype),
toolranks.colors.grey,
(uses or 0)
(type(uses) == "number" and uses or 0)
)
return newdesc
end

function toolranks.get_level(uses)
return math.min(max_level, math.floor(uses / level_digs))
end

function toolranks.new_afteruse(itemstack, user, node, digparams)
local itemmeta = itemstack:get_meta()
local itemdef = itemstack:get_definition()
Expand Down Expand Up @@ -107,7 +110,6 @@ function toolranks.new_afteruse(itemstack, user, node, digparams)
to_player = user:get_player_name(),
gain = 2.0,
})
itemmeta:set_string("lastlevel", level)

local speed_multiplier = 1 + (level * level_multiplier * (max_speed - 1))
local use_multiplier = 1 + (level * level_multiplier * (max_use - 1))
Expand All @@ -125,7 +127,8 @@ function toolranks.new_afteruse(itemstack, user, node, digparams)
itemmeta:set_tool_capabilities(caps)
end

itemmeta:set_string("description", toolranks.create_description(itemdesc, dugnodes, level))
itemmeta:set_string("lastlevel", level)
itemmeta:set_string("description", toolranks.create_description(itemdesc, dugnodes))
itemstack:add_wear(digparams.wear)
return itemstack
end
Expand All @@ -135,7 +138,7 @@ function toolranks.add_tool(name)
local desc = ItemStack(name):get_definition().description
minetest.override_item(name, {
original_description = desc,
description = toolranks.create_description(desc, 0, 1),
description = toolranks.create_description(desc),
after_use = toolranks.new_afteruse
})
end
Expand Down

0 comments on commit d000b4b

Please sign in to comment.