mirror of
https://github.com/minetest-mods/gauges.git
synced 2024-12-23 01:10:23 +01:00
Fix entity creating crash and restore 0.4 support
This commit is contained in:
parent
1990169c0a
commit
9425b8dcf5
10
CHANGELOG.md
10
CHANGELOG.md
@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [1.0.2] - 2020-01-16
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix crash when creating an entity if a player leaves the server quickly.
|
||||
|
||||
### Changed
|
||||
|
||||
- Restore Minetest 0.4.17 support. The version check works only with `minetest_game` with the `player_api` mod added in Minetest 5.0.
|
||||
|
||||
## [1.0.1] - 2020-01-01
|
||||
|
||||
### Changed
|
||||
|
@ -60,7 +60,7 @@ on that line.
|
||||
|
||||
## Version compatibility
|
||||
|
||||
Gauges is currently primarily tested with Minetest 5.1.0. It may or may not work
|
||||
Gauges is currently primarily tested with Minetest 5.1.0 and 0.4.17. It may or may not work
|
||||
with newer or older versions. Issues arising in versions older than 5.0.0
|
||||
will generally not be fixed.
|
||||
|
||||
|
13
init.lua
13
init.lua
@ -21,12 +21,13 @@ minetest.register_entity("gauges:hp_bar", {
|
||||
|
||||
on_step = function(self)
|
||||
local player = self.wielder
|
||||
local gauge = self.object
|
||||
|
||||
if not player or
|
||||
not minetest.is_player(player) or
|
||||
vector_distance(player:get_pos(), self.object:get_pos()) > 3
|
||||
vector_distance(player:get_pos(), gauge:get_pos()) > 3
|
||||
then
|
||||
self.object:remove()
|
||||
gauge:remove()
|
||||
return
|
||||
end
|
||||
|
||||
@ -34,7 +35,7 @@ minetest.register_entity("gauges:hp_bar", {
|
||||
local breath = player:get_breath() <= 10 and player:get_breath() or 11
|
||||
|
||||
if self.hp ~= hp or self.breath ~= breath then
|
||||
self.object:set_properties({
|
||||
gauge:set_properties({
|
||||
textures = {
|
||||
"health_"..tostring(hp)..".png^"..
|
||||
"breath_"..tostring(breath)..".png"
|
||||
@ -47,11 +48,15 @@ minetest.register_entity("gauges:hp_bar", {
|
||||
})
|
||||
|
||||
local function add_gauge(player)
|
||||
if player and minetest.is_player(player) then
|
||||
local entity = minetest.add_entity(player:get_pos(), "gauges:hp_bar")
|
||||
-- check for minetest_game 0.4.*
|
||||
local height = minetest.get_modpath("player_api") and 19 or 9
|
||||
|
||||
entity:set_attach(player, "", {x=0, y=19, z=0}, {x=0, y=0, z=0})
|
||||
entity:set_attach(player, "", {x=0, y=height, z=0}, {x=0, y=0, z=0})
|
||||
entity:get_luaentity().wielder = player
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
minetest.after(1, add_gauge, player)
|
||||
|
Loading…
Reference in New Issue
Block a user