forked from mtcontrib/signs_lib
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:
parent
1e05aa9309
commit
6a4ddfddab
38
api.lua
38
api.lua
@ -168,9 +168,14 @@ minetest.register_entity("signs_lib:text", {
|
|||||||
function signs_lib.delete_objects(pos)
|
function signs_lib.delete_objects(pos)
|
||||||
local objects = minetest.get_objects_inside_radius(pos, 0.5)
|
local objects = minetest.get_objects_inside_radius(pos, 0.5)
|
||||||
for _, v in ipairs(objects) do
|
for _, v in ipairs(objects) do
|
||||||
|
if v then
|
||||||
|
local e = v:get_luaentity()
|
||||||
|
if e and string.match(e.name, "sign.*text") then
|
||||||
v:remove()
|
v:remove()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function signs_lib.spawn_entity(pos, texture)
|
function signs_lib.spawn_entity(pos, texture)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
@ -182,8 +187,17 @@ function signs_lib.spawn_entity(pos, texture)
|
|||||||
local obj
|
local obj
|
||||||
|
|
||||||
if #objects > 0 then
|
if #objects > 0 then
|
||||||
obj = objects[1]
|
for _, v in ipairs(objects) do
|
||||||
else
|
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")
|
obj = minetest.add_entity(pos, "signs_lib:text")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -230,6 +244,14 @@ function signs_lib.spawn_entity(pos, texture)
|
|||||||
end
|
end
|
||||||
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
|
-- rotation
|
||||||
|
|
||||||
function signs_lib.handle_rotation(pos, node, user, mode)
|
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 })
|
minetest.swap_node(tpos, { name = node.name, param2 = signs_lib.rotate_facedir[node.param2] or 0 })
|
||||||
end
|
end
|
||||||
|
|
||||||
signs_lib.delete_objects(tpos)
|
|
||||||
signs_lib.update_sign(tpos)
|
signs_lib.update_sign(tpos)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -544,7 +565,7 @@ local function make_line_texture(line, lineno, pos, line_width, line_height, cwi
|
|||||||
return table.concat(texture), lineno
|
return table.concat(texture), lineno
|
||||||
end
|
end
|
||||||
|
|
||||||
local function make_sign_texture(lines, pos)
|
function signs_lib.make_sign_texture(lines, pos)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
|
||||||
@ -598,14 +619,6 @@ function signs_lib.split_lines_and_words(text)
|
|||||||
return lines
|
return lines
|
||||||
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, make_sign_texture(split(text_ansi), pos))
|
|
||||||
end
|
|
||||||
|
|
||||||
function signs_lib.construct_sign(pos)
|
function signs_lib.construct_sign(pos)
|
||||||
local form = "size[6,4]"..
|
local form = "size[6,4]"..
|
||||||
"textarea[0,-0.3;6.5,3;text;;${text}]"..
|
"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})
|
minetest.swap_node(pos, {name = basename, param2 = node.param2})
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_int("widefont", 1)
|
meta:set_int("widefont", 1)
|
||||||
signs_lib.delete_objects(pos)
|
|
||||||
signs_lib.update_sign(pos)
|
signs_lib.update_sign(pos)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user