Add Toolranks mod

This commit is contained in:
MoNTE48 2019-10-15 16:42:03 +02:00
parent 925fd33455
commit 77bbdedfb0
6 changed files with 138 additions and 7 deletions

View File

@ -64,6 +64,8 @@ minetest.register_node("fire:basic_flame", flame_fire_node)
-- Permanent flame nodes
minetest.register_node("fire:permanent_flame", fire_node)
local tr = minetest.get_modpath("toolranks")
-- Flint and Steel
minetest.register_tool("fire:flint_and_steel", {
description = "Flint and Steel",
@ -96,7 +98,14 @@ minetest.register_tool("fire:flint_and_steel", {
and creative.is_enabled_for(player_name)) then
-- Wear tool
local wdef = itemstack:get_definition()
itemstack:add_wear(1000)
-- Toolranks support
if tr then
toolranks.new_afteruse(itemstack, user, nil, {wear = 1000})
else
itemstack:add_wear(1000)
end
-- Tool break sound
if itemstack:get_count() == 0 and wdef.sound and wdef.sound.breaks then
minetest.sound_play(wdef.sound.breaks, {pos = sound_pos, gain = 0.5})
@ -206,7 +215,7 @@ if flame_sound then
to_player = player_name,
gain = math.min(0.06 * (1 + flames * 0.125), 0.18),
max_hear_distance = 32,
loop = true, -- In case of lag
loop = true -- In case of lag
})
-- Store sound handle for this player
if handle then
@ -261,7 +270,7 @@ if minetest.is_singleplayer() then
if p then
minetest.set_node(p, {name = "fire:basic_flame"})
end
end,
end
})
-- Remove flammable nodes around basic flame
@ -273,10 +282,10 @@ if minetest.is_singleplayer() then
chance = 18,
catch_up = false,
action = function(pos)
local p = minetest.find_node_near(pos, 1, {"group:flammable"})
if not p then
return
end
local p = minetest.find_node_near(pos, 1, {"group:flammable"})
if not p then
return
end
local flammable_node = minetest.get_node(p)
local def = minetest.registered_nodes[flammable_node.name]
if def.on_burn then

View File

@ -0,0 +1,21 @@
MutliCraft Game mod: toolranks
==============================
See license.txt for license information.
Tool gains levels for digging nodes. Higher level tools take longer to
wear out.
https://github.com/lisacvuk/minetest-toolranks
https://notabug.org/TenPlus1/toolranks
Authors of source code
----------------------
lisacvuk (LGPLv3.0+)
TenPlus1 (LGPLv3.0+)
MultiCraft Development Team (LGPLv3.0+)
Authors of sounds
-----------------
Cabeeno Rossley (CC BY 3.0)
https://freesound.org/people/Cabeeno%20Rossley/sounds/126422/
toolranks_levelup.ogg

View File

@ -0,0 +1 @@
default

95
files/toolranks/init.lua Normal file
View File

@ -0,0 +1,95 @@
-- Intllib
local S = intllib.make_gettext_pair()
toolranks = {}
local function create_description(name, uses, level)
if not uses then return name end
return default.colors.green .. name .. "\n"
.. default.colors.gold .. S("Level") .. ": " .. (level or 1) .. "\n"
.. default.colors.grey .. S("Uses") .. ": " .. (uses or 0)
end
function toolranks.get_level(uses)
if uses >= 3200 then
return 6
elseif uses >= 1600 then
return 5
elseif uses >= 800 then
return 4
elseif uses >= 400 then
return 3
elseif uses >= 200 then
return 2
else
return 1
end
end
function toolranks.new_afteruse(itemstack, user, node, digparams)
-- Get tool metadata and number of times used
local itemmeta = itemstack:get_meta()
local dugnodes = tonumber(itemmeta:get_string("dug")) or 1
-- Only count nodes that spend the tool
if digparams.wear > 0 then
dugnodes = dugnodes + 1
itemmeta:set_string("dug", dugnodes)
else
return
end
-- Get tool description and last level
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
if itemstack:get_wear() > 60100 then
minetest.chat_send_player(name,
default.colors.gold .. S("Your tool is almost broken!"))
minetest.sound_play("default_tool_breaks", {
to_player = name,
gain = 2.0
})
end
local level = toolranks.get_level(dugnodes)
-- Alert player when tool got a new level
if lastlevel < level then
minetest.chat_send_player(name, S("Your") .. " "
.. default.colors.green .. itemdesc
.. default.colors.white .. " " .. S("got a new level!"))
minetest.sound_play("toolranks_levelup", {
to_player = name,
gain = 1.0
})
itemmeta:set_string("lastlevel", level)
end
-- Set new meta
local newdesc = create_description(itemdesc, dugnodes, level)
itemmeta:set_string("description", newdesc)
-- Set wear level
local wear = digparams.wear
if level > 1 then
wear = digparams.wear * 4 / (4 + level)
end
itemstack:add_wear(wear)
return itemstack
end
-- Helper function
minetest.after(0, function()
for name, def in pairs(minetest.registered_tools) do
minetest.override_item(name, {
original_description = def.description,
description = create_description(def.description),
after_use = toolranks.new_afteruse
})
end
end)

View File

@ -0,0 +1,5 @@
Level = Уровень
Uses = Использований
Your tool is almost broken! = Ваш инструмент почти сломан!
Your = Ваш инструмент
got a new level! = получил новый уровень!

Binary file not shown.