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.setting_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 -- Boilerplate to support localized strings if intllib mod is installed.
117 local S = rawget(_G, "intllib") and intllib.Getter() or function(s) return s end
118 signs_lib.gettext = S
120 -- the list of standard sign nodes
122 signs_lib.sign_node_list = {
123 "default:sign_wall_wood",
124 "default:sign_wall_steel",
126 "signs:sign_hanging",
127 "signs:sign_wall_green",
128 "signs:sign_wall_yellow",
129 "signs:sign_wall_red",
130 "signs:sign_wall_white_red",
131 "signs:sign_wall_white_black",
132 "signs:sign_wall_orange",
133 "signs:sign_wall_blue",
134 "signs:sign_wall_brown",
135 "locked_sign:sign_wall_locked"
138 local default_sign, default_sign_image
140 -- Default sign was renamed in 0.4.14. Support both & old versions.
141 if minetest.registered_nodes["default:sign_wall_wood"] then
142 default_sign = "default:sign_wall_wood"
143 default_sign_image = "default_sign_wood.png"
145 default_sign = "default:sign_wall"
146 default_sign_image = "default_sign_wall.png"
149 default_sign_metal = "default:sign_wall_steel"
150 default_sign_metal_image = "default_sign_steel.png"
154 function signs_lib.table_copy(t)
156 for k, v in pairs(t) do
157 if type(v) == "table" then
158 nt[k] = signs_lib.table_copy(v)
168 if not minetest.setting_getbool("creative_mode") then
169 signs_lib.expect_infinite_stacks = false
171 signs_lib.expect_infinite_stacks = true
176 local MP = minetest.get_modpath("signs_lib")
178 -- Used by `build_char_db' to locate the file.
179 local FONT_FMT = "%s/hdf_%02x.png"
181 -- Simple texture name for building text texture.
182 local FONT_FMT_SIMPLE = "hdf_%02x.png"
184 -- Path to the textures.
185 local TP = MP.."/textures"
187 -- Lots of overkill here. KISS advocates, go away, shoo! ;) -- kaeza
189 local PNG_HDR = string.char(0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A)
191 -- Read the image size from a PNG file.
192 -- Returns image_w, image_h.
193 -- Only the LSB is read from each field!
194 local function read_image_size(filename)
195 local f = io.open(filename, "rb")
197 local hdr = f:read(8)
198 if hdr ~= PNG_HDR then
207 return ws:byte(), hs:byte()
210 -- Set by build_char_db()
213 local COLORBGW, COLORBGH
215 -- Size of the canvas, in characters.
216 -- Please note that CHARS_PER_LINE is multiplied by the average character
217 -- width to get the total width of the canvas, so for proportional fonts,
218 -- either more or fewer characters may fit on a line.
219 local CHARS_PER_LINE = 30
220 local NUMBER_OF_LINES = 6
222 -- 6 rows, max 80 chars per, plus a bit of fudge to
223 -- avoid excess trimming (e.g. due to color codes)
225 local MAX_INPUT_CHARS = 600
227 -- This holds the individual character widths.
228 -- Indexed by the actual character (e.g. charwidth["A"])
231 -- helper functions to trim sign text input/output
233 local function trim_input(text)
234 return text:sub(1, math.min(MAX_INPUT_CHARS, text:len()))
237 local function build_char_db()
241 -- To calculate average char width.
242 local total_width = 0
246 local w, h = read_image_size(FONT_FMT:format(TP, c))
248 local ch = string.char(c)
250 total_width = total_width + w
251 char_count = char_count + 1
255 COLORBGW, COLORBGH = read_image_size(TP.."/slc_n.png")
256 assert(COLORBGW and COLORBGH, "error reading bg dimensions")
257 LINE_HEIGHT = COLORBGH
259 -- XXX: Is there a better way to calc this?
260 SIGN_WIDTH = math.floor((total_width / char_count) * CHARS_PER_LINE)
264 local sign_groups = {choppy=2, dig_immediate=2}
266 local fences_with_sign = { }
268 -- some local helper functions
270 local function split_lines_and_words_old(text)
273 if not text then return end
274 for word in text:gmatch("%S+") do
276 table.insert(lines, line)
277 if #lines >= NUMBER_OF_LINES then break end
279 elseif word == "\\|" then
280 table.insert(line, "|")
282 table.insert(line, word)
285 table.insert(lines, line)
289 local function split_lines_and_words(text)
290 if not text then return end
291 text = string.gsub(text, "@KEYWORD", current_keyword)
293 for _, line in ipairs(text:split("\n")) do
294 table.insert(lines, line:split(" "))
299 local math_max = math.max
301 local function fill_line(x, y, w, c)
304 for xx = 0, math.max(0, w), COLORBGW do
305 table.insert(tex, (":%d,%d=slc_%s.png"):format(x + xx, y, c))
307 return table.concat(tex)
310 local function make_line_texture(line, lineno, pos)
316 local n = minetest.registered_nodes[minetest.get_node(pos).name]
317 local default_color = n.default_color or 0
319 local cur_color = tonumber(default_color, 16)
321 -- We check which chars are available here.
322 for word_i, word in ipairs(line) do
328 local c = word:sub(i, i)
330 local cc = tonumber(word:sub(i+1, i+1), 16)
336 local w = charwidth[c]
338 width = width + w + 1
339 if width >= (SIGN_WIDTH - charwidth[" "]) then
342 maxw = math_max(width, maxw)
344 if #chars < MAX_INPUT_CHARS then
345 table.insert(chars, {
347 tex=FONT_FMT_SIMPLE:format(c:byte()),
348 col=("%X"):format(cur_color),
351 ch_offs = ch_offs + w
356 width = width + charwidth[" "] + 1
357 maxw = math_max(width, maxw)
358 table.insert(words, { chars=chars, w=ch_offs })
361 -- Okay, we actually build the "line texture" here.
365 local start_xpos = math.floor((SIGN_WIDTH - maxw) / 2)
367 local xpos = start_xpos
368 local ypos = (LINE_HEIGHT * lineno)
372 for word_i, word in ipairs(words) do
373 local xoffs = (xpos - start_xpos)
374 if (xoffs > 0) and ((xoffs + word.w) > maxw) then
375 table.insert(texture, fill_line(xpos, ypos, maxw, "n"))
377 ypos = ypos + LINE_HEIGHT
379 if lineno >= NUMBER_OF_LINES then break end
380 table.insert(texture, fill_line(xpos, ypos, maxw, cur_color))
382 for ch_i, ch in ipairs(word.chars) do
383 if ch.col ~= cur_color then
385 table.insert(texture, fill_line(xpos + ch.off, ypos, maxw, cur_color))
387 table.insert(texture, (":%d,%d=%s"):format(xpos + ch.off, ypos, ch.tex))
389 table.insert(texture, (":%d,%d=hdf_20.png"):format(xpos + word.w, ypos))
390 xpos = xpos + word.w + charwidth[" "]
391 if xpos >= (SIGN_WIDTH + charwidth[" "]) then break end
394 table.insert(texture, fill_line(xpos, ypos, maxw, "n"))
395 table.insert(texture, fill_line(start_xpos, ypos + LINE_HEIGHT, maxw, "n"))
397 return table.concat(texture), lineno
400 local function make_sign_texture(lines, pos)
401 local texture = { ("[combine:%dx%d"):format(SIGN_WIDTH, LINE_HEIGHT * NUMBER_OF_LINES) }
404 if lineno >= NUMBER_OF_LINES then break end
405 local linetex, ln = make_line_texture(lines[i], lineno, pos)
406 table.insert(texture, linetex)
409 table.insert(texture, "^[makealpha:0,0,0")
410 return table.concat(texture, "")
413 local function set_obj_text(obj, text, new, pos)
414 local split = new and split_lines_and_words or split_lines_and_words_old
415 local n = minetest.registered_nodes[minetest.get_node(pos).name]
416 local text_scale = n.text_scale or DEFAULT_TEXT_SCALE
418 textures={make_sign_texture(split(text), pos)},
419 visual_size = text_scale,
423 signs_lib.construct_sign = function(pos, locked)
424 local meta = minetest.get_meta(pos)
428 "textarea[0,-0.3;6.5,3;text;;${text}]"..
429 "button_exit[2,3.4;2,1;ok;Write]"..
430 "background[-0.5,-0.5;7,5;bg_signs_lib.jpg]")
431 meta:set_string("infotext", "")
434 signs_lib.destruct_sign = function(pos)
435 local objects = minetest.get_objects_inside_radius(pos, 0.5)
436 for _, v in ipairs(objects) do
437 local e = v:get_luaentity()
438 if e and e.name == "signs:text" then
444 local function make_infotext(text)
445 text = trim_input(text)
446 local lines = split_lines_and_words(text) or {}
448 for _, line in ipairs(lines) do
449 table.insert(lines2, (table.concat(line, " "):gsub("#[0-9a-fA-F]", ""):gsub("##", "#")))
451 return table.concat(lines2, "\n")
454 signs_lib.update_sign = function(pos, fields, owner)
456 -- First, check if the interact keyword from CWz's mod is being set,
457 -- or has been changed since the last restart...
459 local meta = minetest.get_meta(pos)
460 local stored_text = meta:get_string("text") or ""
461 current_keyword = rawget(_G, "mki_interact_keyword") or current_keyword
463 if fields then -- ...we're editing the sign.
464 if fields.text and string.find(dump(fields.text), "@KEYWORD") then
465 meta:set_string("keyword", current_keyword)
467 meta:set_string("keyword", nil)
469 elseif string.find(dump(stored_text), "@KEYWORD") then -- we need to check if the password is being set/changed
471 local stored_keyword = meta:get_string("keyword")
472 if stored_keyword and stored_keyword ~= "" and stored_keyword ~= current_keyword then
473 signs_lib.destruct_sign(pos)
474 meta:set_string("keyword", current_keyword)
476 if owner then ownstr = "Locked sign, owned by "..owner.."\n" end
477 meta:set_string("infotext", ownstr..string.gsub(make_infotext(stored_text), "@KEYWORD", current_keyword).." ")
485 fields.text = trim_input(fields.text)
488 if owner then ownstr = "Locked sign, owned by "..owner.."\n" end
490 meta:set_string("infotext", ownstr..string.gsub(make_infotext(fields.text), "@KEYWORD", current_keyword).." ")
491 meta:set_string("text", fields.text)
493 meta:set_int("__signslib_new_format", 1)
496 new = (meta:get_int("__signslib_new_format") ~= 0)
498 local text = meta:get_string("text")
499 if text == nil then return end
500 local objects = minetest.get_objects_inside_radius(pos, 0.5)
502 for _, v in ipairs(objects) do
503 local e = v:get_luaentity()
504 if e and e.name == "signs:text" then
508 set_obj_text(v, text, new, pos)
517 -- if there is no entity
519 local signnode = minetest.get_node(pos)
520 local signname = signnode.name
521 local textpos = minetest.registered_nodes[signname].textpos
523 sign_info = textpos[minetest.get_node(pos).param2 + 1]
524 elseif signnode.name == "signs:sign_yard" then
525 sign_info = signs_lib.yard_sign_model.textpos[minetest.get_node(pos).param2 + 1]
526 elseif signnode.name == "signs:sign_hanging" then
527 sign_info = signs_lib.hanging_sign_model.textpos[minetest.get_node(pos).param2 + 1]
528 elseif string.find(signnode.name, "sign_wall") then
529 if signnode.name == default_sign
530 or signnode.name == default_sign_metal
531 or signnode.name == "locked_sign:sign_wall_locked" then
532 sign_info = signs_lib.regular_wall_sign_model.textpos[minetest.get_node(pos).param2 + 1]
534 sign_info = signs_lib.metal_wall_sign_model.textpos[minetest.get_node(pos).param2 + 1]
536 else -- ...it must be a sign on a fence post.
537 sign_info = signs_lib.sign_post_model.textpos[minetest.get_node(pos).param2 + 1]
539 if sign_info == nil then
542 local text = minetest.add_entity({x = pos.x + sign_info.delta.x,
543 y = pos.y + sign_info.delta.y,
544 z = pos.z + sign_info.delta.z}, "signs:text")
545 text:setyaw(sign_info.yaw)
548 -- What kind of sign do we need to place, anyway?
550 function signs_lib.determine_sign_type(itemstack, placer, pointed_thing, locked)
552 name = minetest.get_node(pointed_thing.under).name
553 if fences_with_sign[name] then
554 if minetest.is_protected(pointed_thing.under, placer:get_player_name()) then
555 minetest.record_protection_violation(pointed_thing.under,
556 placer:get_player_name())
560 name = minetest.get_node(pointed_thing.above).name
561 local def = minetest.registered_nodes[name]
562 if not def.buildable_to then
565 if minetest.is_protected(pointed_thing.above, placer:get_player_name()) then
566 minetest.record_protection_violation(pointed_thing.above,
567 placer:get_player_name())
572 local node=minetest.get_node(pointed_thing.under)
574 if minetest.registered_nodes[node.name] and
575 minetest.registered_nodes[node.name].on_rightclick and
576 not placer:get_player_control().sneak then
577 return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack, pointed_thing)
579 local above = pointed_thing.above
580 local under = pointed_thing.under
581 local dir = {x = under.x - above.x,
582 y = under.y - above.y,
583 z = under.z - above.z}
585 local wdir = minetest.dir_to_wallmounted(dir)
587 local placer_pos = placer:getpos()
590 x = above.x - placer_pos.x,
591 y = above.y - placer_pos.y,
592 z = above.z - placer_pos.z
596 local fdir = minetest.dir_to_facedir(dir)
597 local pt_name = minetest.get_node(under).name
598 local signname = itemstack:get_name()
600 if fences_with_sign[pt_name] and signname == default_sign then
601 minetest.add_node(under, {name = fences_with_sign[pt_name], param2 = fdir})
602 elseif wdir == 0 and signname == default_sign then
603 minetest.add_node(above, {name = "signs:sign_hanging", param2 = fdir})
604 elseif wdir == 1 and signname == default_sign then
605 minetest.add_node(above, {name = "signs:sign_yard", param2 = fdir})
606 elseif signname == default_sign_metal then
607 minetest.add_node(above, {name = signname, param2 = wdir })
608 elseif signname ~= default_sign
609 and signname ~= default_sign_metal
610 and signname ~= "locked_sign:sign_wall_locked" then -- it's a signs_lib colored metal wall sign.
611 minetest.add_node(above, {name = signname, param2 = fdir})
612 else -- it must be a default or locked wooden wall sign
613 minetest.add_node(above, {name = signname, param2 = wdir }) -- note it's wallmounted here!
615 local meta = minetest.get_meta(above)
616 local owner = placer:get_player_name()
617 meta:set_string("owner", owner)
621 if not signs_lib.expect_infinite_stacks then
622 itemstack:take_item()
628 function signs_lib.receive_fields(pos, formname, fields, sender, lock)
629 if minetest.is_protected(pos, sender:get_player_name()) then
630 minetest.record_protection_violation(pos,
631 sender:get_player_name())
634 local lockstr = lock and "locked " or ""
635 if fields and fields.text and fields.ok then
636 minetest.log("action", S("%s wrote \"%s\" to "..lockstr.."sign at %s"):format(
637 (sender:get_player_name() or ""),
639 minetest.pos_to_string(pos)
642 signs_lib.update_sign(pos, fields, sender:get_player_name())
644 signs_lib.update_sign(pos, fields)
649 minetest.register_node(":"..default_sign, {
650 description = S("Sign"),
651 inventory_image = default_sign_image,
652 wield_image = default_sign_image,
653 node_placement_prediction = "",
654 sunlight_propagates = true,
656 paramtype2 = "wallmounted",
657 drawtype = "nodebox",
658 node_box = signs_lib.regular_wall_sign_model.nodebox,
659 tiles = {"signs_wall_sign.png"},
660 groups = sign_groups,
662 on_place = function(itemstack, placer, pointed_thing)
663 return signs_lib.determine_sign_type(itemstack, placer, pointed_thing)
665 on_construct = function(pos)
666 signs_lib.construct_sign(pos)
668 on_destruct = function(pos)
669 signs_lib.destruct_sign(pos)
671 on_receive_fields = function(pos, formname, fields, sender)
672 signs_lib.receive_fields(pos, formname, fields, sender)
674 on_punch = function(pos, node, puncher)
675 signs_lib.update_sign(pos)
677 on_rotate = signs_lib.wallmounted_rotate
680 minetest.register_node(":signs:sign_yard", {
682 sunlight_propagates = true,
683 paramtype2 = "facedir",
684 drawtype = "nodebox",
685 node_box = signs_lib.yard_sign_model.nodebox,
688 fixed = {-0.4375, -0.5, -0.0625, 0.4375, 0.375, 0}
690 tiles = {"signs_top.png", "signs_bottom.png", "signs_side.png", "signs_side.png", "signs_back.png", "signs_front.png"},
691 groups = {choppy=2, dig_immediate=2},
694 on_construct = function(pos)
695 signs_lib.construct_sign(pos)
697 on_destruct = function(pos)
698 signs_lib.destruct_sign(pos)
700 on_receive_fields = function(pos, formname, fields, sender)
701 signs_lib.receive_fields(pos, formname, fields, sender)
703 on_punch = function(pos, node, puncher)
704 signs_lib.update_sign(pos)
708 minetest.register_node(":signs:sign_hanging", {
710 sunlight_propagates = true,
711 paramtype2 = "facedir",
712 drawtype = "nodebox",
713 node_box = signs_lib.hanging_sign_model.nodebox,
716 fixed = {-0.45, -0.275, -0.049, 0.45, 0.5, 0.049}
719 "signs_hanging_top.png",
720 "signs_hanging_bottom.png",
721 "signs_hanging_side.png",
722 "signs_hanging_side.png",
723 "signs_hanging_back.png",
724 "signs_hanging_front.png"
726 groups = {choppy=2, dig_immediate=2},
729 on_construct = function(pos)
730 signs_lib.construct_sign(pos)
732 on_destruct = function(pos)
733 signs_lib.destruct_sign(pos)
735 on_receive_fields = function(pos, formname, fields, sender)
736 signs_lib.receive_fields(pos, formname, fields, sender)
738 on_punch = function(pos, node, puncher)
739 signs_lib.update_sign(pos)
743 minetest.register_node(":signs:sign_post", {
745 sunlight_propagates = true,
746 paramtype2 = "facedir",
747 drawtype = "nodebox",
748 node_box = signs_lib.sign_post_model.nodebox,
750 "signs_post_top.png",
751 "signs_post_bottom.png",
752 "signs_post_side.png",
753 "signs_post_side.png",
754 "signs_post_back.png",
755 "signs_post_front.png",
757 groups = {choppy=2, dig_immediate=2},
761 { items = { default_sign }},
762 { items = { "default:fence_wood" }},
769 minetest.register_privilege("sign_editor", "Can edit all locked signs")
771 minetest.register_node(":locked_sign:sign_wall_locked", {
772 description = S("Sign"),
773 inventory_image = "signs_locked_inv.png",
774 wield_image = "signs_locked_inv.png",
775 node_placement_prediction = "",
776 sunlight_propagates = true,
778 paramtype2 = "wallmounted",
779 drawtype = "nodebox",
780 node_box = signs_lib.regular_wall_sign_model.nodebox,
781 tiles = { "signs_wall_sign_locked.png" },
782 groups = sign_groups,
783 on_place = function(itemstack, placer, pointed_thing)
784 return signs_lib.determine_sign_type(itemstack, placer, pointed_thing, true)
786 on_construct = function(pos)
787 signs_lib.construct_sign(pos, true)
789 on_destruct = function(pos)
790 signs_lib.destruct_sign(pos)
792 on_receive_fields = function(pos, formname, fields, sender)
793 local meta = minetest.get_meta(pos)
794 local owner = meta:get_string("owner")
795 local pname = sender:get_player_name() or ""
796 if pname ~= owner and pname ~= minetest.setting_get("name")
797 and not minetest.check_player_privs(pname, {sign_editor=true}) then
800 signs_lib.receive_fields(pos, formname, fields, sender, true)
802 on_punch = function(pos, node, puncher)
803 signs_lib.update_sign(pos)
805 can_dig = function(pos, player)
806 local meta = minetest.get_meta(pos)
807 local owner = meta:get_string("owner")
808 local pname = player:get_player_name()
809 return pname == owner or pname == minetest.setting_get("name")
810 or minetest.check_player_privs(pname, {sign_editor=true})
812 on_rotate = signs_lib.wallmounted_rotate
815 -- default metal sign, if defined
817 if minetest.registered_nodes["default:sign_wall_steel"] then
818 minetest.register_node(":"..default_sign_metal, {
819 description = S("Sign"),
820 inventory_image = default_sign_metal_image,
821 wield_image = default_sign_metal_image,
822 node_placement_prediction = "",
823 sunlight_propagates = true,
825 paramtype2 = "wallmounted",
826 drawtype = "nodebox",
827 node_box = signs_lib.regular_wall_sign_model.nodebox,
828 tiles = {"signs_wall_sign_metal.png"},
829 groups = sign_groups,
831 on_place = function(itemstack, placer, pointed_thing)
832 return signs_lib.determine_sign_type(itemstack, placer, pointed_thing)
834 on_construct = function(pos)
835 signs_lib.construct_sign(pos)
837 on_destruct = function(pos)
838 signs_lib.destruct_sign(pos)
840 on_receive_fields = function(pos, formname, fields, sender)
841 signs_lib.receive_fields(pos, formname, fields, sender)
843 on_punch = function(pos, node, puncher)
844 signs_lib.update_sign(pos)
846 on_rotate = signs_lib.wallmounted_rotate
850 -- metal, colored signs
851 if enable_colored_metal_signs then
852 local sign_colors = { "green", "yellow", "red", "white_red", "white_black", "orange", "blue", "brown" }
853 local sign_default_text_colors = { "f", "0", "f", "4", "0", "0", "f", "f" }
855 for i, color in ipairs(sign_colors) do
856 minetest.register_node(":signs:sign_wall_"..color, {
857 description = S("Sign ("..color..", metal)"),
858 inventory_image = "signs_"..color.."_inv.png",
859 wield_image = "signs_"..color.."_inv.png",
860 node_placement_prediction = "",
862 sunlight_propagates = true,
863 paramtype2 = "facedir",
864 drawtype = "nodebox",
865 node_box = signs_lib.metal_wall_sign_model.nodebox,
867 "signs_metal_tb.png",
868 "signs_metal_tb.png",
869 "signs_metal_sides.png",
870 "signs_metal_sides.png",
871 "signs_metal_back.png",
872 "signs_"..color.."_front.png"
874 default_color = sign_default_text_colors[i],
875 groups = sign_groups,
876 on_place = function(itemstack, placer, pointed_thing)
877 return signs_lib.determine_sign_type(itemstack, placer, pointed_thing)
879 on_construct = function(pos)
880 signs_lib.construct_sign(pos)
882 on_destruct = function(pos)
883 signs_lib.destruct_sign(pos)
885 on_receive_fields = function(pos, formname, fields, sender)
886 signs_lib.receive_fields(pos, formname, fields, sender)
888 on_punch = function(pos, node, puncher)
889 signs_lib.update_sign(pos)
895 local signs_text_on_activate
897 signs_text_on_activate = function(self)
898 local pos = self.object:getpos()
899 local meta = minetest.get_meta(pos)
900 local text = meta:get_string("text")
901 local new = (meta:get_int("__signslib_new_format") ~= 0)
903 text = trim_input(text)
904 set_obj_text(self.object, text, new, pos)
908 minetest.register_entity(":signs:text", {
909 collisionbox = { 0, 0, 0, 0, 0, 0 },
910 visual = "upright_sprite",
913 on_activate = signs_text_on_activate,
916 -- And the good stuff here! :-)
918 function signs_lib.register_fence_with_sign(fencename, fencewithsignname)
919 local def = minetest.registered_nodes[fencename]
920 local def_sign = minetest.registered_nodes[fencewithsignname]
921 if not (def and def_sign) then
922 minetest.log("warning", "[signs_lib] Attempt to register unknown node as fence")
925 def = signs_lib.table_copy(def)
926 def_sign = signs_lib.table_copy(def_sign)
927 fences_with_sign[fencename] = fencewithsignname
929 def_sign.on_place = function(itemstack, placer, pointed_thing, ...)
930 local node_above = minetest.get_node_or_nil(pointed_thing.above)
931 local node_under = minetest.get_node_or_nil(pointed_thing.under)
932 local def_above = node_above and minetest.registered_nodes[node_above.name]
933 local def_under = node_under and minetest.registered_nodes[node_under.name]
934 local fdir = minetest.dir_to_facedir(placer:get_look_dir())
935 local playername = placer:get_player_name()
937 if minetest.is_protected(pointed_thing.under, playername) then
938 minetest.record_protection_violation(pointed_thing.under, playername)
942 if minetest.is_protected(pointed_thing.above, playername) then
943 minetest.record_protection_violation(pointed_thing.above, playername)
947 if def_under and def_under.on_rightclick then
948 return def_under.on_rightclick(pointed_thing.under, node_under, placer, itemstack, pointed_thing) or itemstack
949 elseif def_under and def_under.buildable_to then
950 minetest.add_node(pointed_thing.under, {name = fencename, param2 = fdir})
951 if not signs_lib.expect_infinite_stacks then
952 itemstack:take_item()
954 placer:set_wielded_item(itemstack)
955 elseif def_above and def_above.buildable_to then
956 minetest.add_node(pointed_thing.above, {name = fencename, param2 = fdir})
957 if not signs_lib.expect_infinite_stacks then
958 itemstack:take_item()
960 placer:set_wielded_item(itemstack)
964 def_sign.on_construct = function(pos, ...)
965 signs_lib.construct_sign(pos)
967 def_sign.on_destruct = function(pos, ...)
968 signs_lib.destruct_sign(pos)
970 def_sign.on_receive_fields = function(pos, formname, fields, sender)
971 signs_lib.receive_fields(pos, formname, fields, sender)
973 def_sign.on_punch = function(pos, node, puncher, ...)
974 signs_lib.update_sign(pos)
976 local fencename = fencename
977 def_sign.after_dig_node = function(pos, node, ...)
978 node.name = fencename
979 minetest.add_node(pos, node)
981 def_sign.drop = default_sign
982 minetest.register_node(":"..fencename, def)
983 minetest.register_node(":"..fencewithsignname, def_sign)
984 table.insert(signs_lib.sign_node_list, fencewithsignname)
985 minetest.log("verbose", S("Registered %s and %s"):format(fencename, fencewithsignname))
990 minetest.register_alias("homedecor:fence_wood_with_sign", "signs:sign_post")
991 minetest.register_alias("sign_wall_locked", "locked_sign:sign_wall_locked")
993 signs_lib.register_fence_with_sign("default:fence_wood", "signs:sign_post")
995 -- restore signs' text after /clearobjects and the like, the next time
996 -- a block is reloaded by the server.
998 minetest.register_lbm({
999 nodenames = signs_lib.sign_node_list,
1000 name = "signs_lib:restore_sign_text",
1001 label = "Restore sign text",
1002 run_at_every_load = true,
1003 action = function(pos, node)
1004 signs_lib.update_sign(pos)
1010 minetest.register_craft({
1011 output = "locked_sign:sign_wall_locked",
1013 {"group:wood", "group:wood", "group:wood"},
1014 {"group:wood", "group:wood", "default:steel_ingot"},
1015 {"", "group:stick", ""},
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.setting_get("log_mods") then
1162 minetest.log("action", S("signs loaded"))