1
0
mirror of https://github.com/mt-mods/signs_lib.git synced 2024-12-25 00:30:18 +01:00

Merge branch 'patch-1' into 'master'

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

See merge request VanessaE/signs_lib!1
This commit is contained in:
Vanessa Dannenberg 2018-09-26 19:21:22 +00:00
commit fac33e369f

217
init.lua
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,15 +184,15 @@ 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)
else else
nt[k] = v nt[k] = v
end end
end end
return nt return nt
end end
-- infinite stacks -- infinite stacks
@ -512,7 +490,7 @@ local function set_obj_text(obj, text, new, pos)
end end
signs_lib.construct_sign = function(pos, locked) signs_lib.construct_sign = function(pos, locked)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string( meta:set_string(
"formspec", "formspec",
"size[6,4]".. "size[6,4]"..
@ -523,13 +501,13 @@ signs_lib.construct_sign = function(pos, locked)
end end
signs_lib.destruct_sign = function(pos) signs_lib.destruct_sign = function(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
local e = v:get_luaentity() local e = v:get_luaentity()
if e and e.name == "signs:text" then if e and e.name == "signs:text" then
v:remove() v:remove()
end end
end end
end end
local function make_infotext(text) local function make_infotext(text)
@ -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,11 @@ 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
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,52 +725,52 @@ 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
}) })
minetest.register_node(":signs:sign_yard", { minetest.register_node(":signs:sign_yard", {
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
paramtype2 = "facedir", paramtype2 = "facedir",
drawtype = "nodebox", drawtype = "nodebox",
node_box = signs_lib.yard_sign_model.nodebox, node_box = signs_lib.yard_sign_model.nodebox,
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = {-0.4375, -0.5, -0.0625, 0.4375, 0.375, 0} fixed = {-0.4375, -0.5, -0.0625, 0.4375, 0.375, 0}
}, },
tiles = {"signs_top.png", "signs_bottom.png", "signs_side.png", "signs_side.png", "signs_back.png", "signs_front.png"}, tiles = {"signs_top.png", "signs_bottom.png", "signs_side.png", "signs_side.png", "signs_back.png", "signs_front.png"},
groups = {choppy=2, dig_immediate=2}, groups = {choppy=2, dig_immediate=2},
drop = default_sign, drop = default_sign,
on_construct = function(pos) on_construct = function(pos)
signs_lib.construct_sign(pos) signs_lib.construct_sign(pos)
end, end,
on_destruct = function(pos) on_destruct = function(pos)
signs_lib.destruct_sign(pos) signs_lib.destruct_sign(pos)
end, end,
on_receive_fields = function(pos, formname, fields, sender) on_receive_fields = function(pos, formname, fields, sender)
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
}) })
minetest.register_node(":signs:sign_hanging", { minetest.register_node(":signs:sign_hanging", {
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
paramtype2 = "facedir", paramtype2 = "facedir",
drawtype = "nodebox", drawtype = "nodebox",
node_box = signs_lib.hanging_sign_model.nodebox, node_box = signs_lib.hanging_sign_model.nodebox,
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = {-0.45, -0.275, -0.049, 0.45, 0.5, 0.049} fixed = {-0.45, -0.275, -0.049, 0.45, 0.5, 0.049}
}, },
tiles = { tiles = {
"signs_hanging_top.png", "signs_hanging_top.png",
"signs_hanging_bottom.png", "signs_hanging_bottom.png",
"signs_hanging_side.png", "signs_hanging_side.png",
@ -817,31 +778,31 @@ minetest.register_node(":signs:sign_hanging", {
"signs_hanging_back.png", "signs_hanging_back.png",
"signs_hanging_front.png" "signs_hanging_front.png"
}, },
groups = {choppy=2, dig_immediate=2}, groups = {choppy=2, dig_immediate=2},
drop = default_sign, drop = default_sign,
on_construct = function(pos) on_construct = function(pos)
signs_lib.construct_sign(pos) signs_lib.construct_sign(pos)
end, end,
on_destruct = function(pos) on_destruct = function(pos)
signs_lib.destruct_sign(pos) signs_lib.destruct_sign(pos)
end, end,
on_receive_fields = function(pos, formname, fields, sender) on_receive_fields = function(pos, formname, fields, sender)
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
}) })
minetest.register_node(":signs:sign_post", { minetest.register_node(":signs:sign_post", {
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
paramtype2 = "facedir", paramtype2 = "facedir",
drawtype = "nodebox", drawtype = "nodebox",
node_box = signs_lib.sign_post_model.nodebox, node_box = signs_lib.sign_post_model.nodebox,
tiles = { tiles = {
"signs_post_top.png", "signs_post_top.png",
"signs_post_bottom.png", "signs_post_bottom.png",
"signs_post_side.png", "signs_post_side.png",
@ -849,14 +810,14 @@ minetest.register_node(":signs:sign_post", {
"signs_post_back.png", "signs_post_back.png",
"signs_post_front.png", "signs_post_front.png",
}, },
groups = {choppy=2, dig_immediate=2}, groups = {choppy=2, dig_immediate=2},
drop = { drop = {
max_items = 2, max_items = 2,
items = { items = {
{ items = { default_sign }}, { items = { default_sign }},
{ items = { "default:fence_wood" }}, { items = { "default:fence_wood" }},
}, },
}, },
on_rotate = signs_lib.facedir_rotate_simple on_rotate = signs_lib.facedir_rotate_simple
}) })
@ -896,7 +857,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 +898,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 +952,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
}) })
@ -1012,9 +973,9 @@ signs_text_on_activate = function(self)
end end
minetest.register_entity(":signs:text", { minetest.register_entity(":signs:text", {
collisionbox = { 0, 0, 0, 0, 0, 0 }, collisionbox = { 0, 0, 0, 0, 0, 0 },
visual = "upright_sprite", visual = "upright_sprite",
textures = {}, textures = {},
on_activate = signs_text_on_activate, on_activate = signs_text_on_activate,
}) })
@ -1022,17 +983,17 @@ minetest.register_entity(":signs:text", {
-- And the good stuff here! :-) -- And the good stuff here! :-)
function signs_lib.register_fence_with_sign(fencename, fencewithsignname) function signs_lib.register_fence_with_sign(fencename, fencewithsignname)
local def = minetest.registered_nodes[fencename] local def = minetest.registered_nodes[fencename]
local def_sign = minetest.registered_nodes[fencewithsignname] local def_sign = minetest.registered_nodes[fencewithsignname]
if not (def and def_sign) then if not (def and def_sign) then
minetest.log("warning", "[signs_lib] "..S("Attempt to register unknown node as fence")) minetest.log("warning", "[signs_lib] "..S("Attempt to register unknown node as fence"))
return return
end end
def = signs_lib.table_copy(def) def = signs_lib.table_copy(def)
def_sign = signs_lib.table_copy(def_sign) def_sign = signs_lib.table_copy(def_sign)
fences_with_sign[fencename] = fencewithsignname fences_with_sign[fencename] = fencewithsignname
def_sign.on_place = function(itemstack, placer, pointed_thing, ...) def_sign.on_place = function(itemstack, placer, pointed_thing, ...)
local node_above = minetest.get_node_or_nil(pointed_thing.above) local node_above = minetest.get_node_or_nil(pointed_thing.above)
local node_under = minetest.get_node_or_nil(pointed_thing.under) local node_under = minetest.get_node_or_nil(pointed_thing.under)
local def_above = node_above and minetest.registered_nodes[node_above.name] local def_above = node_above and minetest.registered_nodes[node_above.name]
@ -1077,16 +1038,16 @@ 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, ...)
node.name = fencename node.name = fencename
minetest.add_node(pos, node) minetest.add_node(pos, node)
end end
def_sign.on_rotate = signs_lib.facedir_rotate_simple def_sign.on_rotate = signs_lib.facedir_rotate_simple
def_sign.drop = default_sign def_sign.drop = default_sign
minetest.register_node(":"..fencename, def) minetest.register_node(":"..fencename, def)
minetest.register_node(":"..fencewithsignname, def_sign) minetest.register_node(":"..fencewithsignname, def_sign)
table.insert(signs_lib.sign_node_list, fencewithsignname) table.insert(signs_lib.sign_node_list, fencewithsignname)
@ -1109,18 +1070,18 @@ 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
}) })
-- locked sign -- locked sign
minetest.register_craft({ minetest.register_craft({
output = "locked_sign:sign_wall_locked", output = "locked_sign:sign_wall_locked",
recipe = { recipe = {
{default_sign}, {default_sign},
{"default:steel_ingot"}, {"default:steel_ingot"},
}, },
}) })
-- craft recipes for the metal signs -- craft recipes for the metal signs