2020-02-19 03:54:17 +00:00
|
|
|
tt = {}
|
2021-03-29 22:01:29 +00:00
|
|
|
tt.COLOR_DEFAULT = mcl_colors.GREEN
|
|
|
|
tt.COLOR_DANGER = mcl_colors.YELLOW
|
|
|
|
tt.COLOR_GOOD = mcl_colors.GREEN
|
|
|
|
tt.NAME_COLOR = mcl_colors.YELLOW
|
2020-02-19 03:54:17 +00:00
|
|
|
|
|
|
|
-- API
|
|
|
|
tt.registered_snippets = {}
|
|
|
|
|
2021-05-27 22:34:58 +00:00
|
|
|
function tt.register_snippet(func)
|
2020-02-19 03:54:17 +00:00
|
|
|
table.insert(tt.registered_snippets, func)
|
|
|
|
end
|
|
|
|
|
2021-05-27 22:34:58 +00:00
|
|
|
function tt.register_priority_snippet(func)
|
2021-05-01 14:52:16 +00:00
|
|
|
table.insert(tt.registered_snippets, 1, func)
|
|
|
|
end
|
|
|
|
|
2020-09-10 13:34:53 +00:00
|
|
|
dofile(minetest.get_modpath(minetest.get_current_modname()).."/snippets.lua")
|
2020-02-19 03:54:17 +00:00
|
|
|
|
|
|
|
-- Apply item description updates
|
|
|
|
|
2020-10-27 18:53:49 +00:00
|
|
|
local function apply_snippets(desc, itemstring, toolcaps, itemstack)
|
|
|
|
local first = true
|
|
|
|
-- Apply snippets
|
|
|
|
for s=1, #tt.registered_snippets do
|
|
|
|
local str, snippet_color = tt.registered_snippets[s](itemstring, toolcaps, itemstack)
|
|
|
|
if snippet_color == nil then
|
|
|
|
snippet_color = tt.COLOR_DEFAULT
|
|
|
|
end
|
|
|
|
if str then
|
|
|
|
if first then
|
|
|
|
first = false
|
|
|
|
end
|
|
|
|
desc = desc .. "\n"
|
|
|
|
if snippet_color then
|
|
|
|
desc = desc .. minetest.colorize(snippet_color, str)
|
|
|
|
else
|
|
|
|
desc = desc .. str
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return desc
|
|
|
|
end
|
|
|
|
|
|
|
|
local function should_change(itemstring, def)
|
2021-05-29 14:12:33 +00:00
|
|
|
return itemstring ~= "" and itemstring ~= "air" and itemstring ~= "ignore" and itemstring ~= "unknown" and def and def.description and def.description ~= "" and def._tt_ignore ~= true
|
2020-10-27 18:53:49 +00:00
|
|
|
end
|
|
|
|
|
2020-02-19 03:54:17 +00:00
|
|
|
local function append_snippets()
|
|
|
|
for itemstring, def in pairs(minetest.registered_items) do
|
2020-10-27 18:53:49 +00:00
|
|
|
if should_change(itemstring, def) then
|
|
|
|
local orig_desc = def.description
|
|
|
|
local desc = apply_snippets(orig_desc, itemstring, def.tool_capabilities, nil)
|
|
|
|
if desc ~= orig_desc then
|
2020-02-19 03:54:17 +00:00
|
|
|
minetest.override_item(itemstring, { description = desc, _tt_original_description = orig_desc })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_mods_loaded(append_snippets)
|
2020-10-27 18:53:49 +00:00
|
|
|
|
2021-05-27 22:34:58 +00:00
|
|
|
function tt.reload_itemstack_description(itemstack)
|
2020-10-27 18:53:49 +00:00
|
|
|
local itemstring = itemstack:get_name()
|
|
|
|
local def = itemstack:get_definition()
|
2020-11-01 12:44:05 +00:00
|
|
|
local meta = itemstack:get_meta()
|
2020-11-01 13:23:43 +00:00
|
|
|
if def and def._mcl_generate_description then
|
2020-11-01 12:44:05 +00:00
|
|
|
def._mcl_generate_description(itemstack)
|
2021-03-22 21:50:14 +00:00
|
|
|
elseif should_change(itemstring, def) then
|
2020-11-25 11:47:27 +00:00
|
|
|
local toolcaps
|
|
|
|
if def.tool_capabilities then
|
|
|
|
toolcaps = itemstack:get_tool_capabilities()
|
2020-11-01 13:23:43 +00:00
|
|
|
end
|
|
|
|
local orig_desc = def._tt_original_description or def.description
|
2021-03-22 21:50:14 +00:00
|
|
|
if meta:get_string("name") ~= "" then
|
|
|
|
orig_desc = minetest.colorize(tt.NAME_COLOR, meta:get_string("name"))
|
2023-10-27 03:08:23 +00:00
|
|
|
elseif def.groups._mcl_potion == 1 then
|
|
|
|
local potency = meta:get_int("mcl_potions:potion_potent")
|
|
|
|
local plus = meta:get_int("mcl_potions:potion_plus")
|
|
|
|
if potency > 0 then
|
|
|
|
local sym_potency = mcl_util.to_roman(potency+1)
|
|
|
|
orig_desc = orig_desc.. " ".. sym_potency
|
|
|
|
end
|
|
|
|
if plus > 0 then
|
|
|
|
local sym_plus = " "
|
|
|
|
local i = plus
|
|
|
|
while i>0 do
|
|
|
|
i = i - 1
|
|
|
|
sym_plus = sym_plus.. "+"
|
|
|
|
end
|
|
|
|
orig_desc = orig_desc.. sym_plus
|
|
|
|
end
|
2021-03-22 21:50:14 +00:00
|
|
|
end
|
2020-11-01 13:23:43 +00:00
|
|
|
local desc = apply_snippets(orig_desc, itemstring, toolcaps or def.tool_capabilities, itemstack)
|
2024-04-28 15:04:39 +00:00
|
|
|
if desc == def.description and meta:get_string("description") == "" then return end
|
2021-11-20 13:52:51 +00:00
|
|
|
meta:set_string("description", desc)
|
2020-10-27 18:53:49 +00:00
|
|
|
end
|
|
|
|
end
|