mirror of
https://codeberg.org/minenux/minetest-mod-toolranks
synced 2023-10-03 09:08:51 -07:00
update to increase speed levels
This commit is contained in:
parent
9cd6179ad9
commit
cf85317c7e
37
README.md
37
README.md
@ -1,20 +1,27 @@
|
|||||||
# minetest-toolranks
|
# minetest-toolranks [toolranks]
|
||||||
|
|
||||||
Minetest tool ranks mod
|
Minetest tool ranks mod
|
||||||
|
|
||||||
## Original mod by lisacvuk
|
Tools gain levels for digging nodes. Higher level tools dig faster and take longer to wear out.
|
||||||
https://github.com/lisacvuk/minetest-toolranks
|
|
||||||
|
|
||||||
Tool gains levels for digging nodes. Higher level tools take longer to
|
|
||||||
wear out.
|
|
||||||
|
|
||||||
## Are you a mod developer?
|
## Are you a mod developer?
|
||||||
Does one of your mods add new tools?
|
|
||||||
If so, to support this mod, check if it is loaded with
|
|
||||||
```minetest.get_modpath("toolranks")```
|
|
||||||
and then replace all after_use definitions with toolranks.new_afteruse.
|
|
||||||
Optionaly, you can also replace tools description with
|
|
||||||
```toolranks.create_description("Tool Name", 0, 1)```
|
|
||||||
and then set original_description to your tools name.
|
|
||||||
|
|
||||||
### This is a fork
|
Does one of your mods add new tools?
|
||||||
Yep, this is a simplified version of toolranks with lesser dependencies.
|
If so, to support this mod, add this code to your mod, after your tool's code:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
if minetest.get_modpath("toolranks") then
|
||||||
|
minetest.override_item("mymod:mytool", {
|
||||||
|
original_description = "My Tool",
|
||||||
|
description = toolranks.create_description("My Tool"),
|
||||||
|
after_use = toolranks.new_afteruse
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
Or alternatively, you can use the helper function:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
toolranks.add_tool("mymod:mytool")
|
||||||
|
```
|
||||||
|
193
init.lua
193
init.lua
@ -1,5 +1,8 @@
|
|||||||
|
local S = minetest.get_translator("toolranks")
|
||||||
|
|
||||||
|
|
||||||
toolranks = {
|
toolranks = {
|
||||||
|
|
||||||
colors = {
|
colors = {
|
||||||
grey = minetest.get_color_escape_sequence("#9d9d9d"),
|
grey = minetest.get_color_escape_sequence("#9d9d9d"),
|
||||||
green = minetest.get_color_escape_sequence("#1eff00"),
|
green = minetest.get_color_escape_sequence("#1eff00"),
|
||||||
@ -9,125 +12,137 @@ toolranks = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function toolranks.create_description(name, uses, level)
|
local max_speed = tonumber(minetest.settings:get("toolranks_speed_multiplier")) or 1.5--2.0
|
||||||
|
local max_use = tonumber(minetest.settings:get("toolranks_use_multiplier")) or 2.0
|
||||||
return toolranks.colors.green .. (name or "") .. "\n"
|
local max_level = tonumber(minetest.settings:get("toolranks_levels")) or 10
|
||||||
.. toolranks.colors.gold .. "Level: " .. (level or 1) .. "\n"
|
local level_digs = tonumber(minetest.settings:get("toolranks_level_digs")) or 500
|
||||||
.. toolranks.colors.grey .. "Used: " .. (uses or 0) .. " times"
|
local level_multiplier = 1 / max_level
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function toolranks.get_level(uses)
|
function toolranks.get_level(uses)
|
||||||
|
|
||||||
if uses >= 3200 then
|
if type(uses) == "number" and uses > 0 then
|
||||||
return 6
|
return math.min(max_level, math.floor(uses / level_digs))
|
||||||
elseif uses >= 2000 then
|
|
||||||
return 5
|
|
||||||
elseif uses >= 1000 then
|
|
||||||
return 4
|
|
||||||
elseif uses >= 400 then
|
|
||||||
return 3
|
|
||||||
elseif uses >= 200 then
|
|
||||||
return 2
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function toolranks.create_description(name, uses)
|
||||||
|
|
||||||
|
local description = name
|
||||||
|
local newdesc = S(
|
||||||
|
"@1@2\n@3Level @4 @5\n@6@Node dug: @7",
|
||||||
|
toolranks.colors.green,
|
||||||
|
description,
|
||||||
|
toolranks.colors.gold,
|
||||||
|
toolranks.get_level(uses),
|
||||||
|
"", -- was tooltype
|
||||||
|
toolranks.colors.grey,
|
||||||
|
(type(uses) == "number" and uses or 0)
|
||||||
|
)
|
||||||
|
|
||||||
|
return newdesc
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function toolranks.new_afteruse(itemstack, user, node, digparams)
|
function toolranks.new_afteruse(itemstack, user, node, digparams)
|
||||||
|
|
||||||
-- Get tool metadata and number of times used
|
local pname = user:get_player_name()
|
||||||
|
|
||||||
|
if not pname then return itemstack end -- player nil check
|
||||||
|
|
||||||
local itemmeta = itemstack:get_meta()
|
local itemmeta = itemstack:get_meta()
|
||||||
local dugnodes = tonumber(itemmeta:get_string("dug")) or 0
|
local dugnodes = tonumber(itemmeta:get_string("dug")) or 0
|
||||||
|
|
||||||
-- Only count nodes that spend the tool
|
if digparams.wear > 0 then -- Only count nodes that spend the tool
|
||||||
if digparams.wear > 0 then
|
|
||||||
|
|
||||||
dugnodes = dugnodes + 1
|
dugnodes = dugnodes + 1
|
||||||
|
|
||||||
itemmeta:set_string("dug", dugnodes)
|
itemmeta:set_string("dug", dugnodes)
|
||||||
else
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get tool description and last level
|
if itemstack:get_wear() > 60135 then
|
||||||
local itemdef = itemstack:get_definition()
|
|
||||||
local itemdesc = itemdef.original_description or itemdef.description or "Tool"
|
|
||||||
local lastlevel = tonumber(itemmeta:get_string("lastlevel")) or 1
|
|
||||||
local name = user:get_player_name()
|
|
||||||
|
|
||||||
-- Warn player when tool is almost broken
|
minetest.chat_send_player(pname,
|
||||||
if itemstack:get_wear() > 60100 then
|
toolranks.colors.gold .. S("Your tool is about to break!"))
|
||||||
|
|
||||||
minetest.chat_send_player(name,
|
|
||||||
toolranks.colors.gold .. "Your tool is almost broken!")
|
|
||||||
|
|
||||||
minetest.sound_play("default_tool_breaks", {
|
minetest.sound_play("default_tool_breaks", {
|
||||||
to_player = name,
|
to_player = pname,
|
||||||
gain = 1.0
|
gain = 2.0,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local itemdef = itemstack:get_definition()
|
||||||
|
local itemdesc = itemdef.original_description or ""
|
||||||
|
local lastlevel = tonumber(itemmeta:get_string("lastlevel")) or 0
|
||||||
local level = toolranks.get_level(dugnodes)
|
local level = toolranks.get_level(dugnodes)
|
||||||
|
|
||||||
-- Alert player when tool has leveled up
|
|
||||||
if lastlevel < level then
|
if lastlevel < level then
|
||||||
|
|
||||||
minetest.chat_send_player(name, "Your "
|
local levelup_text = S(
|
||||||
.. toolranks.colors.green .. itemdesc
|
"Your @1@2@3 just leveled up!",
|
||||||
.. toolranks.colors.white .. " just leveled up!")
|
toolranks.colors.green,
|
||||||
|
itemdesc,
|
||||||
|
toolranks.colors.white
|
||||||
|
)
|
||||||
|
|
||||||
|
minetest.chat_send_player(pname, levelup_text)
|
||||||
|
|
||||||
minetest.sound_play("toolranks_levelup", {
|
minetest.sound_play("toolranks_levelup", {
|
||||||
to_player = name,
|
to_player = pname,
|
||||||
gain = 1.0
|
gain = 2.0,
|
||||||
})
|
})
|
||||||
|
|
||||||
itemmeta:set_string("lastlevel", level)
|
-- Make tool better by modifying tool_capabilities (if defined)
|
||||||
|
if itemdef.tool_capabilities then
|
||||||
|
|
||||||
|
local speed_multiplier = 1 + (level * level_multiplier * (max_speed - 1))
|
||||||
|
local use_multiplier = 1 + (level * level_multiplier * (max_use - 1))
|
||||||
|
local caps = table.copy(itemdef.tool_capabilities)
|
||||||
|
|
||||||
|
caps.full_punch_interval = caps.full_punch_interval and
|
||||||
|
(caps.full_punch_interval / speed_multiplier)
|
||||||
|
|
||||||
|
caps.punch_attack_uses = caps.punch_attack_uses and
|
||||||
|
(caps.punch_attack_uses * use_multiplier)
|
||||||
|
|
||||||
|
for _,c in pairs(caps.groupcaps) do
|
||||||
|
|
||||||
|
c.uses = c.uses * use_multiplier
|
||||||
|
|
||||||
|
for i,t in ipairs(c.times) do
|
||||||
|
c.times[i] = t / speed_multiplier
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set new meta
|
itemmeta:set_tool_capabilities(caps)
|
||||||
itemmeta:set_string("description",
|
end
|
||||||
toolranks.create_description(itemdesc, dugnodes, level))
|
end
|
||||||
|
|
||||||
|
-- Old method for compatibility with tools without tool_capabilities defined
|
||||||
local wear = digparams.wear
|
local wear = digparams.wear
|
||||||
|
|
||||||
-- Set wear level
|
if level > 0 and not itemdef.tool_capabilities then
|
||||||
if level > 1 then
|
|
||||||
wear = digparams.wear * 4 / (4 + level)
|
local use_multiplier = 1 + (level * level_multiplier * (max_use - 1))
|
||||||
|
|
||||||
|
wear = wear / use_multiplier
|
||||||
end
|
end
|
||||||
|
|
||||||
|
itemmeta:set_string("lastlevel", level)
|
||||||
|
itemmeta:set_string("description", toolranks.create_description(itemdesc, dugnodes))
|
||||||
itemstack:add_wear(wear)
|
itemstack:add_wear(wear)
|
||||||
|
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Default tool list
|
-- Helper function
|
||||||
local tools = {
|
function toolranks.add_tool(name)
|
||||||
|
|
||||||
"default:sword_wood", "default:sword_stone", "default:sword_steel",
|
local desc = ItemStack(name):get_definition().description
|
||||||
"default:sword_bronze", "default:sword_mese", "default:sword_diamond",
|
|
||||||
|
|
||||||
"default:pick_wood", "default:pick_stone", "default:pick_steel",
|
|
||||||
"default:pick_bronze", "default:pick_mese", "default:pick_diamond",
|
|
||||||
|
|
||||||
"default:axe_wood", "default:axe_stone", "default:axe_steel",
|
|
||||||
"default:axe_bronze", "default:axe_mese", "default:axe_diamond",
|
|
||||||
|
|
||||||
"default:shovel_wood", "default:shovel_stone", "default:shovel_steel",
|
|
||||||
"default:shovel_bronze", "default:shovel_mese", "default:shovel_diamond"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
-- Loop through tool list and add new toolranks description
|
|
||||||
for n = 1, #tools do
|
|
||||||
|
|
||||||
local name = tools[n]
|
|
||||||
local def = minetest.registered_tools[name]
|
|
||||||
local desc = def and def.description
|
|
||||||
|
|
||||||
if desc then
|
|
||||||
|
|
||||||
minetest.override_item(name, {
|
minetest.override_item(name, {
|
||||||
original_description = desc,
|
original_description = desc,
|
||||||
@ -135,4 +150,36 @@ for n = 1, #tools do
|
|||||||
after_use = toolranks.new_afteruse
|
after_use = toolranks.new_afteruse
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
|
-- Sword
|
||||||
|
toolranks.add_tool("default:sword_wood")
|
||||||
|
toolranks.add_tool("default:sword_stone")
|
||||||
|
toolranks.add_tool("default:sword_steel")
|
||||||
|
toolranks.add_tool("default:sword_bronze")
|
||||||
|
toolranks.add_tool("default:sword_mese")
|
||||||
|
toolranks.add_tool("default:sword_diamond")
|
||||||
|
|
||||||
|
-- Pickaxe
|
||||||
|
toolranks.add_tool("default:pick_wood")
|
||||||
|
toolranks.add_tool("default:pick_stone")
|
||||||
|
toolranks.add_tool("default:pick_steel")
|
||||||
|
toolranks.add_tool("default:pick_bronze")
|
||||||
|
toolranks.add_tool("default:pick_mese")
|
||||||
|
toolranks.add_tool("default:pick_diamond")
|
||||||
|
|
||||||
|
-- Axe
|
||||||
|
toolranks.add_tool("default:axe_wood")
|
||||||
|
toolranks.add_tool("default:axe_stone")
|
||||||
|
toolranks.add_tool("default:axe_steel")
|
||||||
|
toolranks.add_tool("default:axe_bronze")
|
||||||
|
toolranks.add_tool("default:axe_mese")
|
||||||
|
toolranks.add_tool("default:axe_diamond")
|
||||||
|
|
||||||
|
-- Shovel
|
||||||
|
toolranks.add_tool("default:shovel_wood")
|
||||||
|
toolranks.add_tool("default:shovel_stone")
|
||||||
|
toolranks.add_tool("default:shovel_steel")
|
||||||
|
toolranks.add_tool("default:shovel_bronze")
|
||||||
|
toolranks.add_tool("default:shovel_mese")
|
||||||
|
toolranks.add_tool("default:shovel_diamond")
|
||||||
|
11
locale/toolranks.en.tr
Normal file
11
locale/toolranks.en.tr
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# textdomain: toolranks
|
||||||
|
@1@2@n@3Level @4 @5@n@6Node dug: @7=@1@2@n@3Level @4 @5@n@6Node dug: @7
|
||||||
|
pickaxe=pickaxe
|
||||||
|
axe=axe
|
||||||
|
shovel=shovel
|
||||||
|
hoe=hoe
|
||||||
|
sword=sword
|
||||||
|
tool=tool
|
||||||
|
Most used tool is now a @1@2@3 owned by @4 with @5 uses.=Most used tool is now a @1@2@3 owned by @4 with @5 uses.
|
||||||
|
Your tool is about to break!=Your tool is about to break!
|
||||||
|
Your @1@2@3 just leveled up!=Your @1@2@3 just leveled up!
|
11
locale/toolranks.fr.tr
Normal file
11
locale/toolranks.fr.tr
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# textdomain: toolranks
|
||||||
|
@1@2@n@3Level @4 @5@n@6Node dug: @7=@1@2@n@3@5 niveau @4@n@6Blocks minés : @7
|
||||||
|
pickaxe=pioche
|
||||||
|
axe=hache
|
||||||
|
shovel=pelle
|
||||||
|
hoe=houe
|
||||||
|
sword=épée
|
||||||
|
tool=outil
|
||||||
|
Most used tool is now a @1@2@3 owned by @4 with @5 uses.=L’outil le plus utilisé est désormais @1@2@3 appartenant à @4 avec @5 utilisations.
|
||||||
|
Your tool is about to break!=Votre outil va se casser !
|
||||||
|
Your @1@2@3 just leveled up!=Votre @1@2@3 a gagné un niveau !
|
2
mod.conf
2
mod.conf
@ -1,4 +1,2 @@
|
|||||||
name = toolranks
|
name = toolranks
|
||||||
depends = default
|
depends = default
|
||||||
optional_depends =
|
|
||||||
description = Add ability to level up tools to make them last longer.
|
|
||||||
|
8
settingtypes.txt
Normal file
8
settingtypes.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Number of tool levels
|
||||||
|
toolranks_levels (Levels) int 10
|
||||||
|
# Number of nodes that need to be dug to reach the next tool level
|
||||||
|
toolranks_level_digs (Digs per level) int 500
|
||||||
|
# Dig speed multiplier at maximum tool level (1.0 to disable)
|
||||||
|
toolranks_speed_multiplier (Dig speed multiplier) float 2.0 1.0 10.0
|
||||||
|
# Durability multiplier at maximum tool level (1.0 to disable)
|
||||||
|
toolranks_use_multiplier (Durability multiplier) float 2.0 1.0 10.0
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user