5 Commits

Author SHA1 Message Date
0341fe1ef9 Merge branch 'github' 2021-11-09 23:52:28 +01:00
b6cfb91717 Fix crash on math.round field as nil 2021-11-09 23:43:55 +01:00
b7051168f1 Merge remote-tracking branch 'upstream/master' 2021-11-06 09:18:25 +01:00
7c916f93a0 Update changelog with recent additions 2021-11-02 00:31:29 +01:00
b08db516d5 Don't lose hp_bar when teleporting
If a player teleports far away, their hp_bar can become deactivated and disappear. The mod installs the gauge only when a player joins, so it will be forever missing. `static_save = false` prevents the item from deactivating https://github.com/minetest/minetest/blob/master/src/serverenvironment.cpp#L2028 .
Also, it doesn't make sense to save `gauges:hp_bar` to map meta since it's not a standalone item.
2021-11-02 00:20:07 +01:00
2 changed files with 15 additions and 1 deletions

View File

@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
### Changed
- [Health and breath bars now adapt to custom maximum values instead of being hardcoded to 20 and 11 respectively.](https://github.com/minetest-mods/gauges/pull/9)
### Fixed
- [The health bar entity is no longer lost when a player teleports.](https://github.com/minetest-mods/gauges/pull/10)
- A side effect is that health bar entities are no longer saved in map metadata.
## [1.0.4] - 2020-09-27
### Added

View File

@ -3,6 +3,10 @@
-- Copyright © 2014-2020 4aiman, Hugo Locurcio and contributors - MIT License
-- See `LICENSE.md` included in the source distribution for details.
local function round(v)
return math.floor(v + 0.5)
end
local enabled = minetest.settings:get_bool("health_bars") ~= false
if enabled then
enabled = minetest.settings:get_bool("enable_damage")
@ -36,7 +40,7 @@ local function scaleToDefault(player, field)
-- Scale "hp" or "breath" to supported amount
local current = player["get_" .. field](player)
local max_display = math.max(player:get_properties()[field .. "_max"], current)
return math.round(current / max_display * max[field])
return round(current / max_display * max[field])
end
minetest.register_entity("gauges:hp_bar", {
@ -45,6 +49,7 @@ minetest.register_entity("gauges:hp_bar", {
textures = {"blank.png"},
collisionbox = {0},
physical = false,
static_save = false,
on_step = function(self)
local player = self.wielder