From 9425b8dcf5910d61dbbfd295338015c57c17a215 Mon Sep 17 00:00:00 2001 From: Maksim Date: Thu, 16 Jan 2020 10:53:37 +0100 Subject: [PATCH] Fix entity creating crash and restore 0.4 support --- CHANGELOG.md | 10 ++++++++++ README.md | 2 +- init.lua | 17 +++++++++++------ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6b46da..c7fc5dd 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/README.md b/README.md index 89e326f..ff9e1cb 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/init.lua b/init.lua index 98c76d6..22fede5 100644 --- a/init.lua +++ b/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,10 +48,14 @@ minetest.register_entity("gauges:hp_bar", { }) local function add_gauge(player) - local entity = minetest.add_entity(player:get_pos(), "gauges:hp_bar") + 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:get_luaentity().wielder = player + 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)