pass node information to sign update function, remove all entities on update incase of rogue

This commit is contained in:
tenplus1 2018-09-26 12:13:34 +00:00
parent 6995c3e768
commit e57faeb8cf

View File

@ -40,55 +40,33 @@ local wall_dir_change = {
signs_lib.wallmounted_rotate = function(pos, node, user, mode) signs_lib.wallmounted_rotate = function(pos, node, user, mode)
if mode ~= screwdriver.ROTATE_FACE then return false end if mode ~= screwdriver.ROTATE_FACE then return false end
minetest.swap_node(pos, { name = node.name, param2 = wall_dir_change[node.param2 % 6] }) minetest.swap_node(pos, { name = node.name, param2 = wall_dir_change[node.param2 % 6] })
for _, v in ipairs(minetest.get_objects_inside_radius(pos, 0.5)) do signs_lib.update_sign(pos,nil,nil,node)
local e = v:get_luaentity()
if e and e.name == "signs:text" then
v:remove()
end
end
signs_lib.update_sign(pos)
return true return true
end end
signs_lib.facedir_rotate = function(pos, node, user, mode) signs_lib.facedir_rotate = function(pos, node, user, mode)
if mode ~= screwdriver.ROTATE_FACE then return false end if mode ~= screwdriver.ROTATE_FACE then return false end
newparam2 = (node.param2 %8) + 1 local newparam2 = (node.param2 %8) + 1
if newparam2 == 5 then if newparam2 == 5 then
newparam2 = 6 newparam2 = 6
elseif newparam2 > 6 then elseif newparam2 > 6 then
newparam2 = 0 newparam2 = 0
end end
minetest.swap_node(pos, { name = node.name, param2 = newparam2 }) minetest.swap_node(pos, { name = node.name, param2 = newparam2 })
for _, v in ipairs(minetest.get_objects_inside_radius(pos, 0.5)) do signs_lib.update_sign(pos,nil,nil,node)
local e = v:get_luaentity()
if e and e.name == "signs:text" then
v:remove()
end
end
signs_lib.update_sign(pos)
return true return true
end end
signs_lib.facedir_rotate_simple = function(pos, node, user, mode) signs_lib.facedir_rotate_simple = function(pos, node, user, mode)
if mode ~= screwdriver.ROTATE_FACE then return false end if mode ~= screwdriver.ROTATE_FACE then return false end
newparam2 = (node.param2 %8) + 1 local newparam2 = (node.param2 %8) + 1
if newparam2 > 3 then newparam2 = 0 end if newparam2 > 3 then newparam2 = 0 end
minetest.swap_node(pos, { name = node.name, param2 = newparam2 }) minetest.swap_node(pos, { name = node.name, param2 = newparam2 })
for _, v in ipairs(minetest.get_objects_inside_radius(pos, 0.5)) do signs_lib.update_sign(pos,nil,nil,node)
local e = v:get_luaentity()
if e and e.name == "signs:text" then
v:remove()
end
end
signs_lib.update_sign(pos)
return true return true
end end
signs_lib.modpath = minetest.get_modpath("signs_lib") signs_lib.modpath = minetest.get_modpath("signs_lib")
local DEFAULT_TEXT_SCALE = {x=0.8, y=0.5} local DEFAULT_TEXT_SCALE = {x=0.8, y=0.5}
@ -206,7 +184,7 @@ default_sign_metal_image = "default_sign_steel.png"
--table copy --table copy
function signs_lib.table_copy(t) function signs_lib.table_copy(t)
local nt = { }; local nt = { }
for k, v in pairs(t) do for k, v in pairs(t) do
if type(v) == "table" then if type(v) == "table" then
nt[k] = signs_lib.table_copy(v) nt[k] = signs_lib.table_copy(v)
@ -542,7 +520,7 @@ local function make_infotext(text)
return table.concat(lines2, "\n") return table.concat(lines2, "\n")
end end
signs_lib.update_sign = function(pos, fields, owner) signs_lib.update_sign = function(pos, fields, owner, node)
-- First, check if the interact keyword from CWz's mod is being set, -- First, check if the interact keyword from CWz's mod is being set,
-- or has been changed since the last restart... -- or has been changed since the last restart...
@ -586,28 +564,14 @@ signs_lib.update_sign = function(pos, fields, owner)
else else
new = (meta:get_int("__signslib_new_format") ~= 0) new = (meta:get_int("__signslib_new_format") ~= 0)
end end
signs_lib.destruct_sign(pos)
local text = meta:get_string("text") local text = meta:get_string("text")
if text == nil then return end if text == nil or text == "" then return end
local objects = minetest.get_objects_inside_radius(pos, 0.5)
local found if node then print ("---", node.name, node.param2) end
for _, v in ipairs(objects) do
local e = v:get_luaentity()
if e and e.name == "signs:text" then
if found then
v:remove()
else
set_obj_text(v, text, new, pos)
found = true
end
end
end
if found then
return
end
-- if there is no entity
local sign_info local sign_info
local signnode = minetest.get_node(pos) local signnode = node or minetest.get_node(pos)
local signname = signnode.name local signname = signnode.name
local textpos = minetest.registered_nodes[signname].textpos local textpos = minetest.registered_nodes[signname].textpos
if textpos then if textpos then
@ -764,7 +728,7 @@ minetest.register_node(":"..default_sign, {
signs_lib.receive_fields(pos, formname, fields, sender) signs_lib.receive_fields(pos, formname, fields, sender)
end, end,
on_punch = function(pos, node, puncher) on_punch = function(pos, node, puncher)
signs_lib.update_sign(pos) signs_lib.update_sign(pos,nil,nil,node)
end, end,
on_rotate = signs_lib.wallmounted_rotate on_rotate = signs_lib.wallmounted_rotate
}) })
@ -793,7 +757,7 @@ minetest.register_node(":signs:sign_yard", {
signs_lib.receive_fields(pos, formname, fields, sender) signs_lib.receive_fields(pos, formname, fields, sender)
end, end,
on_punch = function(pos, node, puncher) on_punch = function(pos, node, puncher)
signs_lib.update_sign(pos) signs_lib.update_sign(pos,nil,nil,node)
end, end,
on_rotate = signs_lib.facedir_rotate_simple on_rotate = signs_lib.facedir_rotate_simple
@ -830,7 +794,7 @@ minetest.register_node(":signs:sign_hanging", {
signs_lib.receive_fields(pos, formname, fields, sender) signs_lib.receive_fields(pos, formname, fields, sender)
end, end,
on_punch = function(pos, node, puncher) on_punch = function(pos, node, puncher)
signs_lib.update_sign(pos) signs_lib.update_sign(pos,nil,nil,node)
end, end,
on_rotate = signs_lib.facedir_rotate_simple on_rotate = signs_lib.facedir_rotate_simple
}) })
@ -896,7 +860,7 @@ minetest.register_node(":locked_sign:sign_wall_locked", {
signs_lib.receive_fields(pos, formname, fields, sender, true) signs_lib.receive_fields(pos, formname, fields, sender, true)
end, end,
on_punch = function(pos, node, puncher) on_punch = function(pos, node, puncher)
signs_lib.update_sign(pos) signs_lib.update_sign(pos,nil,nil,node)
end, end,
can_dig = function(pos, player) can_dig = function(pos, player)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
@ -937,7 +901,7 @@ if minetest.registered_nodes["default:sign_wall_steel"] then
signs_lib.receive_fields(pos, formname, fields, sender) signs_lib.receive_fields(pos, formname, fields, sender)
end, end,
on_punch = function(pos, node, puncher) on_punch = function(pos, node, puncher)
signs_lib.update_sign(pos) signs_lib.update_sign(pos,nil,nil,node)
end, end,
on_rotate = signs_lib.wallmounted_rotate on_rotate = signs_lib.wallmounted_rotate
}) })
@ -991,7 +955,7 @@ if enable_colored_metal_signs then
signs_lib.receive_fields(pos, formname, fields, sender) signs_lib.receive_fields(pos, formname, fields, sender)
end, end,
on_punch = function(pos, node, puncher) on_punch = function(pos, node, puncher)
signs_lib.update_sign(pos) signs_lib.update_sign(pos,nil,nil,node)
end, end,
on_rotate = signs_lib.facedir_rotate on_rotate = signs_lib.facedir_rotate
}) })
@ -1077,7 +1041,7 @@ function signs_lib.register_fence_with_sign(fencename, fencewithsignname)
signs_lib.receive_fields(pos, formname, fields, sender) signs_lib.receive_fields(pos, formname, fields, sender)
end end
def_sign.on_punch = function(pos, node, puncher, ...) def_sign.on_punch = function(pos, node, puncher, ...)
signs_lib.update_sign(pos) signs_lib.update_sign(pos,nil,nil,node)
end end
local fencename = fencename local fencename = fencename
def_sign.after_dig_node = function(pos, node, ...) def_sign.after_dig_node = function(pos, node, ...)
@ -1109,7 +1073,7 @@ minetest.register_lbm({
label = "Restore sign text", label = "Restore sign text",
run_at_every_load = true, run_at_every_load = true,
action = function(pos, node) action = function(pos, node)
signs_lib.update_sign(pos) signs_lib.update_sign(pos,nil,nil,node)
end end
}) })