Camas/mods/tt/init.lua

128 lines
4.7 KiB
Lua
Raw Normal View History

2019-12-05 10:30:46 +01:00
local S = minetest.get_translator("tt")
2020-01-31 03:42:44 +01:00
local COLOR_DEFAULT = "#d0ffd0"
local COLOR_DANGER = "#ffff00"
local COLOR_GOOD = "#00ff00"
2019-12-05 10:30:46 +01:00
tt = {}
tt.registered_snippets = {}
local function append_descs()
for itemstring, def in pairs(minetest.registered_items) do
2019-12-11 23:21:28 +01:00
if itemstring ~= "" and itemstring ~= "air" and itemstring ~= "ignore" and itemstring ~= "unknown" and def ~= nil and def.description ~= nil and def.description ~= "" and def._tt_ignore ~= true then
2019-12-05 10:30:46 +01:00
local desc = def.description
local orig_desc = desc
-- Custom text
if def._tt_help then
2020-01-31 03:42:44 +01:00
desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, def._tt_help)
2019-12-05 10:30:46 +01:00
end
2019-12-11 23:21:28 +01:00
-- Tool info
2019-12-05 10:30:46 +01:00
if def.tool_capabilities then
-- Digging stats
if def.tool_capabilities.groupcaps then
-- TODO: Add more detail (such as digging speed)
--local groups = {}
--for group, caps in pairs(def.tool_capabilities.groupcaps) do
-- table.insert(groups, group)
--end
2020-01-31 03:42:44 +01:00
--desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, S("Digs: @1", table.concat(groups, ", ")))
2019-12-05 10:30:46 +01:00
end
-- Weapon stats
if def.tool_capabilities.damage_groups then
for group, damage in pairs(def.tool_capabilities.damage_groups) do
if group == "fleshy" then
2020-01-31 03:42:44 +01:00
desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, S("Damage: @1", damage))
2019-12-05 10:30:46 +01:00
else
2020-01-31 03:42:44 +01:00
desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, S("Damage (@1): @2", group, damage))
2019-12-05 10:30:46 +01:00
end
end
local full_punch_interval = def.tool_capabilities.full_punch_interval
if not full_punch_interval then
full_punch_interval = 1
end
2020-01-31 03:42:44 +01:00
desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, S("Full punch interval: @1s", full_punch_interval))
2019-12-05 10:30:46 +01:00
end
end
-- Food
if def._tt_food then
2020-01-31 03:42:44 +01:00
desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, S("Food item"))
2019-12-05 10:30:46 +01:00
if def._tt_food_hp then
2020-02-01 04:18:30 +01:00
local msg = S("+@1 food points", def._tt_food_hp)
2020-01-31 03:42:44 +01:00
desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, msg)
2019-12-05 10:30:46 +01:00
end
-- NOTE: This is unused atm
--[[if def._tt_food_satiation then
if def._tt_food_satiation >= 0 then
msg = S("+@1 satiation", def._tt_food_satiation)
else
msg = S("@1 satiation", def._tt_food_satiation)
end
2020-01-31 03:42:44 +01:00
desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, msg)
2019-12-05 10:30:46 +01:00
end]]
end
2019-12-11 23:21:28 +01:00
-- Node info
-- Damage-related
do
if def.damage_per_second and def.damage_per_second > 0 then
2020-01-31 03:42:44 +01:00
desc = desc .. "\n" .. minetest.colorize(COLOR_DANGER, S("Contact damage: @1 per second", def.damage_per_second))
2019-12-11 23:21:28 +01:00
end
if def.drowning and def.drowning > 0 then
2020-01-31 03:42:44 +01:00
desc = desc .. "\n" .. minetest.colorize(COLOR_DANGER, S("Drowning damage: @1", def.drowning))
2019-12-11 23:21:28 +01:00
end
local tmp = minetest.get_item_group(itemstring, "fall_damage_add_percent")
if tmp > 0 then
2020-01-31 03:42:44 +01:00
desc = desc .. "\n" .. minetest.colorize(COLOR_DANGER, S("Fall damage: +@1%", tmp))
2019-12-11 23:21:28 +01:00
elseif tmp == -100 then
2020-01-31 03:42:44 +01:00
desc = desc .. "\n" .. minetest.colorize(COLOR_GOOD, S("No fall damage"))
2019-12-11 23:21:28 +01:00
elseif tmp < 0 then
2020-01-31 03:42:44 +01:00
desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, S("Fall damage: @1%", tmp))
2019-12-11 23:21:28 +01:00
end
end
-- Movement-related node facts
if minetest.get_item_group(itemstring, "disable_jump") == 1 and not def.climbable then
if def.liquidtype == "none" then
2020-01-31 03:42:44 +01:00
desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, S("No jumping"))
2019-12-11 23:21:28 +01:00
else
2020-01-31 03:42:44 +01:00
desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, S("No swimming upwards"))
2019-12-11 23:21:28 +01:00
end
end
if def.climbable then
if minetest.get_item_group(itemstring, "disable_jump") == 1 then
2020-01-31 03:42:44 +01:00
desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, S("Climbable (only downwards)"))
2019-12-11 23:21:28 +01:00
else
2020-01-31 03:42:44 +01:00
desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, S("Climbable"))
2019-12-11 23:21:28 +01:00
end
end
if minetest.get_item_group(itemstring, "slippery") >= 1 then
2020-01-31 03:42:44 +01:00
desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, S("Slippery"))
2019-12-11 23:21:28 +01:00
end
2020-02-01 04:18:30 +01:00
local tmp = minetest.get_item_group(itemstring, "bouncy")
2019-12-11 23:21:28 +01:00
if tmp >= 1 then
2020-01-31 03:42:44 +01:00
desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, S("Bouncy (@1%)", tmp))
2019-12-11 23:21:28 +01:00
end
-- Node appearance
tmp = def.light_source
if tmp and tmp >= 1 then
2020-01-31 03:42:44 +01:00
desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, S("Luminance: @1", tmp))
2019-12-11 23:21:28 +01:00
end
2019-12-05 10:30:46 +01:00
-- Custom functions
for s=1, #tt.registered_snippets do
2020-01-31 03:42:44 +01:00
local str, snippet_color = tt.registered_snippets[s](itemstring)
if not snippet_color then
snippet_color = COLOR_DEFAULT
end
2019-12-05 10:30:46 +01:00
if str then
2020-01-31 03:42:44 +01:00
desc = desc .. "\n" .. minetest.colorize(snippet_color, str)
2019-12-05 10:30:46 +01:00
end
end
minetest.override_item(itemstring, { description = desc, _tt_original_description = orig_desc })
end
end
end
tt.register_snippet = function(func)
table.insert(tt.registered_snippets, func)
end
minetest.register_on_mods_loaded(append_descs)