diff --git a/API.md b/API.md index f70d2e6..843e410 100644 --- a/API.md +++ b/API.md @@ -8,8 +8,6 @@ This API allows you to add, change, hide and unhide custom HUD bars for this mod To give you a *very* brief overview over this API, here is the basic workflow on how to add your own custom HUD bar: * Create images for your HUD bar -* Optionally, set `hb.hp_max` to customize maximun healt of player, implementing lua minetest api -* Optional, set `hb.breath_max` to customize maximun players breath, implementing lua minetest api * Call `hb.register_hudbar` to make the definition of the HUD bar known to this mod * Call `hb.init_hudbar` for each player for which you want to use previously defined HUD bar * Use `hb.change_hudbar` whenever you need to change the values of a HUD bar of a certain player @@ -94,11 +92,8 @@ explicitly initialized on a per-player basis. You probably want to do this in the `minetest.register_on_joinplayer`. -Take into consideration there's a rare bug on minetest engine that into this callback, -sometimes that call its lazy and do not executed well. In such case just recall again only one time. - ### `hb.init_hudbar(player, identifier, start_value, start_max, start_hidden)` -This function initializes and activates a previously registered HUD bar and assigns it to a +This function initialzes and activates a previously registered HUD bar and assigns it to a certain client/player. This has only to be done once per player and after that, you can change the values using `hb.change_hudbar`. diff --git a/README.md b/README.md index 09f00c3..98b4ad9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # minetest HUD bars -HUD mod to display as bars and API for +HUD mod to display as bars and API for healt, armor, breath, hunger ## Information -------------- @@ -13,37 +13,125 @@ this mod will place them accordingly. ![](screenshot.png) +### Features + +* This mod adds a mechanic for hunger, using "satiation" concept +* This mod adds information bar for armor status +* Eating an apple (from Minetest Game) increases your satiation by 2 + +> Warning: Eating food will not directly increase your health anymore, as long as the food +item is supported by this mod (see below). + +> Warning: ! Some foods may be poisoned. If you eat a poisoned item, you may still get a satiation +boost, but for a brief period you lose health points because of food poisoning. However, +food poisoning can never kill you. + ## Technical info ----------------- +This mod its a simplification of hudbars+hbarmor+hbhunger for performance +it provides extra checks for security an backguard compatibility +on all minetest engines. TExture media was optimized for low end devices. + +This fusioned hudbars 2.3.4.0 and hbarmor 1.0.1 with hbhunger 1.1.2 +with aditional patches rejected by upstream that improves performance. + +#### About armor support + +This mod adds a simple HUD bar which displays the current damage +of the player's armor (from the 3D Armor [`3d_armor`] mod) as a percentage (rounded). + +100% armor means the armor is in perfect shape. 0% means the armor is almost destroyed +or non-existant. Note that to reach 100%, the player must wear at least 4 or 6 different +pieces of armor in perfect shape. + +#### About hunger supoort + +This mod adds a hunger buildin mechanic to the game. Players get a new attribute called “satiation”: + +* A new player starts with 20 satiation points out of 30 +* Actions like digging, placing and walking cause exhaustion, which lower the satiation +* Every 800 seconds you lose 1 satiation point without doing anything +* At 1 or 0 satiation you will suffer damage and die in case you don't eat something +* If your satiation is 16 or higher, you will slowly regenerate health points +* Eating food will increase your satiation (Duh!) + +All mods which add food through standard measures (`minetest.item_eat`) are already +supported automatically. Poisoned food needs special support. + +#### Dependencies + +* default +* 3d_armor +* farming + +More mod are optionally supported depending of availability + +#### Known supported food mods + +* Apple and Blueberries from Minetest Game [`default`] +* Red and brown mushroom from Minetest Game [`flowers`] +* Bread from Minetest Game [`farming`] +* [`animalmaterials`] (Mob Framework (`mobf` modpack)) +* Bushes [`bushes`] +* [`bushes_classic`] +* Creatures [`creatures`] +* [`dwarves`] (beer and such) +* Docfarming [`docfarming`] +* Ethereal / Ethereal NG [`ethereal`] +* Farming Redo [`farming`] by TenPlus1 +* Farming plus [`farming_plus`] +* Ferns [`ferns`] +* Fishing [`fishing`] +* [`fruit`] +* Glooptest [`glooptest`] +* JKMod ([`jkanimals`], [`jkfarming`], [`jkwine`]) +* [`kpgmobs`] +* [`mobfcooking`] +* [`mooretrees`] +* [`mtfoods`] +* [`mushroom`] +* [`mush45`] +* Seaplants [`sea`] +* Simple mobs [`mobs`] +* Pizza [`pizza`] +* Not So Simple Mobs [`nssm`] + +#### Statbar mode + +If you use the statbar mode of the HUD Bars mod, these things are important to know: +As with all mods using HUD Bars, the bread statbar symbols represent the rough percentage +out of 30 satiation points, in steps of 5%, so the symbols give you an estimate of your +satiation. This is different from the hunger mod by BlockMen. + > **Warning** Keep in mind if running a server with this mod, that the custom position should be displayed correctly on every screen size. -#### Dependencies - -There's no depends, older engines just need intlib but its optional - #### Current version -The current version is 2.3.4.1 its a plus fork from original cos current +The current version is 2.3.5 its a plus fork from original cos current minetest most close mods developers are not so open to support already working servers. -This fork feaured real honoring to max healt and max breath and customization of, also: +It works for Minetest 0.4.16+/5.X+ or later. -It works for Minetest 0.4.17+ (maybe 0.4.16 too) or later, including lastest crap from 5.7+. - -#### Settings +#### Configurations This mod can be configured quite a bit. You can change HUD bar appearance, offsets, ordering, and more. Use the advanced settings menu in Minetest for detailed configuration. -| configuration name | Description | type | values, min/default/max | +| configuration name | Description | type | values, default/min/max | | ---------------------------- | ------------------------------------- | ---- | ------------------------ | | hudbars_hp_player_maximun | set the maximun hp of the player healt | int | 10 20 60 | | hudbars_br_player_maximun | set the maximun player breath value | int | 10 10 30 | -| hudbars_bar_type | HUD bars style | enum | progress_bar progress_bar,statbar_classic,statbar_modern | +| hbarmor_autohide | Automatically hide armor HUD bar | bool | false | +| hbhunger_satiation_tick | Time in seconds which 1 saturation point is taken | float | 800 | +| hbhunger_satiation_sprint_dig | exhaustion increased this value after digged node | float | 3 | +| hbhunger_satiation_sprint_place | exhaustion increased this value after placed | float | 1 | +| hbhunger_satiation_sprint_move | exhaustion increased this value if player moves | float | 0.2 | +| hbhunger_satiation_sprint_lvl | at what exhaustion player satiation gets lowerd | float | 160 | +| hudbars_bar_type | HUD bars style | enum | progress_bar (progress_bar,statbar_classic,statbar_modern) | | hudbars_autohide_breath | Automatically hide breath indicators | bool | true | -| hudbars_alignment_pattern | HUD bars alignment pattern | enum | zigzag zigzag,stack_up,stack_down | +| hudbars_alignment_pattern | HUD bars alignment pattern | enum | zigzag (zigzag,stack_up,stack_down) | | hudbars_sorting | HUD bars order | string | breath=1, health=0 | | hudbars_pos_left_x | Left HUD bar screen x position | float | 0.5 0.0 1.0 | | hudbars_pos_left_y | Left HUD bar screen y position | float | 1.0 0.0 1.0 | @@ -58,7 +146,7 @@ Use the advanced settings menu in Minetest for detailed configuration. | hudbars_start_statbar_offset_right_x | Right HUD statbar x offset | int | 25 | | hudbars_start_statbar_offset_right_y | Right HUD statbar y offset | int | -90 | | hudbars_vmargin | Vertical distance between HUD bars | int | 24 0 | -| hudbars_tick | Default HUD bars update interval | float | 0.1 0.0 4.0 | +| hudbars_tick | Default HUD bars update interval | float | 0.2 0.0 4.0 | #### API @@ -69,9 +157,12 @@ Documentation for the API of this mod can be found in [`API.md`.](API.md) #### License of source code -Author: Wuzzy (2015) +Authors: -Also: This mod was forked from the “Better HUD” [hud] mod by BlockMen. +* Wuzzy (2015) +* PICCORO Lenz McKAY (2023) + +This mod was forked from the “Better HUD” (and hunger) [hud] mod by BlockMen. Translations: @@ -91,12 +182,15 @@ and/or modify it under the terms of the MIT License. #### Licenses of textures * `hudbars_icon_health.png`—celeron55 (CC BY-SA 3.0), modified by BlockMen -* `hudbars_bgicon_health.png`—celeron55 (CC BY-SA 3.0), modified by BlockMen * `hudbars_icon_breath.png`—kaeza (MIT License), modified by BlockMen, modified again by Wuzzy -* `hudbars_bgicon_breath.png`—based on previous image, edited by Wuzzy (MIT License) * `hudbars_bar_health.png`—Wuzzy (MIT License) * `hudbars_bar_breath.png`—Wuzzy (MIT License) * `hudbars_bar_background.png`—Wuzzy (MIT License) +* `hbarmor_icon.png`—Stu ([CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/)), modified by BlockMen +* `hbarmor_bar.png`—Wuzzy (MIT License) +* `hbhunger_icon.png`—PilzAdam ([MIT License](https://opensource.org/licenses/MIT)), modified by BlockMen +* `hbhunger_bar.png`—Wuzzy (MIT License) +* `hbhunger_icon_health_poison.png`—celeron55 ([CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/)), modified by BlockMen, modified again by Wuzzy #### License references diff --git a/default_settings.lua b/default_settings.lua index dd6d4d3..75ec2e6 100644 --- a/default_settings.lua +++ b/default_settings.lua @@ -25,14 +25,14 @@ else hb.settings.start_offset_right.y = hb.load_setting("hudbars_start_statbar_offset_right_y", "number", -90) end hb.settings.vmargin = hb.load_setting("hudbars_vmargin", "number", 24) -hb.settings.tick = hb.load_setting("hudbars_tick", "number", 0.1) +hb.settings.tick = hb.load_setting("hudbars_tick", "number", 0.3) -- Experimental setting: Changing this setting is not officially supported, do NOT rely on it! hb.settings.forceload_default_hudbars = hb.load_setting("hudbars_forceload_default_hudbars", "bool", true) -- Misc. settings hb.settings.alignment_pattern = hb.load_setting("hudbars_alignment_pattern", "string", "zigzag", {"zigzag", "stack_up", "stack_down"}) -hb.settings.autohide_breath = hb.load_setting("hudbars_autohide_breath", "bool", true) +hb.settings.autohide_breath = hb.load_setting("hudbars_autohide_breath", "bool", (true and not hb.settings.forceload_default_hudbars)) local sorting = minetest.settings:get("hudbars_sorting") if sorting ~= nil then @@ -47,10 +47,33 @@ else hb.settings.sorting_reverse = { [0] = "health", [1] = "breath" } end -hb.settings.hp_player_maximun = hb.load_setting("hudbars_hp_player_maximun", "number", 20) -hb.settings.br_player_maximun = hb.load_setting("hudbars_br_player_maximun", "number", 10) +hb.settings.hp_player_maximun = hb.load_setting("hudbars_hp_player_maximun", "number", 40) +hb.settings.br_player_maximun = hb.load_setting("hudbars_br_player_maximun", "number", 20) --- expose direct api -hb.hp_max = hb.settings.hp_player_maximun -hb.breath_max = hb.settings.br_player_maximun +if minetest.has_feature("object_use_texture_alpha") then +core.PLAYER_MAX_HP_DEFAULT = hb.settings.hp_player_maximun +else +core.PLAYER_MAX_HP = hb.settings.hp_player_maximun +end +hbarmor.autohide = (true and not hb.settings.forceload_default_hudbars) + +hbhunger.HUD_TICK = 0.2 + +hbhunger.HUNGER_TICK = 800 -- time in seconds after that 1 hunger point is taken +hbhunger.EXHAUST_DIG = 3 -- exhaustion increased this value after digged node +hbhunger.EXHAUST_PLACE = 1 -- exhaustion increased this value after placed +hbhunger.EXHAUST_MOVE = 0.2 -- exhaustion increased this value if player movement detected +hbhunger.EXHAUST_LVL = 160 -- at what exhaustion player satiation gets lowerd +hbhunger.SAT_MAX = 30 -- maximum satiation points +hbhunger.SAT_INIT = 20 -- initial satiation points +hbhunger.SAT_HEAL = 15 -- required satiation points to start healing + +local set + +set = minetest.settings:get_bool("hbarmor_autohide") if set ~= nil then hbarmor.autohide = set end +set = minetest.settings:get("hbhunger_satiation_tick") if set ~= nil then hbhunger.HUNGER_TICK = tonumber(set) end +set = minetest.settings:get("hbhunger_satiation_dig") if set ~= nil then hbhunger.HUNGER_DIG = tonumber(set) end +set = minetest.settings:get("hbhunger_satiation_place") if set ~= nil then hbhunger.HUNGER_PLACE = tonumber(set) end +set = minetest.settings:get("hbhunger_satiation_move") if set ~= nil then hbhunger.HUNGER_MOVE = tonumber(set) end +set = minetest.settings:get("hbhunger_satiation_lvl") if set ~= nil then hbhunger.HUNGER_LVL = tonumber(set) end diff --git a/depends.txt b/depends.txt index d9b8b81..afc33be 100644 --- a/depends.txt +++ b/depends.txt @@ -1 +1,31 @@ -intllib? \ No newline at end of file +default? +intllib? +3d_armor? +flowers? +animalmaterials? +bucket? +bushes? +bushes_classic? +cooking? +creatures? +docfarming? +dwarves? +ethereal? +farming? +farming_plus? +ferns? +fishing? +fruit? +glooptest? +jkanimals? +jkfarming? +jkwine? +kpgmobs? +mobfcooking? +mobs?moretrees? +mtfoods? +mush45? +mushroom? +seaplants? +pizza? +nssm? diff --git a/description.txt b/description.txt index 726453c..3b178c7 100644 --- a/description.txt +++ b/description.txt @@ -1 +1 @@ -HUD mod to display as bars and API for \ No newline at end of file +HUD mod to display as bars and API for satiaton/stamina and armor status features diff --git a/init.lua b/init.lua index 5fff6b9..1e3eb83 100644 --- a/init.lua +++ b/init.lua @@ -24,7 +24,13 @@ end local N = function(s) return s end +if (not armor) or (not armor.def) then + minetest.log("error", "[hbarmor] Outdated 3d_armor version. Please update your version of 3d_armor!") +end + hb = {} +hb.version = "2.3.5.0" +hb.redo = true hb.hudtables = {} @@ -34,8 +40,34 @@ hb.hudbars_count = 0 -- table which records which HUD bar slots have been “registered” so far; used for automatic positioning hb.registered_slots = {} +-- Table which contains all players with active default HUD bars (only for internal use) +hb.players = {} + +hbarmor = {} +hbhunger = {} + +-- HUD item ids +local hunger_hud = {} + +-- Stores if player's HUD bar has been initialized so far. +hbarmor.player_active = {} + +-- HUD statbar values +hbarmor.armor = {} +hbhunger.food = {} +hbhunger.hunger = {} +hbhunger.hunger_out = {} +hbhunger.poisonings = {} +hbhunger.exhaustion = {} -- Exhaustion is experimental! + +-- If true, the armor bar is hidden when the player does not wear any armor +hbarmor.autohide = true + hb.settings = {} +hb.hba = minetest.get_modpath("hbarmor") +hb.hbh = minetest.get_modpath("hbhunger") + function hb.load_setting(sname, stype, defaultval, valid_values) local sval if stype == "string" then @@ -70,13 +102,56 @@ end -- Load default settings dofile(minetest.get_modpath("hudbars").."/default_settings.lua") +if not hb.hbh then + + -- due lackof global hbhunger these need to be first + hbhunger.get_hunger_raw = function(player) + local inv = player:get_inventory() + if not inv then return nil end + local hgp = inv:get_stack("hunger", 1):get_count() + if hgp == 0 then + hgp = 21 + inv:set_stack("hunger", 1, ItemStack({name=":", count=hgp})) + else + hgp = hgp + end + return hgp-1 + end + + hbhunger.set_hunger_raw = function(player) + local inv = player:get_inventory() + local name = player:get_player_name() + local value = hbhunger.hunger[name] + if not inv or not value then return nil end + if value > hbhunger.SAT_MAX then value = hbhunger.SAT_MAX end + if value < 0 then value = 0 end + + inv:set_stack("hunger", 1, ItemStack({name=":", count=value+1})) + + return true + end + + -- Load hunger management function for food and mod handling + dofile(minetest.get_modpath("hudbars").."/hunger.lua") + dofile(minetest.get_modpath("hudbars").."/register_foods.lua") + +end + local function player_exists(player) - return player ~= nil and player:is_player() + return player ~= nil and (type(player) == "userdata") +end + +local must_hide = function(playername, arm) + return ((not armor.def[playername].count or armor.def[playername].count == 0 or not hb.settings.forceload_default_hudbars) and arm == 0) +end + +local arm_printable = function(arm) + return math.ceil(math.floor(arm+0.5)) end local function checksupportmax(player) local statusinfo = minetest.get_server_status() - if string.find(statusinfo,"0.4.1") and not string.find(statusinfo,"0.4.19") and not string.find(statusinfo,"0.4.18") and not string.find(statusinfo,"0.4.17.4") then + if string.find(statusinfo,"0.4.1") and not string.find(statusinfo,"0.4.18") and not string.find(statusinfo,"0.4.17.3") then hb.settings.hp_player_maximun = 20 hb.settings.br_player_maximun = 10 if player_exists(player) then @@ -116,9 +191,6 @@ local function make_label(format_string, format_string_config, label, start_valu return ret end --- Table which contains all players with active default HUD bars (only for internal use) -hb.players = {} - function hb.value_to_barlength(value, max) if max == 0 then return 0 @@ -234,7 +306,7 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta hud_elem_type = "image", position = pos, scale = bgscale, - text = "hudbars_bar_background.png", + text = "", alignment = {x=1,y=1}, offset = { x = offset.x - 1, y = offset.y - 1 }, z_index = 0, @@ -312,7 +384,8 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta state.text = text state.barlength = hb.value_to_barlength(start_value, start_max) - local main_error_text = "[hudbars] Bad initial values of HUD bar identifier “"..tostring(identifier).."” for player "..name..". " + local main_error_text = + "[hudbars] Bad initial values of HUD bar identifier “"..tostring(identifier).."” for player "..name..". " if start_max < start_value then minetest.log("error", main_error_text.."start_max ("..start_max..") is smaller than start_value ("..start_value..")!") @@ -455,6 +528,8 @@ function hb.hide_hudbar(player, identifier) local name = player:get_player_name() local hudtable = hb.get_hudtable(identifier) if hudtable == nil then return false end + if not hudtable.hudstate[name] then return false end + if not hudtable.hudstate[name].hidden then return false end if hudtable.hudstate[name].hidden == true then return true end if hb.settings.bar_type == "progress_bar" then if hudtable.hudids[name].icon ~= nil then @@ -474,7 +549,8 @@ function hb.unhide_hudbar(player, identifier) local name = player:get_player_name() local hudtable = hb.get_hudtable(identifier) if hudtable == nil then return false end - if hudtable.hudstate[name].hidden == false then return true end + if not hudtable.hudstate[name] then return false end + if not hudtable.hudstate[name].hidden then return false end local value = hudtable.hudstate[name].value local max = hudtable.hudstate[name].max if hb.settings.bar_type == "progress_bar" then @@ -517,10 +593,20 @@ function hb.get_hudbar_identifiers() return ids end ---register built-in HUD bars +--register built-in HUD bars and armor HUD bar if minetest.settings:get_bool("enable_damage") or hb.settings.forceload_default_hudbars then - hb.register_hudbar("health", 0xFFFFFF, S("Health"), { bar = "hudbars_bar_health.png", icon = "hudbars_icon_health.png", bgicon = "hudbars_bgicon_health.png" }, hb.settings.hp_player_maximun, hb.settings.hp_player_maximun, false) - hb.register_hudbar("breath", 0xFFFFFF, S("Breath"), { bar = "hudbars_bar_breath.png", icon = "hudbars_icon_breath.png", bgicon = "hudbars_bgicon_breath.png" }, hb.settings.br_player_maximun, hb.settings.br_player_maximun, true) + local hicon = "hudbars_icon_health.png" + local bicon = "hudbars_icon_breath.png" + local aicon = "hbarmor_icon.png" + local sicon = "hbhunger_icon.png" + hb.register_hudbar("health", 0xFFFFFF, S("Health"), { bar = "hudbars_bar_health.png", icon = hicon, bgicon = nil }, hb.settings.hp_player_maximun, hb.settings.hp_player_maximun, false) + hb.register_hudbar("breath", 0xFFFFFF, S("Breath"), { bar = "hudbars_bar_breath.png", icon = bicon, bgicon = nil }, hb.settings.br_player_maximun, hb.settings.br_player_maximun, false) + if not hb.hba then + hb.register_hudbar("armor", 0xFFFFFF, S("Armor"), { bar = "hbarmor_bar.png", icon = aicon, bgicon = nil }, 0, 100, hbarmor.autohide, N("@1: @2%"), { order = { "label", "value" } } ) + end + if not hb.hbh then + hb.register_hudbar("satiation", 0xFFFFFF, S("Satiation"), { bar = "hbhunger_bar.png", icon = sicon, bgicon = nil }, hbhunger.SAT_INIT, hbhunger.SAT_MAX, false, nil, { format_value = "%02.0f", format_max_value = "%02.0f" }) + end end local function hide_builtin(player) @@ -530,27 +616,66 @@ local function hide_builtin(player) player:hud_set_flags(flags) end +if not hb.hba then + + function hbarmor.get_armor(player) + if not player or not armor.def then + return false + end + local name = player:get_player_name() + local def = armor.def[name] or nil + if def and def.state and def.count then + hbarmor.set_armor(name, def.state, def.count) + else + minetest.log("error", "[hudbars] Call to hbarmor.get_armor returned with false!") + return false + end + return true + end + + function hbarmor.set_armor(player_name, ges_state, items) + local max_items = 4 + if items == 5 then max_items = items end + local max = max_items * 65535 + local lvl = max - ges_state + lvl = lvl/max + if ges_state == 0 and items == 0 then lvl = 0 end + + hbarmor.armor[player_name] = math.max(0, math.min(lvl* (items * (100 / max_items)), 100)) + end + +end local function custom_hud(player) + local name = player:get_player_name() + if minetest.settings:get_bool("enable_damage") or hb.settings.forceload_default_hudbars then - local hide - if minetest.settings:get_bool("enable_damage") then - hide = false - else - hide = true - end + local hp = player:get_hp() local hp_max = hb.settings.hp_player_maximun - hb.init_hudbar(player, "health", math.min(hp, hp_max), hp_max, hide) + local hide_hp = not minetest.settings:get_bool("enable_damage") or true + if player:get_properties().hp_max then player:set_properties({hp_max = hb.settings.hp_player_maximun}) end + hb.init_hudbar(player, "health", math.min(hp, hp_max), hp_max, hide_hp) + local breath = player:get_breath() local breath_max = hb.settings.br_player_maximun local hide_breath - -- real honoring to configuration of max hp custom heal and breath from others mod - if player:get_properties().hp_max then player:set_properties({hp_max = hb.settings.hp_player_maximun}) end if player:get_properties().breath_max then player:set_properties({breath_max = hb.settings.br_player_maximun}) end - -- workaround bug https://github.com/minetest/minetest/issues/12350 if breath >= breath_max and hb.settings.autohide_breath == true then hide_breath = true else hide_breath = false end - hb.init_hudbar(player, "breath", math.min(breath, breath_max), breath_max, hide_breath or hide) + hb.init_hudbar(player, "breath", math.min(breath, breath_max), breath_max, hide_breath) + + if not hb.hba then + local arm = tonumber(hbarmor.armor[name]) + if not arm then arm = 0 end + local hide_ar = hbarmor.autohide and must_hide(name, arm) + hbarmor.get_armor(player) + arm = tonumber(hbarmor.armor[name]) + hb.init_hudbar(player, "armor", arm_printable(arm), 100, hide_ar) + end + + if not hb.hbh then + hb.init_hudbar(player, "satiation", hbhunger.get_hunger_raw(player), nil, (not hb.settings.forceload_default_hudbars) ) + end end end @@ -562,16 +687,18 @@ end -- update built-in HUD bars local function update_hud(player) - if not player_exists(player) then return end + + local name = player:get_player_name() -- player checks are already made before call this function + if not name then return end + + -- loading only if need or force loading if minetest.settings:get_bool("enable_damage") then if hb.settings.forceload_default_hudbars then hb.unhide_hudbar(player, "health") end --air local breath_max = player:get_properties().breath_max or hb.settings.br_player_maximun - -- workaround bug https://github.com/minetest/minetest/issues/12350 local breath = player:get_breath() - if breath >= breath_max and hb.settings.autohide_breath == true then hb.hide_hudbar(player, "breath") else @@ -580,10 +707,38 @@ local function update_hud(player) end --health update_health(player) + -- armor + if not hb.hba then + local larmor = hbarmor.armor[name] + local arm = tonumber(larmor) + if not arm then arm = 0; hbarmor.armor[name] = 0 end + if hbarmor.autohide then + if must_hide(name, arm) then + hb.hide_hudbar(player, "armor") + else + hb.change_hudbar(player, "armor", arm_printable(arm)) + hb.unhide_hudbar(player, "armor") + end + else + hb.change_hudbar(player, "armor", arm_printable(arm)) + hb.unhide_hudbar(player, "armor") + end + end + -- hunger + if not hb.hbh then + local h_out = tonumber(hbhunger.hunger_out[name]) + local h = tonumber(hbhunger.hunger[name]) + if h_out ~= h then + hbhunger.hunger_out[name] = h + hb.change_hudbar(player, "satiation", h) + end + end elseif hb.settings.forceload_default_hudbars then update_health(player) hb.hide_hudbar(player, "health") hb.hide_hudbar(player, "breath") + hb.hide_hudbar(player, "armor") + hb.hide_hudbar(player, "satiation") end end @@ -594,36 +749,122 @@ minetest.register_on_player_hpchange(function(player) end) minetest.register_on_respawnplayer(function(player) - if player_exists(player) then + if not player_exists(player) then return end + + local name = player:get_player_name() update_health(player) + if not hb.hbh then + hbhunger.hunger[name] = hbhunger.SAT_INIT + hbhunger.set_hunger_raw(player) + hbhunger.exhaustion[name] = 0 end hb.hide_hudbar(player, "breath") end) minetest.register_on_joinplayer(function(player) + if not player_exists(player) then return end + + local name = player:get_player_name() + local inv = player:get_inventory() + if not hb.hbh then + inv:set_size("hunger",1) + hbhunger.hunger[name] = hbhunger.get_hunger_raw(player) + hbhunger.hunger_out[name] = hbhunger.hunger[name] + hbhunger.exhaustion[name] = 0 + hbhunger.poisonings[name] = 0 + end hide_builtin(player) custom_hud(player) - hb.players[player:get_player_name()] = player + hb.players[name] = player + if not hb.hba then + hbarmor.player_active[name] = true + end + if not hb.hbh then + hbhunger.set_hunger_raw(player) + end end) minetest.register_on_leaveplayer(function(player) - hb.players[player:get_player_name()] = nil + if not player_exists(player) then return end + + local name = player:get_player_name() + hb.players[name] = nil + if not hb.hba then + hbarmor.player_active[name] = false + end end) +local modresult = "" + +if hb.hba then modresult = modresult .. " without build-in hbarmor" end +if hb.hbh then modresult = modresult .. " without build-in hbhunger" end + +minetest.log("[MOD] hudbars"..modresult.." loaded" ) + + local main_timer = 0 local timer = 0 +local timer2 = 0 minetest.register_globalstep(function(dtime) main_timer = main_timer + dtime timer = timer + dtime + timer2 = timer2 + dtime + -- main timer are for healt and breath, separate satiation cos needs aditional timers if main_timer > hb.settings.tick or timer > 4 then if main_timer > hb.settings.tick then main_timer = 0 end -- only proceed if damage is enabled if minetest.settings:get_bool("enable_damage") or hb.settings.forceload_default_hudbars then + -- update hud for healt for _, player in pairs(hb.players) do - -- update all hud elements update_hud(player) end + if not hb.hba then + -- update all hud elements + for _,player in ipairs(minetest.get_connected_players()) do + if player_exists(player) then + local name = player:get_player_name() + if hbarmor.player_active[name] == true then + hbarmor.get_armor(player) + update_hud(player) + end + end + end + end + end + end + if not hb.hbh then + -- satiaton are internal properties, so update live (not hb) player properties + if timer > 4 or timer2 > hbhunger.HUNGER_TICK then + for _,player in ipairs(minetest.get_connected_players()) do + if player_exists(player) then + local name = player:get_player_name() + local h = tonumber(hbhunger.hunger[name]) + local hp = player:get_hp() + if timer > 4 then + if h > hbhunger.SAT_HEAL and hp > 0 and player:get_breath() > 0 then + player:set_hp(hp+1) -- heal player by 1 hp if not dead and satiation is > hbhunger.SAT_HEAL + elseif h <= 1 then + if hp-1 >= 0 then player:set_hp(hp-1) end -- or damage player by 1 hp if satiation is < 2 + end + end + if timer2 > hbhunger.HUNGER_TICK then + if h > 0 then + h = h-1 -- lower satiation by 1 point after xx seconds + hbhunger.hunger[name] = h + hbhunger.set_hunger_raw(player) + end + end + -- still do not update all hud elements cos we have 2 loops + local controls = player:get_player_control() + if controls.up or controls.down or controls.left or controls.right then + hbhunger.handle_node_actions(nil, nil, player) -- Determine if the player is walking + end + end + end end end if timer > 4 then timer = 0 end + if timer2 > hbhunger.HUNGER_TICK then timer2 = 0 end end) + + diff --git a/locale/hudbars.de.tr b/locale/hudbars.de.tr index 3d1e697..2c4c0c1 100644 --- a/locale/hudbars.de.tr +++ b/locale/hudbars.de.tr @@ -2,3 +2,11 @@ Health=Leben Breath=Atem @1: @2/@3=@1: @2/@3 +Armor=Panzerung +@1: @2%=@1: @2% +Satiation=Sättigung +Set satiation of player or yourself=Sättigung von Spieler oder Ihnen selbst setzen +Not possible, damage is disabled.=Nicht möglich, Schaden ist deaktiviert. +Invalid satiation!=Ungültige Sättigung! +Player @1 does not exist.=Spieler @1 existiert nicht. +[] =[] diff --git a/locale/hudbars.es.tr b/locale/hudbars.es.tr index bbf0279..288d2e7 100644 --- a/locale/hudbars.es.tr +++ b/locale/hudbars.es.tr @@ -2,3 +2,10 @@ Health=Salud Breath=Aliento @1: @2/@3=@1: @2/@3 +Armor=Armado +@1: @2%=@1:@2% +Satiation=Saciado +Set satiation of player or yourself=Establece la saciedad en el jugador o en si mismo +Not possible, damage is disabled.=No es posible, daño esta desactivado. +Invalid satiation!=Satisfaccion invalida! +Player @1 does not exist.=El jugador @1 no existe. diff --git a/locale/hudbars.it.tr b/locale/hudbars.it.tr index 3ada5b6..c974141 100644 --- a/locale/hudbars.it.tr +++ b/locale/hudbars.it.tr @@ -1,6 +1,7 @@ # textdomain: hudbars Health=Salute Breath=Ossigeno - -# Default format string for progress bar-style HUD bars, e.g. “Health 5/20” @1: @2/@3=@1: @2/@3 +Armor=Armatura +@1: @2%=@1:@2% +Satiation=Sazietà diff --git a/locale/hudbars.ms.tr b/locale/hudbars.ms.tr index eb811ab..a0f4b5a 100644 --- a/locale/hudbars.ms.tr +++ b/locale/hudbars.ms.tr @@ -2,3 +2,4 @@ Health=Kesihatan Breath=Nafas @1: @2/@3=@1: @2/@3 +Satiation=Kekenyangan diff --git a/locale/hudbars.pt.tr b/locale/hudbars.pt.tr index a818f09..e57a8b2 100644 --- a/locale/hudbars.pt.tr +++ b/locale/hudbars.pt.tr @@ -1,6 +1,7 @@ # textdomain: hudbars Health=Saude Breath=Folego - -# Formato de string padrão para progresso bar-style de barras do HUD, por exemplo “Saude 5/20” @1: @2/@3=@1: @2/@3 +Armor=Armado +@1: @2%=@1: @2% +Satiation=Saciedade diff --git a/locale/hudbars.ru.tr b/locale/hudbars.ru.tr index 2d278e3..cc39433 100644 --- a/locale/hudbars.ru.tr +++ b/locale/hudbars.ru.tr @@ -1,4 +1,7 @@ # textdomain: hudbars -Health=HP +Health=Здоровье Breath=дыхание @1: @2/@3=@1: @2/@3 +Armor=Доспехи +@1: @2%=@1: @2% +Satiation=голод diff --git a/locale/template.txt b/locale/template.txt index 37b0559..253d574 100644 --- a/locale/template.txt +++ b/locale/template.txt @@ -1,6 +1,10 @@ # textdomain: hudbars Health= Breath= +Armor= -# Default format string for progress bar-style HUD bars, e.g. “Health 5/20” +# Default format string for progress bar-style HUD bars, e.g. “Health 05/20” @1: @2/@3= + +# Format string for displaying the armor. E.g. "Armor: 100%" +@1: @2%= diff --git a/mod.conf b/mod.conf index d6a0571..e07285d 100644 --- a/mod.conf +++ b/mod.conf @@ -1,2 +1,3 @@ name = hudbars -description = HUD mod to display as bars and API for +description = HUD mod to display as bars and API for with satiaton/stamina features and armor status +optional_depends = 3d_armor, default, flowers, animalmaterials, bucket, bushes, bushes_classic, cooking, creatures, docfarming, dwarves, ethereal, farming, farming_plus, ferns, fishing, fruit, glooptest, jkanimals, jkfarming, jkwine, kpgmobs, mobfcooking, mobs, moretrees, mtfoods, mush45, mushroom, seaplants, pizza, nssm diff --git a/screenshot.png b/screenshot.png index 88ee323..fcc1dd1 100644 Binary files a/screenshot.png and b/screenshot.png differ diff --git a/settingtypes.txt b/settingtypes.txt index 6ce1385..4a491ad 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -19,7 +19,7 @@ hudbars_bar_type (HUD bars style) enum progress_bar progress_bar,statbar_classic # If enabled (default), the breath indicators in the HUD will be automatically hidden shortly # after the breath has been filled up. Otherwise, the breath will always be displayed. -hudbars_autohide_breath (Automatically hide breath indicators) bool true +hudbars_autohide_breath (Automatically hide breath indicators) bool false # This setting changes the way the HUD bars are ordered on the display. You can choose # between a zig-zag pattern (default) or a vertically stacked pattern. @@ -120,8 +120,21 @@ hudbars_tick (Default HUD bars update interval) float 0.3 0.0 4.0 [player values defaults] # set a default value for max hp healt of player, if you customized and need on older engines -hudbars_hp_player_maximun (maximun value of heal of player) int 20 +hudbars_hp_player_maximun (maximun value of heal of player) int 40 # set a default value for max breath of player, if you customized and need on older engines -hudbars_br_player_maximun (maximun value of braeth of player) int 10 +hudbars_br_player_maximun (maximun value of braeth of player) int 20 +#If true, automatically hides the armor HUD bar when the player wears no +#armor. Otherwise, the armor bar shows “0%”. +hbarmor_autohide (Automatically hide armor HUD bar) bool false + +hbhunger_satiation_tick (Time in seconds after which 1 saturation point is taken) float 800 + +hbhunger_satiation_sprint_dig (exhaustion increased this value after digged node) float 3 + +hbhunger_satiation_sprint_place (exhaustion increased this value after placed) float 1 + +hbhunger_satiation_sprint_move (exhaustion increased this value if player movement detected) float 0.3 + +hbhunger_satiation_sprint_lvl (at what exhaustion player satiation gets lowerd) float 160 diff --git a/textures/hudbars_icon_breath.png b/textures/hudbars_icon_breath.png index 8f49fbd..810cac9 100644 Binary files a/textures/hudbars_icon_breath.png and b/textures/hudbars_icon_breath.png differ diff --git a/textures/hudbars_icon_health.png b/textures/hudbars_icon_health.png index f1c980f..d5302ec 100644 Binary files a/textures/hudbars_icon_health.png and b/textures/hudbars_icon_health.png differ