forked from mtcontrib/signs_lib
pass node information to sign update function, remove all entities on update incase of rogue
This commit is contained in:
parent
6995c3e768
commit
e57faeb8cf
76
init.lua
76
init.lua
@ -40,55 +40,33 @@ local wall_dir_change = {
|
||||
signs_lib.wallmounted_rotate = function(pos, node, user, mode)
|
||||
if mode ~= screwdriver.ROTATE_FACE then return false end
|
||||
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
|
||||
local e = v:get_luaentity()
|
||||
if e and e.name == "signs:text" then
|
||||
v:remove()
|
||||
end
|
||||
end
|
||||
signs_lib.update_sign(pos)
|
||||
signs_lib.update_sign(pos,nil,nil,node)
|
||||
return true
|
||||
end
|
||||
|
||||
signs_lib.facedir_rotate = function(pos, node, user, mode)
|
||||
if mode ~= screwdriver.ROTATE_FACE then return false end
|
||||
newparam2 = (node.param2 %8) + 1
|
||||
local newparam2 = (node.param2 %8) + 1
|
||||
if newparam2 == 5 then
|
||||
newparam2 = 6
|
||||
elseif newparam2 > 6 then
|
||||
newparam2 = 0
|
||||
end
|
||||
minetest.swap_node(pos, { name = node.name, param2 = newparam2 })
|
||||
for _, v in ipairs(minetest.get_objects_inside_radius(pos, 0.5)) do
|
||||
local e = v:get_luaentity()
|
||||
if e and e.name == "signs:text" then
|
||||
v:remove()
|
||||
end
|
||||
end
|
||||
signs_lib.update_sign(pos)
|
||||
signs_lib.update_sign(pos,nil,nil,node)
|
||||
return true
|
||||
end
|
||||
|
||||
signs_lib.facedir_rotate_simple = function(pos, node, user, mode)
|
||||
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
|
||||
minetest.swap_node(pos, { name = node.name, param2 = newparam2 })
|
||||
for _, v in ipairs(minetest.get_objects_inside_radius(pos, 0.5)) do
|
||||
local e = v:get_luaentity()
|
||||
if e and e.name == "signs:text" then
|
||||
v:remove()
|
||||
end
|
||||
end
|
||||
signs_lib.update_sign(pos)
|
||||
signs_lib.update_sign(pos,nil,nil,node)
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
signs_lib.modpath = minetest.get_modpath("signs_lib")
|
||||
|
||||
local DEFAULT_TEXT_SCALE = {x=0.8, y=0.5}
|
||||
@ -206,7 +184,7 @@ default_sign_metal_image = "default_sign_steel.png"
|
||||
--table copy
|
||||
|
||||
function signs_lib.table_copy(t)
|
||||
local nt = { };
|
||||
local nt = { }
|
||||
for k, v in pairs(t) do
|
||||
if type(v) == "table" then
|
||||
nt[k] = signs_lib.table_copy(v)
|
||||
@ -542,7 +520,7 @@ local function make_infotext(text)
|
||||
return table.concat(lines2, "\n")
|
||||
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,
|
||||
-- or has been changed since the last restart...
|
||||
@ -586,28 +564,14 @@ signs_lib.update_sign = function(pos, fields, owner)
|
||||
else
|
||||
new = (meta:get_int("__signslib_new_format") ~= 0)
|
||||
end
|
||||
signs_lib.destruct_sign(pos)
|
||||
local text = meta:get_string("text")
|
||||
if text == nil then return end
|
||||
local objects = minetest.get_objects_inside_radius(pos, 0.5)
|
||||
local found
|
||||
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 text == nil or text == "" then return end
|
||||
|
||||
if node then print ("---", node.name, node.param2) end
|
||||
|
||||
-- if there is no entity
|
||||
local sign_info
|
||||
local signnode = minetest.get_node(pos)
|
||||
local signnode = node or minetest.get_node(pos)
|
||||
local signname = signnode.name
|
||||
local textpos = minetest.registered_nodes[signname].textpos
|
||||
if textpos then
|
||||
@ -764,7 +728,7 @@ minetest.register_node(":"..default_sign, {
|
||||
signs_lib.receive_fields(pos, formname, fields, sender)
|
||||
end,
|
||||
on_punch = function(pos, node, puncher)
|
||||
signs_lib.update_sign(pos)
|
||||
signs_lib.update_sign(pos,nil,nil,node)
|
||||
end,
|
||||
on_rotate = signs_lib.wallmounted_rotate
|
||||
})
|
||||
@ -793,7 +757,7 @@ minetest.register_node(":signs:sign_yard", {
|
||||
signs_lib.receive_fields(pos, formname, fields, sender)
|
||||
end,
|
||||
on_punch = function(pos, node, puncher)
|
||||
signs_lib.update_sign(pos)
|
||||
signs_lib.update_sign(pos,nil,nil,node)
|
||||
end,
|
||||
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)
|
||||
end,
|
||||
on_punch = function(pos, node, puncher)
|
||||
signs_lib.update_sign(pos)
|
||||
signs_lib.update_sign(pos,nil,nil,node)
|
||||
end,
|
||||
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)
|
||||
end,
|
||||
on_punch = function(pos, node, puncher)
|
||||
signs_lib.update_sign(pos)
|
||||
signs_lib.update_sign(pos,nil,nil,node)
|
||||
end,
|
||||
can_dig = function(pos, player)
|
||||
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)
|
||||
end,
|
||||
on_punch = function(pos, node, puncher)
|
||||
signs_lib.update_sign(pos)
|
||||
signs_lib.update_sign(pos,nil,nil,node)
|
||||
end,
|
||||
on_rotate = signs_lib.wallmounted_rotate
|
||||
})
|
||||
@ -991,7 +955,7 @@ if enable_colored_metal_signs then
|
||||
signs_lib.receive_fields(pos, formname, fields, sender)
|
||||
end,
|
||||
on_punch = function(pos, node, puncher)
|
||||
signs_lib.update_sign(pos)
|
||||
signs_lib.update_sign(pos,nil,nil,node)
|
||||
end,
|
||||
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)
|
||||
end
|
||||
def_sign.on_punch = function(pos, node, puncher, ...)
|
||||
signs_lib.update_sign(pos)
|
||||
signs_lib.update_sign(pos,nil,nil,node)
|
||||
end
|
||||
local fencename = fencename
|
||||
def_sign.after_dig_node = function(pos, node, ...)
|
||||
@ -1109,7 +1073,7 @@ minetest.register_lbm({
|
||||
label = "Restore sign text",
|
||||
run_at_every_load = true,
|
||||
action = function(pos, node)
|
||||
signs_lib.update_sign(pos)
|
||||
signs_lib.update_sign(pos,nil,nil,node)
|
||||
end
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user