diff --git a/games/MeseCraft b/games/MeseCraft index 84cf63d..3d0bb81 160000 --- a/games/MeseCraft +++ b/games/MeseCraft @@ -1 +1 @@ -Subproject commit 84cf63d85c6eb9ead20ba6513a30cc4ca54dc467 +Subproject commit 3d0bb81f4d45d4e7021f12e6961891145c62563b diff --git a/worldmods/tt/API.md b/worldmods/tt/API.md new file mode 100755 index 0000000..a510553 --- /dev/null +++ b/worldmods/tt/API.md @@ -0,0 +1,31 @@ +# Tooltip API +This API explains how to handle the extended item tooltips (`description` field). + +## Fields + +Add these to the item definition. + +* `_tt_ignore`: If `true`, the `description` of this item won't be altered at all +* `_tt_help`: Custom help text + +Once this mod had overwritten the `description` field of an item was overwritten, it will save the original (unaltered) `description` in the `_tt_original_description` field. + +## `tt.register_snippet(func)` + +Register a custom snippet function. +`func` is a function of the form `func(itemstring)`. +It will be called for (nearly) every itemstring. + +Returns: Two values, the first one is required. +1st return value: A string you want to append to this item or `nil` if nothing shall be appended. +2nd return value: If nil, `tt` will take of the text color. If a ColorString in `"#RRGGBB"` format, entire text is colorized in this color. Return `false` to force `tt` to not apply text any colorization (useful if you want to call `minetest.colorize` yourself. + +Example: + +``` +tt.register_snippet(function(itemstring) + if minetest.get_item_group(itemstring, "magic") == 1 then + return "This item is magic" + end +end) +``` diff --git a/worldmods/tt/README.md b/worldmods/tt/README.md new file mode 100755 index 0000000..92cd652 --- /dev/null +++ b/worldmods/tt/README.md @@ -0,0 +1,11 @@ +# Extended Tooltip (`tt`) +This mod extends the tooltip of items to add more informative texts. + +The mod itself does nothing and is meant to be integrated into +games to use the API to define custom tooltips (see `API.md`). + +## Version +1.0.0 + +## License +MIT License. diff --git a/worldmods/tt/init.lua b/worldmods/tt/init.lua new file mode 100755 index 0000000..a79bf27 --- /dev/null +++ b/worldmods/tt/init.lua @@ -0,0 +1,50 @@ +tt = {} +tt.COLOR_DEFAULT = "#d0ffd0" +tt.COLOR_DANGER = "#ffff00" +tt.COLOR_GOOD = "#00ff00" + +-- API +tt.registered_snippets = {} + +tt.register_snippet = function(func) + table.insert(tt.registered_snippets, func) +end + +dofile(minetest.get_modpath(minetest.get_current_modname()).."/snippets.lua") + +-- Apply item description updates + +local function append_snippets() + for itemstring, def in pairs(minetest.registered_items) do + 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 + local desc = def.description + local orig_desc = desc + local first = true + -- Apply snippets + for s=1, #tt.registered_snippets do + local str, snippet_color = tt.registered_snippets[s](itemstring) + if snippet_color == nil then + snippet_color = tt.COLOR_DEFAULT + elseif snippet_color == false then + snippet_color = false + 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 + if desc ~= def.description then + minetest.override_item(itemstring, { description = desc, _tt_original_description = orig_desc }) + end + end + end +end + +minetest.register_on_mods_loaded(append_snippets) diff --git a/worldmods/tt/mod.conf b/worldmods/tt/mod.conf new file mode 100755 index 0000000..4060cf8 --- /dev/null +++ b/worldmods/tt/mod.conf @@ -0,0 +1,5 @@ +name = tt +description = Support for custom tooltip extensions for items +release = 5069 +author = Wuzzy +title = Extended Tooltips diff --git a/worldmods/tt/screenshot.png b/worldmods/tt/screenshot.png new file mode 100755 index 0000000..f3ab7dd Binary files /dev/null and b/worldmods/tt/screenshot.png differ diff --git a/worldmods/tt/snippets.lua b/worldmods/tt/snippets.lua new file mode 100755 index 0000000..694b225 --- /dev/null +++ b/worldmods/tt/snippets.lua @@ -0,0 +1,11 @@ +-- CUSTOM SNIPPETS -- + +-- Custom text (_tt_help) +tt.register_snippet(function(itemstring) + local def = minetest.registered_items[itemstring] + if def._tt_help then + return def._tt_help + end +end) + + diff --git a/worldmods/tt_base/README.md b/worldmods/tt_base/README.md new file mode 100755 index 0000000..5622e36 --- /dev/null +++ b/worldmods/tt_base/README.md @@ -0,0 +1,25 @@ +This mod is for the Extended Tooltips [tt] mod to extend item tooltips with the following +basic info: + +* Tool digging times +* Weapon stats +* Food stats +* Node damage +* Node light level +* Node info: climbable, slippery, bouncy, jumping restriction + +This mod assumes that the default gameplay behavior of Minetest is used. + +This mod introduces support for new item definition fields: + +* `_tt_food`: If `true`, item is a food item that can be consumed by the player +* `_tt_food_hp`: Health increase (in HP) for player when consuming food item + +Because there is no standard way in Minetest (yet) to mark an item as food, these fields +are required for food items to be recognized as such. + +## Version +1.0.0 + +## License +MIT License. diff --git a/worldmods/tt_base/init.lua b/worldmods/tt_base/init.lua new file mode 100755 index 0000000..4ea8a00 --- /dev/null +++ b/worldmods/tt_base/init.lua @@ -0,0 +1,190 @@ +local S = minetest.get_translator("tt_base") + +local function get_min_digtime(caps) + local mintime + local unique = true + local maxlevel = caps.maxlevel + if not maxlevel then + maxlevel = 1 + end + if maxlevel > 1 then + unique = false + end + if caps.times then + for r=1,3 do + local time = caps.times[r] + if time and maxlevel > 1 then + time = time / maxlevel + end + if time and ((not mintime) or (time < mintime)) then + if mintime and (time < mintime) then + unique = false + end + mintime = time + end + end + end + return mintime, unique +end + +local function newline(str) + if str ~= "" then + str = str .. "\n" + end + return str +end + +-- Tool information (digging times, weapon stats) +tt.register_snippet(function(itemstring) + local def = minetest.registered_items[itemstring] + local desc = "" + if def.tool_capabilities then + -- Digging times + local digs = "" + local d + if def.tool_capabilities.groupcaps then + for group, caps in pairs(def.tool_capabilities.groupcaps) do + local mintime, unique_mintime + if caps.times then + mintime, unique_mintime = get_min_digtime(caps) + if mintime and (mintime > 0 or (not unique_mintime)) then + d = S("Digs @1 blocks", group) .. "\n" + d = d .. S("Minimum dig time: @1s", string.format("%.2f", mintime)) + digs = newline(digs) + digs = digs .. d + elseif mintime and mintime == 0 then + d = S("Digs @1 blocks instantly", group) + digs = newline(digs) + digs = digs .. d + end + end + end + if digs ~= "" then + desc = desc .. digs + end + end + -- Weapon stats + if def.tool_capabilities.damage_groups then + for group, damage in pairs(def.tool_capabilities.damage_groups) do + local msg + if group == "fleshy" then + if damage >= 0 then + msg = S("Damage: @1", damage) + else + msg = S("Healing: @1", math.abs(damage)) + end + else + if damage >= 0 then + msg = S("Damage (@1): @2", group, damage) + else + msg = S("Healing (@1): @2", group, math.abs(damage)) + end + end + desc = newline(desc) + desc = desc .. msg + end + local full_punch_interval = def.tool_capabilities.full_punch_interval + if not full_punch_interval then + full_punch_interval = 1 + end + desc = newline(desc) + desc = desc .. S("Full punch interval: @1s", string.format("%.2f", full_punch_interval)) + end + end + if desc == "" then + desc = nil + end + return desc +end) + +-- Food +tt.register_snippet(function(itemstring) + local def = minetest.registered_items[itemstring] + local desc + if def._tt_food then + desc = S("Food item") + if def._tt_food_hp then + local msg = S("+@1 food points", def._tt_food_hp) + desc = desc .. "\n" .. msg + end + end + return desc +end) + +-- Node info +tt.register_snippet(function(itemstring) + local def = minetest.registered_items[itemstring] + local desc = "" + + -- Health-related node facts + if def.damage_per_second then + if def.damage_per_second > 0 then + desc = newline(desc) + desc = desc .. minetest.colorize(tt.COLOR_DANGER, S("Contact damage: @1 per second", def.damage_per_second)) + elseif def.damage_per_second < 0 then + desc = newline(desc) + desc = desc .. minetest.colorize(tt.COLOR_GOOD, S("Contact healing: @1 per second", math.abs(def.damage_per_second))) + end + end + if def.drowning and def.drowning ~= 0 then + desc = newline(desc) + desc = desc .. minetest.colorize(tt.COLOR_DANGER, S("Drowning damage: @1", def.drowning)) + end + local tmp = minetest.get_item_group(itemstring, "fall_damage_add_percent") + if tmp > 0 then + desc = newline(desc) + desc = desc .. minetest.colorize(tt.COLOR_DANGER, S("Fall damage: +@1%", tmp)) + elseif tmp == -100 then + desc = newline(desc) + desc = desc .. minetest.colorize(tt.COLOR_GOOD, S("No fall damage")) + elseif tmp < 0 then + desc = newline(desc) + desc = desc .. minetest.colorize(tt.COLOR_DEFAULT, S("Fall damage: @1%", tmp)) + end + + -- Movement-related node facts + if minetest.get_item_group(itemstring, "disable_jump") == 1 and not def.climbable then + if def.liquidtype == "none" then + desc = newline(desc) + desc = desc .. minetest.colorize(tt.COLOR_DEFAULT, S("No jumping")) + elseif minetest.get_item_group(itemstring, "fake_liquid") == 0 then + desc = newline(desc) + desc = desc .. minetest.colorize(tt.COLOR_DEFAULT, S("No swimming upwards")) + else + desc = newline(desc) + desc = desc .. minetest.colorize(tt.COLOR_DEFAULT, S("No rising")) + end + end + if def.climbable then + if minetest.get_item_group(itemstring, "disable_jump") == 1 then + desc = newline(desc) + desc = desc .. minetest.colorize(tt.COLOR_DEFAULT, S("Climbable (only downwards)")) + else + desc = newline(desc) + desc = desc .. minetest.colorize(tt.COLOR_DEFAULT, S("Climbable")) + end + end + if minetest.get_item_group(itemstring, "slippery") >= 1 then + desc = newline(desc) + desc = desc .. minetest.colorize(tt.COLOR_DEFAULT, S("Slippery")) + end + local tmp = minetest.get_item_group(itemstring, "bouncy") + if tmp >= 1 then + desc = newline(desc) + desc = desc .. minetest.colorize(tt.COLOR_DEFAULT, S("Bouncy (@1%)", tmp)) + end + + -- Node appearance + tmp = def.light_source + if tmp and tmp >= 1 then + desc = newline(desc) + desc = desc .. minetest.colorize(tt.COLOR_DEFAULT, S("Luminance: @1", tmp)) + end + + + if desc == "" then + desc = nil + end + return desc, false +end) + diff --git a/worldmods/tt_base/locale/template.txt b/worldmods/tt_base/locale/template.txt new file mode 100755 index 0000000..488a0e2 --- /dev/null +++ b/worldmods/tt_base/locale/template.txt @@ -0,0 +1,27 @@ +# textdomain:tt +Damage: @1= +Damage (@1): @2= +Healing: @1= +Healing (@1): @2= +Full punch interval: @1s= +Food item= ++@1 satiation= +@1 satiation= ++@1 food points= +Contact damage: @1 per second= +Contact healing: @1 per second= +Drowning damage: @1= +Bouncy (@1%)= +Luminance: @1= +Slippery= +Climbable= +Climbable (only downwards)= +No jumping= +No swimming upwards= +No rising= +Fall damage: @1%= +Fall damage: +@1%= +No fall damage= +Digs @1 blocks= +Digs @1 blocks instantly= +Minimum dig time: @1s= diff --git a/worldmods/tt_base/locale/tt_base.de.tr b/worldmods/tt_base/locale/tt_base.de.tr new file mode 100755 index 0000000..6e45bf6 --- /dev/null +++ b/worldmods/tt_base/locale/tt_base.de.tr @@ -0,0 +1,27 @@ +# textdomain:tt_base +Damage: @1=Schaden: @1 +Damage (@1): @2=Schaden (@1): @2 +Healing: @1=Heilung: @1 +Healing (@1): @2=Heilung (@1): @2 +Full punch interval: @1s=Zeit zum Ausholen: @1s +Food item=Lebensmittel ++@1 satiation=+@1 Sättigung +@1 satiation=@1 Sättigung ++@1 food points=+@1 Nahrungspunkte +Contact damage: @1 per second=Kontaktschaden: @1 pro Sekunde +Contact healing: @1 per second=Kontaktheilung: @1 pro Sekunde +Drowning damage: @1=Ertrinkensschaden: @1 +Bouncy (@1%)=Sprunghaft (@1%) +Luminance: @1=Lichtstärke: @1 +Slippery=Rutschig +Climbable=Erkletterbar +Climbable (only downwards)=Erkletterbar (nur nach unten) +No jumping=Kein Springen +No swimming upwards=Kein nach oben schwimmen +No rising=Kein Aufsteigen +Fall damage: @1%=Fallschaden: @1% +Fall damage: +@1%=Fallschaden: +@1% +No fall damage=Kein Fallschaden +Digs @1 blocks=Gräbt „@1“-Blöcke +Digs @1 blocks instantly=Gräbt „@1“-Blöcke sofort +Minimum dig time: @1s=Minimale Grabezeit: @1s diff --git a/worldmods/tt_base/locale/tt_base.ru.tr b/worldmods/tt_base/locale/tt_base.ru.tr new file mode 100755 index 0000000..20fa8a3 --- /dev/null +++ b/worldmods/tt_base/locale/tt_base.ru.tr @@ -0,0 +1,27 @@ +# textdomain: tt_base +Damage: @1=Урон: @1 +Damage (@1): @2=Урон (@1): @2 +Healing: @1=Лечение: @1 +Healing (@1): @2=Лечение (@1): @2 +Full punch interval: @1s=Полн. интерв. уд.: @1с +Food item=Еда ++@1 satiation=+@1 насыщение +@1 satiation=@1 насыщение ++@1 food points=+@1 оч. еды +Contact damage: @1 per second=Конт. урон: @1 в сек +Contact healing: @1 per second=Конт. лечение: @1 в сек +Drowning damage: @1=Повр. в жидк.: @1 +Bouncy (@1%)=Отскок (@1%) +Luminance: @1=Свечение: @1 +Slippery=Скользкий +Climbable=Взбираемый +Climbable (only downwards)=Взбираемый (только вниз) +No jumping=Нельзя прыгать +No swimming upwards=Нельзя плыть вверх +No rising=Нельзя подниматься +Fall damage: @1%=Урон от падения: @1% +Fall damage: +@1%=Урон от падения: +@1% +No fall damage=Нет урона от падения +Digs @1 blocks=Копает @1 блоки +Digs @1 blocks instantly=Копает @1 блоков мгновенно +Minimum dig time: @1s=Время копания: @1с diff --git a/worldmods/tt_base/mod.conf b/worldmods/tt_base/mod.conf new file mode 100755 index 0000000..af45bd2 --- /dev/null +++ b/worldmods/tt_base/mod.conf @@ -0,0 +1,6 @@ +name = tt_base +description = Adds generic tooltip extensions to items +depends = tt +release = 5068 +author = Wuzzy +title = Extended Tooltips: Base diff --git a/worldmods/tt_base/screenshot.png b/worldmods/tt_base/screenshot.png new file mode 100755 index 0000000..ef2dfa5 Binary files /dev/null and b/worldmods/tt_base/screenshot.png differ