1 -- This mod provides the visible text on signs library used by Home Decor
2 -- and perhaps other mods at some point in the future. Forked from thexyz's/
3 -- PilzAdam's original text-on-signs mod and rewritten by Vanessa Ezekowitz
7 -- { delta = {entity position for 0° yaw}, exact yaw expression }
8 -- { delta = {entity position for 180° yaw}, exact yaw expression }
9 -- { delta = {entity position for 270° yaw}, exact yaw expression }
10 -- { delta = {entity position for 90° yaw}, exact yaw expression }
12 -- Made colored metal signs optionals
13 local enable_colored_metal_signs = true
15 -- CWz's keyword interact mod uses this setting.
16 local current_keyword = minetest.settings:get("interact_keyword") or "iaccept"
19 screwdriver = screwdriver or {}
21 signs_lib.wallmounted_rotate = function(pos, node, user, mode, new_param2)
22 if mode ~= screwdriver.ROTATE_AXIS then return false end
23 minetest.swap_node(pos, {name = node.name, param2 = (node.param2 + 1) % 6})
24 for _, v in ipairs(minetest.get_objects_inside_radius(pos, 0.5)) do
25 local e = v:get_luaentity()
26 if e and e.name == "signs:text" then
30 signs_lib.update_sign(pos)
34 signs_lib.modpath = minetest.get_modpath("signs_lib")
36 local DEFAULT_TEXT_SCALE = {x=0.8, y=0.5}
38 signs_lib.regular_wall_sign_model = {
41 wall_side = { -0.5, -0.25, -0.4375, -0.4375, 0.375, 0.4375 },
42 wall_bottom = { -0.4375, -0.5, -0.25, 0.4375, -0.4375, 0.375 },
43 wall_top = { -0.4375, 0.4375, -0.375, 0.4375, 0.5, 0.25 }
48 {delta = { x = 0.41, y = 0.07, z = 0 }, yaw = math.pi / -2},
49 {delta = { x = -0.41, y = 0.07, z = 0 }, yaw = math.pi / 2},
50 {delta = { x = 0, y = 0.07, z = 0.41 }, yaw = 0},
51 {delta = { x = 0, y = 0.07, z = -0.41 }, yaw = math.pi},
55 signs_lib.metal_wall_sign_model = {
58 fixed = {-0.4375, -0.25, 0.4375, 0.4375, 0.375, 0.5}
61 {delta = { x = 0, y = 0.07, z = 0.41 }, yaw = 0},
62 {delta = { x = 0.41, y = 0.07, z = 0 }, yaw = math.pi / -2},
63 {delta = { x = 0, y = 0.07, z = -0.41 }, yaw = math.pi},
64 {delta = { x = -0.41, y = 0.07, z = 0 }, yaw = math.pi / 2},
68 signs_lib.yard_sign_model = {
72 {-0.4375, -0.25, -0.0625, 0.4375, 0.375, 0},
73 {-0.0625, -0.5, -0.0625, 0.0625, -0.1875, 0},
77 {delta = { x = 0, y = 0.07, z = -0.08 }, yaw = 0},
78 {delta = { x = -0.08, y = 0.07, z = 0 }, yaw = math.pi / -2},
79 {delta = { x = 0, y = 0.07, z = 0.08 }, yaw = math.pi},
80 {delta = { x = 0.08, y = 0.07, z = 0 }, yaw = math.pi / 2},
84 signs_lib.hanging_sign_model = {
88 {-0.4375, -0.3125, -0.0625, 0.4375, 0.3125, 0},
89 {-0.4375, 0.25, -0.03125, 0.4375, 0.5, -0.03125},
93 {delta = { x = 0, y = -0.02, z = -0.08 }, yaw = 0},
94 {delta = { x = -0.08, y = -0.02, z = 0 }, yaw = math.pi / -2},
95 {delta = { x = 0, y = -0.02, z = 0.08 }, yaw = math.pi},
96 {delta = { x = 0.08, y = -0.02, z = 0 }, yaw = math.pi / 2},
100 signs_lib.sign_post_model = {
104 {-0.4375, -0.25, -0.1875, 0.4375, 0.375, -0.125},
105 {-0.125, -0.5, -0.125, 0.125, 0.5, 0.125},
109 {delta = { x = 0, y = 0.07, z = -0.2 }, yaw = 0},
110 {delta = { x = -0.2, y = 0.07, z = 0 }, yaw = math.pi / -2},
111 {delta = { x = 0, y = 0.07, z = 0.2 }, yaw = math.pi},
112 {delta = { x = 0.2, y = 0.07, z = 0 }, yaw = math.pi / 2},
116 -- Load support for intllib.
117 local MP = minetest.get_modpath(minetest.get_current_modname())
118 local S, NS = dofile(MP.."/intllib.lua")
119 signs_lib.gettext = S
121 -- the list of standard sign nodes
123 signs_lib.sign_node_list = {
124 "default:sign_wall_wood",
125 "default:sign_wall_steel",
127 "signs:sign_hanging",
128 "signs:sign_wall_green",
129 "signs:sign_wall_yellow",
130 "signs:sign_wall_red",
131 "signs:sign_wall_white_red",
132 "signs:sign_wall_white_black",
133 "signs:sign_wall_orange",
134 "signs:sign_wall_blue",
135 "signs:sign_wall_brown",
136 "locked_sign:sign_wall_locked"
139 local default_sign, default_sign_image
141 -- Default sign was renamed in 0.4.14. Support both & old versions.
142 if minetest.registered_nodes["default:sign_wall_wood"] then
143 default_sign = "default:sign_wall_wood"
144 default_sign_image = "default_sign_wood.png"
146 default_sign = "default:sign_wall"
147 default_sign_image = "default_sign_wall.png"
150 default_sign_metal = "default:sign_wall_steel"
151 default_sign_metal_image = "default_sign_steel.png"
155 function signs_lib.table_copy(t)
157 for k, v in pairs(t) do
158 if type(v) == "table" then
159 nt[k] = signs_lib.table_copy(v)
169 if not minetest.settings:get_bool("creative_mode") then
170 signs_lib.expect_infinite_stacks = false
172 signs_lib.expect_infinite_stacks = true
177 local MP = minetest.get_modpath("signs_lib")
179 -- Used by `build_char_db' to locate the file.
180 local FONT_FMT = "%s/hdf_%02x.png"
182 -- Simple texture name for building text texture.
183 local FONT_FMT_SIMPLE = "hdf_%02x.png"
185 -- Path to the textures.
186 local TP = MP.."/textures"
188 -- Lots of overkill here. KISS advocates, go away, shoo! ;) -- kaeza
190 local PNG_HDR = string.char(0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A)
192 -- Read the image size from a PNG file.
193 -- Returns image_w, image_h.
194 -- Only the LSB is read from each field!
195 local function read_image_size(filename)
196 local f = io.open(filename, "rb")
198 local hdr = f:read(8)
199 if hdr ~= PNG_HDR then
208 return ws:byte(), hs:byte()
211 -- Set by build_char_db()
214 local COLORBGW, COLORBGH
216 -- Size of the canvas, in characters.
217 -- Please note that CHARS_PER_LINE is multiplied by the average character
218 -- width to get the total width of the canvas, so for proportional fonts,
219 -- either more or fewer characters may fit on a line.
220 local CHARS_PER_LINE = 30
221 local NUMBER_OF_LINES = 6
223 -- 6 rows, max 80 chars per, plus a bit of fudge to
224 -- avoid excess trimming (e.g. due to color codes)
226 local MAX_INPUT_CHARS = 600
228 -- This holds the individual character widths.
229 -- Indexed by the actual character (e.g. charwidth["A"])
232 -- helper functions to trim sign text input/output
234 local function trim_input(text)
235 return text:sub(1, math.min(MAX_INPUT_CHARS, text:len()))
238 local function build_char_db()
242 -- To calculate average char width.
243 local total_width = 0
247 local w, h = read_image_size(FONT_FMT:format(TP, c))
249 local ch = string.char(c)
251 total_width = total_width + w
252 char_count = char_count + 1
256 COLORBGW, COLORBGH = read_image_size(TP.."/slc_n.png")
257 assert(COLORBGW and COLORBGH, "error reading bg dimensions")
258 LINE_HEIGHT = COLORBGH
260 -- XXX: Is there a better way to calc this?
261 SIGN_WIDTH = math.floor((total_width / char_count) * CHARS_PER_LINE)
265 local sign_groups = {choppy=2, dig_immediate=2}
267 local fences_with_sign = { }
269 -- some local helper functions
271 local function split_lines_and_words_old(text)
274 if not text then return end
275 for word in text:gmatch("%S+") do
277 table.insert(lines, line)
278 if #lines >= NUMBER_OF_LINES then break end
280 elseif word == "\\|" then
281 table.insert(line, "|")
283 table.insert(line, word)
286 table.insert(lines, line)
290 local function split_lines_and_words(text)
291 if not text then return end
292 text = string.gsub(text, "@KEYWORD", current_keyword)
294 for _, line in ipairs(text:split("\n")) do
295 table.insert(lines, line:split(" "))
300 local math_max = math.max
302 local function fill_line(x, y, w, c)
305 for xx = 0, math.max(0, w), COLORBGW do
306 table.insert(tex, (":%d,%d=slc_%s.png"):format(x + xx, y, c))
308 return table.concat(tex)
311 local function make_line_texture(line, lineno, pos)
317 local n = minetest.registered_nodes[minetest.get_node(pos).name]
318 local default_color = n.default_color or 0
320 local cur_color = tonumber(default_color, 16)
322 -- We check which chars are available here.
323 for word_i, word in ipairs(line) do
329 local c = word:sub(i, i)
331 local cc = tonumber(word:sub(i+1, i+1), 16)
337 local w = charwidth[c]
339 width = width + w + 1
340 if width >= (SIGN_WIDTH - charwidth[" "]) then
343 maxw = math_max(width, maxw)
345 if #chars < MAX_INPUT_CHARS then
346 table.insert(chars, {
348 tex=FONT_FMT_SIMPLE:format(c:byte()),
349 col=("%X"):format(cur_color),
352 ch_offs = ch_offs + w
357 width = width + charwidth[" "] + 1
358 maxw = math_max(width, maxw)
359 table.insert(words, { chars=chars, w=ch_offs })
362 -- Okay, we actually build the "line texture" here.
366 local start_xpos = math.floor((SIGN_WIDTH - maxw) / 2)
368 local xpos = start_xpos
369 local ypos = (LINE_HEIGHT * lineno)
373 for word_i, word in ipairs(words) do
374 local xoffs = (xpos - start_xpos)
375 if (xoffs > 0) and ((xoffs + word.w) > maxw) then
376 table.insert(texture, fill_line(xpos, ypos, maxw, "n"))
378 ypos = ypos + LINE_HEIGHT
380 if lineno >= NUMBER_OF_LINES then break end
381 table.insert(texture, fill_line(xpos, ypos, maxw, cur_color))
383 for ch_i, ch in ipairs(word.chars) do
384 if ch.col ~= cur_color then
386 table.insert(texture, fill_line(xpos + ch.off, ypos, maxw, cur_color))
388 table.insert(texture, (":%d,%d=%s"):format(xpos + ch.off, ypos, ch.tex))
390 table.insert(texture, (":%d,%d=hdf_20.png"):format(xpos + word.w, ypos))
391 xpos = xpos + word.w + charwidth[" "]
392 if xpos >= (SIGN_WIDTH + charwidth[" "]) then break end
395 table.insert(texture, fill_line(xpos, ypos, maxw, "n"))
396 table.insert(texture, fill_line(start_xpos, ypos + LINE_HEIGHT, maxw, "n"))
398 return table.concat(texture), lineno
401 local function make_sign_texture(lines, pos)
402 local texture = { ("[combine:%dx%d"):format(SIGN_WIDTH, LINE_HEIGHT * NUMBER_OF_LINES) }
405 if lineno >= NUMBER_OF_LINES then break end
406 local linetex, ln = make_line_texture(lines[i], lineno, pos)
407 table.insert(texture, linetex)
410 table.insert(texture, "^[makealpha:0,0,0")
411 return table.concat(texture, "")
414 local function set_obj_text(obj, text, new, pos)
415 local split = new and split_lines_and_words or split_lines_and_words_old
416 local n = minetest.registered_nodes[minetest.get_node(pos).name]
417 local text_scale = (n and n.text_scale) or DEFAULT_TEXT_SCALE
419 textures={make_sign_texture(split(text), pos)},
420 visual_size = text_scale,
424 signs_lib.construct_sign = function(pos, locked)
425 local meta = minetest.get_meta(pos)
429 "textarea[0,-0.3;6.5,3;text;;${text}]"..
430 "button_exit[2,3.4;2,1;ok;Write]"..
431 "background[-0.5,-0.5;7,5;bg_signs_lib.jpg]")
432 meta:set_string("infotext", "")
435 signs_lib.destruct_sign = function(pos)
436 local objects = minetest.get_objects_inside_radius(pos, 0.5)
437 for _, v in ipairs(objects) do
438 local e = v:get_luaentity()
439 if e and e.name == "signs:text" then
445 local function make_infotext(text)
446 text = trim_input(text)
447 local lines = split_lines_and_words(text) or {}
449 for _, line in ipairs(lines) do
450 table.insert(lines2, (table.concat(line, " "):gsub("#[0-9a-fA-F]", ""):gsub("##", "#")))
452 return table.concat(lines2, "\n")
455 signs_lib.update_sign = function(pos, fields, owner)
457 -- First, check if the interact keyword from CWz's mod is being set,
458 -- or has been changed since the last restart...
460 local meta = minetest.get_meta(pos)
461 local stored_text = meta:get_string("text") or ""
462 current_keyword = rawget(_G, "mki_interact_keyword") or current_keyword
464 if fields then -- ...we're editing the sign.
465 if fields.text and string.find(dump(fields.text), "@KEYWORD") then
466 meta:set_string("keyword", current_keyword)
468 meta:set_string("keyword", nil)
470 elseif string.find(dump(stored_text), "@KEYWORD") then -- we need to check if the password is being set/changed
472 local stored_keyword = meta:get_string("keyword")
473 if stored_keyword and stored_keyword ~= "" and stored_keyword ~= current_keyword then
474 signs_lib.destruct_sign(pos)
475 meta:set_string("keyword", current_keyword)
477 if owner then ownstr = S("Locked sign, owned by @1\n", owner) end
478 meta:set_string("infotext", ownstr..string.gsub(make_infotext(stored_text), "@KEYWORD", current_keyword).." ")
486 fields.text = trim_input(fields.text)
489 if owner then ownstr = S("Locked sign, owned by @1\n", owner) end
491 meta:set_string("infotext", ownstr..string.gsub(make_infotext(fields.text), "@KEYWORD", current_keyword).." ")
492 meta:set_string("text", fields.text)
494 meta:set_int("__signslib_new_format", 1)
497 new = (meta:get_int("__signslib_new_format") ~= 0)
499 local text = meta:get_string("text")
500 if text == nil then return end
501 local objects = minetest.get_objects_inside_radius(pos, 0.5)
503 for _, v in ipairs(objects) do
504 local e = v:get_luaentity()
505 if e and e.name == "signs:text" then
509 set_obj_text(v, text, new, pos)
518 -- if there is no entity
520 local signnode = minetest.get_node(pos)
521 local signname = signnode.name
522 local textpos = minetest.registered_nodes[signname].textpos
524 sign_info = textpos[minetest.get_node(pos).param2 + 1]
525 elseif signnode.name == "signs:sign_yard" then
526 sign_info = signs_lib.yard_sign_model.textpos[minetest.get_node(pos).param2 + 1]
527 elseif signnode.name == "signs:sign_hanging" then
528 sign_info = signs_lib.hanging_sign_model.textpos[minetest.get_node(pos).param2 + 1]
529 elseif string.find(signnode.name, "sign_wall") then
530 if signnode.name == default_sign
531 or signnode.name == default_sign_metal
532 or signnode.name == "locked_sign:sign_wall_locked" then
533 sign_info = signs_lib.regular_wall_sign_model.textpos[minetest.get_node(pos).param2 + 1]
535 sign_info = signs_lib.metal_wall_sign_model.textpos[minetest.get_node(pos).param2 + 1]
537 else -- ...it must be a sign on a fence post.
538 sign_info = signs_lib.sign_post_model.textpos[minetest.get_node(pos).param2 + 1]
540 if sign_info == nil then
543 local text = minetest.add_entity({x = pos.x + sign_info.delta.x,
544 y = pos.y + sign_info.delta.y,
545 z = pos.z + sign_info.delta.z}, "signs:text")
546 text:setyaw(sign_info.yaw)
549 -- What kind of sign do we need to place, anyway?
551 function signs_lib.determine_sign_type(itemstack, placer, pointed_thing, locked)
553 name = minetest.get_node(pointed_thing.under).name
554 if fences_with_sign[name] then
555 if minetest.is_protected(pointed_thing.under, placer:get_player_name()) then
556 minetest.record_protection_violation(pointed_thing.under,
557 placer:get_player_name())
561 name = minetest.get_node(pointed_thing.above).name
562 local def = minetest.registered_nodes[name]
563 if not def.buildable_to then
566 if minetest.is_protected(pointed_thing.above, placer:get_player_name()) then
567 minetest.record_protection_violation(pointed_thing.above,
568 placer:get_player_name())
573 local node=minetest.get_node(pointed_thing.under)
575 if minetest.registered_nodes[node.name] and
576 minetest.registered_nodes[node.name].on_rightclick and
577 not placer:get_player_control().sneak then
578 return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack, pointed_thing)
580 local above = pointed_thing.above
581 local under = pointed_thing.under
582 local dir = {x = under.x - above.x,
583 y = under.y - above.y,
584 z = under.z - above.z}
586 local wdir = minetest.dir_to_wallmounted(dir)
588 local placer_pos = placer:getpos()
591 x = above.x - placer_pos.x,
592 y = above.y - placer_pos.y,
593 z = above.z - placer_pos.z
597 local fdir = minetest.dir_to_facedir(dir)
598 local pt_name = minetest.get_node(under).name
599 local signname = itemstack:get_name()
601 if fences_with_sign[pt_name] and signname == default_sign then
602 minetest.add_node(under, {name = fences_with_sign[pt_name], param2 = fdir})
603 elseif wdir == 0 and signname == default_sign then
604 minetest.add_node(above, {name = "signs:sign_hanging", param2 = fdir})
605 elseif wdir == 1 and signname == default_sign then
606 minetest.add_node(above, {name = "signs:sign_yard", param2 = fdir})
607 elseif signname == default_sign_metal then
608 minetest.add_node(above, {name = signname, param2 = wdir })
609 elseif signname ~= default_sign
610 and signname ~= default_sign_metal
611 and signname ~= "locked_sign:sign_wall_locked" then -- it's a signs_lib colored metal wall sign.
612 minetest.add_node(above, {name = signname, param2 = fdir})
613 else -- it must be a default or locked wooden wall sign
614 minetest.add_node(above, {name = signname, param2 = wdir }) -- note it's wallmounted here!
616 local meta = minetest.get_meta(above)
617 local owner = placer:get_player_name()
618 meta:set_string("owner", owner)
622 if not signs_lib.expect_infinite_stacks then
623 itemstack:take_item()
629 function signs_lib.receive_fields(pos, formname, fields, sender, lock)
630 if minetest.is_protected(pos, sender:get_player_name()) then
631 minetest.record_protection_violation(pos,
632 sender:get_player_name())
635 local lockstr = lock and S("locked ") or ""
636 if fields and fields.text and fields.ok then
637 minetest.log("action", S("@1 wrote \"@2\" to @3sign at @4",
638 (sender:get_player_name() or ""),
641 minetest.pos_to_string(pos)
644 signs_lib.update_sign(pos, fields, sender:get_player_name())
646 signs_lib.update_sign(pos, fields)
651 minetest.register_node(":"..default_sign, {
652 description = S("Sign"),
653 inventory_image = default_sign_image,
654 wield_image = default_sign_image,
655 node_placement_prediction = "",
656 sunlight_propagates = true,
658 paramtype2 = "wallmounted",
659 drawtype = "nodebox",
660 node_box = signs_lib.regular_wall_sign_model.nodebox,
661 tiles = {"signs_wall_sign.png"},
662 groups = sign_groups,
664 on_place = function(itemstack, placer, pointed_thing)
665 return signs_lib.determine_sign_type(itemstack, placer, pointed_thing)
667 on_construct = function(pos)
668 signs_lib.construct_sign(pos)
670 on_destruct = function(pos)
671 signs_lib.destruct_sign(pos)
673 on_receive_fields = function(pos, formname, fields, sender)
674 signs_lib.receive_fields(pos, formname, fields, sender)
676 on_punch = function(pos, node, puncher)
677 signs_lib.update_sign(pos)
679 on_rotate = signs_lib.wallmounted_rotate
682 minetest.register_node(":signs:sign_yard", {
684 sunlight_propagates = true,
685 paramtype2 = "facedir",
686 drawtype = "nodebox",
687 node_box = signs_lib.yard_sign_model.nodebox,
690 fixed = {-0.4375, -0.5, -0.0625, 0.4375, 0.375, 0}
692 tiles = {"signs_top.png", "signs_bottom.png", "signs_side.png", "signs_side.png", "signs_back.png", "signs_front.png"},
693 groups = {choppy=2, dig_immediate=2},
696 on_construct = function(pos)
697 signs_lib.construct_sign(pos)
699 on_destruct = function(pos)
700 signs_lib.destruct_sign(pos)
702 on_receive_fields = function(pos, formname, fields, sender)
703 signs_lib.receive_fields(pos, formname, fields, sender)
705 on_punch = function(pos, node, puncher)
706 signs_lib.update_sign(pos)
710 minetest.register_node(":signs:sign_hanging", {
712 sunlight_propagates = true,
713 paramtype2 = "facedir",
714 drawtype = "nodebox",
715 node_box = signs_lib.hanging_sign_model.nodebox,
718 fixed = {-0.45, -0.275, -0.049, 0.45, 0.5, 0.049}
721 "signs_hanging_top.png",
722 "signs_hanging_bottom.png",
723 "signs_hanging_side.png",
724 "signs_hanging_side.png",
725 "signs_hanging_back.png",
726 "signs_hanging_front.png"
728 groups = {choppy=2, dig_immediate=2},
731 on_construct = function(pos)
732 signs_lib.construct_sign(pos)
734 on_destruct = function(pos)
735 signs_lib.destruct_sign(pos)
737 on_receive_fields = function(pos, formname, fields, sender)
738 signs_lib.receive_fields(pos, formname, fields, sender)
740 on_punch = function(pos, node, puncher)
741 signs_lib.update_sign(pos)
745 minetest.register_node(":signs:sign_post", {
747 sunlight_propagates = true,
748 paramtype2 = "facedir",
749 drawtype = "nodebox",
750 node_box = signs_lib.sign_post_model.nodebox,
752 "signs_post_top.png",
753 "signs_post_bottom.png",
754 "signs_post_side.png",
755 "signs_post_side.png",
756 "signs_post_back.png",
757 "signs_post_front.png",
759 groups = {choppy=2, dig_immediate=2},
763 { items = { default_sign }},
764 { items = { "default:fence_wood" }},
771 minetest.register_privilege("sign_editor", S("Can edit all locked signs"))
773 minetest.register_node(":locked_sign:sign_wall_locked", {
774 description = S("Locked Sign"),
775 inventory_image = "signs_locked_inv.png",
776 wield_image = "signs_locked_inv.png",
777 node_placement_prediction = "",
778 sunlight_propagates = true,
780 paramtype2 = "wallmounted",
781 drawtype = "nodebox",
782 node_box = signs_lib.regular_wall_sign_model.nodebox,
783 tiles = { "signs_wall_sign_locked.png" },
784 groups = sign_groups,
785 on_place = function(itemstack, placer, pointed_thing)
786 return signs_lib.determine_sign_type(itemstack, placer, pointed_thing, true)
788 on_construct = function(pos)
789 signs_lib.construct_sign(pos, true)
791 on_destruct = function(pos)
792 signs_lib.destruct_sign(pos)
794 on_receive_fields = function(pos, formname, fields, sender)
795 local meta = minetest.get_meta(pos)
796 local owner = meta:get_string("owner")
797 local pname = sender:get_player_name() or ""
798 if pname ~= owner and pname ~= minetest.settings:get("name")
799 and not minetest.check_player_privs(pname, {sign_editor=true}) then
802 signs_lib.receive_fields(pos, formname, fields, sender, true)
804 on_punch = function(pos, node, puncher)
805 signs_lib.update_sign(pos)
807 can_dig = function(pos, player)
808 local meta = minetest.get_meta(pos)
809 local owner = meta:get_string("owner")
810 local pname = player:get_player_name()
811 return pname == owner or pname == minetest.settings:get("name")
812 or minetest.check_player_privs(pname, {sign_editor=true})
814 on_rotate = signs_lib.wallmounted_rotate
817 -- default metal sign, if defined
819 if minetest.registered_nodes["default:sign_wall_steel"] then
820 minetest.register_node(":"..default_sign_metal, {
821 description = S("Sign"),
822 inventory_image = default_sign_metal_image,
823 wield_image = default_sign_metal_image,
824 node_placement_prediction = "",
825 sunlight_propagates = true,
827 paramtype2 = "wallmounted",
828 drawtype = "nodebox",
829 node_box = signs_lib.regular_wall_sign_model.nodebox,
830 tiles = {"signs_wall_sign_metal.png"},
831 groups = sign_groups,
833 on_place = function(itemstack, placer, pointed_thing)
834 return signs_lib.determine_sign_type(itemstack, placer, pointed_thing)
836 on_construct = function(pos)
837 signs_lib.construct_sign(pos)
839 on_destruct = function(pos)
840 signs_lib.destruct_sign(pos)
842 on_receive_fields = function(pos, formname, fields, sender)
843 signs_lib.receive_fields(pos, formname, fields, sender)
845 on_punch = function(pos, node, puncher)
846 signs_lib.update_sign(pos)
848 on_rotate = signs_lib.wallmounted_rotate
852 -- metal, colored signs
853 if enable_colored_metal_signs then
854 -- array : color, translated color, default text color
855 local sign_colors = {
856 {"green", S("green"), "f"},
857 {"yellow", S("yellow"), "0"},
858 {"red", S("red"), "f"},
859 {"white_red", S("white_red"), "4"},
860 {"white_black", S("white_black"), "0"},
861 {"orange", S("orange"), "0"},
862 {"blue", S("blue"), "f"},
863 {"brown", S("brown"), "f"},
866 for i, color in ipairs(sign_colors) do
867 minetest.register_node(":signs:sign_wall_"..color[1], {
868 description = S("Sign (@1, metal)", color[2]),
869 inventory_image = "signs_"..color[1].."_inv.png",
870 wield_image = "signs_"..color[1].."_inv.png",
871 node_placement_prediction = "",
873 sunlight_propagates = true,
874 paramtype2 = "facedir",
875 drawtype = "nodebox",
876 node_box = signs_lib.metal_wall_sign_model.nodebox,
878 "signs_metal_tb.png",
879 "signs_metal_tb.png",
880 "signs_metal_sides.png",
881 "signs_metal_sides.png",
882 "signs_metal_back.png",
883 "signs_"..color[1].."_front.png"
885 default_color = color[3],
886 groups = sign_groups,
887 on_place = function(itemstack, placer, pointed_thing)
888 return signs_lib.determine_sign_type(itemstack, placer, pointed_thing)
890 on_construct = function(pos)
891 signs_lib.construct_sign(pos)
893 on_destruct = function(pos)
894 signs_lib.destruct_sign(pos)
896 on_receive_fields = function(pos, formname, fields, sender)
897 signs_lib.receive_fields(pos, formname, fields, sender)
899 on_punch = function(pos, node, puncher)
900 signs_lib.update_sign(pos)
906 local signs_text_on_activate
908 signs_text_on_activate = function(self)
909 local pos = self.object:getpos()
910 local meta = minetest.get_meta(pos)
911 local text = meta:get_string("text")
912 local new = (meta:get_int("__signslib_new_format") ~= 0)
914 text = trim_input(text)
915 set_obj_text(self.object, text, new, pos)
919 minetest.register_entity(":signs:text", {
920 collisionbox = { 0, 0, 0, 0, 0, 0 },
921 visual = "upright_sprite",
924 on_activate = signs_text_on_activate,
927 -- And the good stuff here! :-)
929 function signs_lib.register_fence_with_sign(fencename, fencewithsignname)
930 local def = minetest.registered_nodes[fencename]
931 local def_sign = minetest.registered_nodes[fencewithsignname]
932 if not (def and def_sign) then
933 minetest.log("warning", "[signs_lib] "..S("Attempt to register unknown node as fence"))
936 def = signs_lib.table_copy(def)
937 def_sign = signs_lib.table_copy(def_sign)
938 fences_with_sign[fencename] = fencewithsignname
940 def_sign.on_place = function(itemstack, placer, pointed_thing, ...)
941 local node_above = minetest.get_node_or_nil(pointed_thing.above)
942 local node_under = minetest.get_node_or_nil(pointed_thing.under)
943 local def_above = node_above and minetest.registered_nodes[node_above.name]
944 local def_under = node_under and minetest.registered_nodes[node_under.name]
945 local fdir = minetest.dir_to_facedir(placer:get_look_dir())
946 local playername = placer:get_player_name()
948 if minetest.is_protected(pointed_thing.under, playername) then
949 minetest.record_protection_violation(pointed_thing.under, playername)
953 if minetest.is_protected(pointed_thing.above, playername) then
954 minetest.record_protection_violation(pointed_thing.above, playername)
958 if def_under and def_under.on_rightclick then
959 return def_under.on_rightclick(pointed_thing.under, node_under, placer, itemstack, pointed_thing) or itemstack
960 elseif def_under and def_under.buildable_to then
961 minetest.add_node(pointed_thing.under, {name = fencename, param2 = fdir})
962 if not signs_lib.expect_infinite_stacks then
963 itemstack:take_item()
965 placer:set_wielded_item(itemstack)
966 elseif def_above and def_above.buildable_to then
967 minetest.add_node(pointed_thing.above, {name = fencename, param2 = fdir})
968 if not signs_lib.expect_infinite_stacks then
969 itemstack:take_item()
971 placer:set_wielded_item(itemstack)
975 def_sign.on_construct = function(pos, ...)
976 signs_lib.construct_sign(pos)
978 def_sign.on_destruct = function(pos, ...)
979 signs_lib.destruct_sign(pos)
981 def_sign.on_receive_fields = function(pos, formname, fields, sender)
982 signs_lib.receive_fields(pos, formname, fields, sender)
984 def_sign.on_punch = function(pos, node, puncher, ...)
985 signs_lib.update_sign(pos)
987 local fencename = fencename
988 def_sign.after_dig_node = function(pos, node, ...)
989 node.name = fencename
990 minetest.add_node(pos, node)
992 def_sign.drop = default_sign
993 minetest.register_node(":"..fencename, def)
994 minetest.register_node(":"..fencewithsignname, def_sign)
995 table.insert(signs_lib.sign_node_list, fencewithsignname)
996 minetest.log("verbose", S("Registered @1 and @2", fencename, fencewithsignname))
1001 minetest.register_alias("homedecor:fence_wood_with_sign", "signs:sign_post")
1002 minetest.register_alias("sign_wall_locked", "locked_sign:sign_wall_locked")
1004 signs_lib.register_fence_with_sign("default:fence_wood", "signs:sign_post")
1006 -- restore signs' text after /clearobjects and the like, the next time
1007 -- a block is reloaded by the server.
1009 minetest.register_lbm({
1010 nodenames = signs_lib.sign_node_list,
1011 name = "signs_lib:restore_sign_text",
1012 label = "Restore sign text",
1013 run_at_every_load = true,
1014 action = function(pos, node)
1015 signs_lib.update_sign(pos)
1021 minetest.register_craft({
1022 output = "locked_sign:sign_wall_locked",
1025 {"default:steel_ingot"},
1029 -- craft recipes for the metal signs
1030 if enable_colored_metal_signs then
1032 minetest.register_craft( {
1033 output = "signs:sign_wall_green",
1035 { "dye:dark_green", "dye:white", "dye:dark_green" },
1036 { "", default_sign_metal, "" }
1040 minetest.register_craft( {
1041 output = "signs:sign_wall_green 2",
1043 { "dye:dark_green", "dye:white", "dye:dark_green" },
1044 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1048 minetest.register_craft( {
1049 output = "signs:sign_wall_yellow",
1051 { "dye:yellow", "dye:black", "dye:yellow" },
1052 { "", default_sign_metal, "" }
1056 minetest.register_craft( {
1057 output = "signs:sign_wall_yellow 2",
1059 { "dye:yellow", "dye:black", "dye:yellow" },
1060 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1064 minetest.register_craft( {
1065 output = "signs:sign_wall_red",
1067 { "dye:red", "dye:white", "dye:red" },
1068 { "", default_sign_metal, "" }
1072 minetest.register_craft( {
1073 output = "signs:sign_wall_red 2",
1075 { "dye:red", "dye:white", "dye:red" },
1076 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1080 minetest.register_craft( {
1081 output = "signs:sign_wall_white_red",
1083 { "dye:white", "dye:red", "dye:white" },
1084 { "", default_sign_metal, "" }
1088 minetest.register_craft( {
1089 output = "signs:sign_wall_white_red 2",
1091 { "dye:white", "dye:red", "dye:white" },
1092 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1096 minetest.register_craft( {
1097 output = "signs:sign_wall_white_black",
1099 { "dye:white", "dye:black", "dye:white" },
1100 { "", default_sign_metal, "" }
1104 minetest.register_craft( {
1105 output = "signs:sign_wall_white_black 2",
1107 { "dye:white", "dye:black", "dye:white" },
1108 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1112 minetest.register_craft( {
1113 output = "signs:sign_wall_orange",
1115 { "dye:orange", "dye:black", "dye:orange" },
1116 { "", default_sign_metal, "" }
1120 minetest.register_craft( {
1121 output = "signs:sign_wall_orange 2",
1123 { "dye:orange", "dye:black", "dye:orange" },
1124 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1128 minetest.register_craft( {
1129 output = "signs:sign_wall_blue",
1131 { "dye:blue", "dye:white", "dye:blue" },
1132 { "", default_sign_metal, "" }
1136 minetest.register_craft( {
1137 output = "signs:sign_wall_blue 2",
1139 { "dye:blue", "dye:white", "dye:blue" },
1140 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1144 minetest.register_craft( {
1145 output = "signs:sign_wall_brown",
1147 { "dye:brown", "dye:white", "dye:brown" },
1148 { "", default_sign_metal, "" }
1152 minetest.register_craft( {
1153 output = "signs:sign_wall_brown 2",
1155 { "dye:brown", "dye:white", "dye:brown" },
1156 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1161 if minetest.settings:get("log_mods") then
1162 minetest.log("action", S("[MOD] signs loaded"))