1
0
mirror of https://github.com/mt-mods/signs_lib.git synced 2024-12-24 16:20:17 +01:00

attempt to work around engine player model bug

when the world loads and the player spawns in, or is
teleported to the same node space as a sign, occasionally, the
player's model goes flat and their skin gets changed to the
whatever the sign's text is.

Also, when checking if an entity needs spawned, or when
deleting, try to make absolutely sure that only sign-related
entities will be selected for re-use, or selected for deletion
(we don't want some player's prize cow to be deleted)

I think this will fix it, or at least it'll surely prevent
signs_lib from being able to cause it.

Also, moved another function to the entity-handling section of
the file and made it global (signs_lib namespace) in the
process.
This commit is contained in:
Vanessa Dannenberg 2019-09-25 15:31:56 -04:00
parent 1e05aa9309
commit 6a4ddfddab

40
api.lua
View File

@ -168,7 +168,12 @@ minetest.register_entity("signs_lib:text", {
function signs_lib.delete_objects(pos)
local objects = minetest.get_objects_inside_radius(pos, 0.5)
for _, v in ipairs(objects) do
v:remove()
if v then
local e = v:get_luaentity()
if e and string.match(e.name, "sign.*text") then
v:remove()
end
end
end
end
@ -182,8 +187,17 @@ function signs_lib.spawn_entity(pos, texture)
local obj
if #objects > 0 then
obj = objects[1]
else
for _, v in ipairs(objects) do
if v then
local e = v:get_luaentity()
if e and e.name == "signs_lib:text" then
obj = v
end
end
end
end
if not obj then
obj = minetest.add_entity(pos, "signs_lib:text")
end
@ -230,6 +244,14 @@ function signs_lib.spawn_entity(pos, texture)
end
end
function signs_lib.set_obj_text(pos, text)
local split = signs_lib.split_lines_and_words
local text_ansi = Utf8ToAnsi(text)
local n = minetest.registered_nodes[minetest.get_node(pos).name]
signs_lib.delete_objects(pos)
signs_lib.spawn_entity(pos, signs_lib.make_sign_texture(split(text_ansi), pos) )
end
-- rotation
function signs_lib.handle_rotation(pos, node, user, mode)
@ -288,7 +310,6 @@ function signs_lib.handle_rotation(pos, node, user, mode)
minetest.swap_node(tpos, { name = node.name, param2 = signs_lib.rotate_facedir[node.param2] or 0 })
end
signs_lib.delete_objects(tpos)
signs_lib.update_sign(tpos)
return true
end
@ -544,7 +565,7 @@ local function make_line_texture(line, lineno, pos, line_width, line_height, cwi
return table.concat(texture), lineno
end
local function make_sign_texture(lines, pos)
function signs_lib.make_sign_texture(lines, pos)
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
@ -598,14 +619,6 @@ function signs_lib.split_lines_and_words(text)
return lines
end
function signs_lib.set_obj_text(pos, text)
local split = signs_lib.split_lines_and_words
local text_ansi = Utf8ToAnsi(text)
local n = minetest.registered_nodes[minetest.get_node(pos).name]
signs_lib.delete_objects(pos)
signs_lib.spawn_entity(pos, make_sign_texture(split(text_ansi), pos))
end
function signs_lib.construct_sign(pos)
local form = "size[6,4]"..
"textarea[0,-0.3;6.5,3;text;;${text}]"..
@ -1045,7 +1058,6 @@ minetest.register_lbm({
minetest.swap_node(pos, {name = basename, param2 = node.param2})
local meta = minetest.get_meta(pos)
meta:set_int("widefont", 1)
signs_lib.delete_objects(pos)
signs_lib.update_sign(pos)
end
})