From 04bc5d9dc780ce5f69f5a51777ef95ad2bb73422 Mon Sep 17 00:00:00 2001 From: whosit Date: Wed, 31 Jan 2024 11:11:58 +0300 Subject: [PATCH] don't update object properties when not changed Avoid calling object:set_properties every second, because it generates AO_CMD_SET_PROPERTIES network packets without actual need. --- api.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/api.lua b/api.lua index e2da1f5..5efdf7b 100644 --- a/api.lua +++ b/api.lua @@ -655,6 +655,9 @@ function mob_class:update_tag(newname) local prop = self.object:get_properties() local qua = prop.hp_max / 6 + local old_nametag = prop.nametag + local old_nametag_color = minetest.colorspec_to_bytes(prop.nametag_color) + -- backwards compatibility if self.nametag and self.nametag ~= "" then newname = self.nametag @@ -680,7 +683,9 @@ function mob_class:update_tag(newname) col = "#00FF00" end - self.object:set_properties({nametag = self._nametag, nametag_color = col}) + if self._nametag ~= old_nametag or minetest.colorspec_to_bytes(col) ~= old_nametag_color then + self.object:set_properties({nametag = self._nametag, nametag_color = col}) + end end local text = "" @@ -709,7 +714,9 @@ function mob_class:update_tag(newname) .. text -- set infotext changes - self.object:set_properties({infotext = self.infotext}) + if self.infotext ~= prop.infotext then + self.object:set_properties({infotext = self.infotext}) + end end