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 signs_lib.path = minetest.get_modpath(minetest.get_current_modname())
20 screwdriver = screwdriver or {}
22 -- Load support for intllib.
23 local S, NS = dofile(signs_lib.path .. "/intllib.lua")
27 dofile(signs_lib.path .. "/encoding.lua");
29 -- Initialize character texture cache
33 local wall_dir_change = {
43 signs_lib.wallmounted_rotate = function(pos, node, user, mode)
44 if minetest.is_protected(pos, user:get_player_name()) then
45 minetest.record_protection_violation(pos,
46 sender:get_player_name())
49 if mode ~= screwdriver.ROTATE_FACE then return false end
50 minetest.swap_node(pos, { name = node.name, param2 = wall_dir_change[node.param2 % 6] })
51 signs_lib.update_sign(pos,nil,nil,node)
55 signs_lib.facedir_rotate = function(pos, node, user, mode)
56 if minetest.is_protected(pos, user:get_player_name()) then
57 minetest.record_protection_violation(pos,
58 sender:get_player_name())
61 if mode ~= screwdriver.ROTATE_FACE then return false end
62 local newparam2 = (node.param2 %8) + 1
63 if newparam2 == 5 then
65 elseif newparam2 > 6 then
68 minetest.swap_node(pos, { name = node.name, param2 = newparam2 })
69 signs_lib.update_sign(pos,nil,nil,node)
73 signs_lib.facedir_rotate_simple = function(pos, node, user, mode)
74 if minetest.is_protected(pos, user:get_player_name()) then
75 minetest.record_protection_violation(pos,
76 sender:get_player_name())
79 if mode ~= screwdriver.ROTATE_FACE then return false end
80 local newparam2 = (node.param2 %8) + 1
81 if newparam2 > 3 then newparam2 = 0 end
82 minetest.swap_node(pos, { name = node.name, param2 = newparam2 })
83 signs_lib.update_sign(pos,nil,nil,node)
88 signs_lib.modpath = minetest.get_modpath("signs_lib")
90 local DEFAULT_TEXT_SCALE = {x=0.8, y=0.5}
92 signs_lib.regular_wall_sign_model = {
95 wall_side = { -0.5, -0.25, -0.4375, -0.4375, 0.375, 0.4375 },
96 wall_bottom = { -0.4375, -0.5, -0.25, 0.4375, -0.4375, 0.375 },
97 wall_top = { -0.4375, 0.4375, -0.375, 0.4375, 0.5, 0.25 }
102 {delta = { x = 0.41, y = 0.07, z = 0 }, yaw = math.pi / -2},
103 {delta = { x = -0.41, y = 0.07, z = 0 }, yaw = math.pi / 2},
104 {delta = { x = 0, y = 0.07, z = 0.41 }, yaw = 0},
105 {delta = { x = 0, y = 0.07, z = -0.41 }, yaw = math.pi},
109 signs_lib.metal_wall_sign_model = {
112 fixed = {-0.4375, -0.25, 0.4375, 0.4375, 0.375, 0.5}
115 {delta = { x = 0, y = 0.07, z = 0.41 }, yaw = 0},
116 {delta = { x = 0.41, y = 0.07, z = 0 }, yaw = math.pi / -2},
117 {delta = { x = 0, y = 0.07, z = -0.41 }, yaw = math.pi},
118 {delta = { x = -0.41, y = 0.07, z = 0 }, yaw = math.pi / 2},
122 signs_lib.yard_sign_model = {
126 {-0.4375, -0.25, -0.0625, 0.4375, 0.375, 0},
127 {-0.0625, -0.5, -0.0625, 0.0625, -0.1875, 0},
131 {delta = { x = 0, y = 0.07, z = -0.08 }, yaw = 0},
132 {delta = { x = -0.08, y = 0.07, z = 0 }, yaw = math.pi / -2},
133 {delta = { x = 0, y = 0.07, z = 0.08 }, yaw = math.pi},
134 {delta = { x = 0.08, y = 0.07, z = 0 }, yaw = math.pi / 2},
138 signs_lib.hanging_sign_model = {
142 {-0.4375, -0.3125, -0.0625, 0.4375, 0.3125, 0},
143 {-0.4375, 0.25, -0.03125, 0.4375, 0.5, -0.03125},
147 {delta = { x = 0, y = -0.02, z = -0.08 }, yaw = 0},
148 {delta = { x = -0.08, y = -0.02, z = 0 }, yaw = math.pi / -2},
149 {delta = { x = 0, y = -0.02, z = 0.08 }, yaw = math.pi},
150 {delta = { x = 0.08, y = -0.02, z = 0 }, yaw = math.pi / 2},
154 signs_lib.sign_post_model = {
158 {-0.4375, -0.25, -0.1875, 0.4375, 0.375, -0.125},
159 {-0.125, -0.5, -0.125, 0.125, 0.5, 0.125},
163 {delta = { x = 0, y = 0.07, z = -0.2 }, yaw = 0},
164 {delta = { x = -0.2, y = 0.07, z = 0 }, yaw = math.pi / -2},
165 {delta = { x = 0, y = 0.07, z = 0.2 }, yaw = math.pi},
166 {delta = { x = 0.2, y = 0.07, z = 0 }, yaw = math.pi / 2},
170 -- the list of standard sign nodes
172 local default_sign = "default:sign_wall_wood"
173 local default_sign_image = "default_sign_wood.png"
175 local default_sign_metal = "default:sign_wall_steel"
176 local default_sign_metal_image = "default_sign_steel.png"
178 signs_lib.sign_node_list = {
182 "signs:sign_hanging",
183 "signs:sign_wall_green",
184 "signs:sign_wall_yellow",
185 "signs:sign_wall_red",
186 "signs:sign_wall_white_red",
187 "signs:sign_wall_white_black",
188 "signs:sign_wall_orange",
189 "signs:sign_wall_blue",
190 "signs:sign_wall_brown",
191 "locked_sign:sign_wall_locked"
196 function signs_lib.table_copy(t)
198 for k, v in pairs(t) do
199 if type(v) == "table" then
200 nt[k] = signs_lib.table_copy(v)
210 if not minetest.settings:get_bool("creative_mode") then
211 signs_lib.expect_infinite_stacks = false
213 signs_lib.expect_infinite_stacks = true
218 -- Path to the textures.
219 local TP = signs_lib.path .. "/textures"
220 -- Font file formatter
221 local CHAR_FILE = "%s_%02x.png"
223 local CHAR_PATH = TP .. "/" .. CHAR_FILE
226 local font_name = "hdf"
228 -- Lots of overkill here. KISS advocates, go away, shoo! ;) -- kaeza
230 local PNG_HDR = string.char(0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A)
232 -- check if a file does exist
233 -- to avoid reopening file after checking again
234 -- pass TRUE as second argument
235 function file_exists(name, return_handle, mode)
237 local f = io.open(name, mode)
239 if (return_handle) then
249 -- Read the image size from a PNG file.
250 -- Returns image_w, image_h.
251 -- Only the LSB is read from each field!
252 local function read_image_size(filename)
253 local f = file_exists(filename, true, "rb")
254 -- file might not exist (don't crash the game)
259 local hdr = f:read(string.len(PNG_HDR))
260 if hdr ~= PNG_HDR then
269 return ws:byte(), hs:byte()
272 -- Set by build_char_db()
275 local COLORBGW, COLORBGH
277 -- Size of the canvas, in characters.
278 -- Please note that CHARS_PER_LINE is multiplied by the average character
279 -- width to get the total width of the canvas, so for proportional fonts,
280 -- either more or fewer characters may fit on a line.
281 local CHARS_PER_LINE = 30
282 local NUMBER_OF_LINES = 6
284 -- 6 rows, max 80 chars per, plus a bit of fudge to
285 -- avoid excess trimming (e.g. due to color codes)
287 local MAX_INPUT_CHARS = 600
289 -- This holds the individual character widths.
290 -- Indexed by the actual character (e.g. charwidth["A"])
293 -- helper functions to trim sign text input/output
295 local function trim_input(text)
296 return text:sub(1, math.min(MAX_INPUT_CHARS, text:len()))
299 local function build_char_db()
303 -- To calculate average char width.
304 local total_width = 0
308 local w, h = read_image_size(CHAR_PATH:format(font_name, c))
310 local ch = string.char(c)
312 total_width = total_width + w
313 char_count = char_count + 1
317 COLORBGW, COLORBGH = read_image_size(TP.."/slc_n.png")
318 assert(COLORBGW and COLORBGH, "error reading bg dimensions")
319 LINE_HEIGHT = COLORBGH
321 -- XXX: Is there a better way to calc this?
322 SIGN_WIDTH = math.floor((total_width / char_count) * CHARS_PER_LINE)
326 local sign_groups = {choppy=2, dig_immediate=2}
328 local fences_with_sign = { }
330 -- some local helper functions
332 local function split_lines_and_words_old(text)
335 if not text then return end
336 for word in text:gmatch("%S+") do
338 table.insert(lines, line)
339 if #lines >= NUMBER_OF_LINES then break end
341 elseif word == "\\|" then
342 table.insert(line, "|")
344 table.insert(line, word)
347 table.insert(lines, line)
351 local function split_lines_and_words(text)
352 if not text then return end
353 text = string.gsub(text, "@KEYWORD", current_keyword)
355 for _, line in ipairs(text:split("\n")) do
356 table.insert(lines, line:split(" "))
361 local math_max = math.max
363 local function fill_line(x, y, w, c)
366 for xx = 0, math.max(0, w), COLORBGW do
367 table.insert(tex, (":%d,%d=slc_%s.png"):format(x + xx, y, c))
369 return table.concat(tex)
372 -- make char texture file name
373 -- if texture file does not exist use fallback texture instead
374 local function char_tex(font_name, ch)
375 if ctexcache[font_name..ch] then
376 return ctexcache[font_name..ch], true
379 local exists, tex = file_exists(CHAR_PATH:format(font_name, c))
380 if exists and c ~= 14 then
381 tex = CHAR_FILE:format(font_name, c)
383 tex = CHAR_FILE:format(font_name, 0x0)
385 ctexcache[font_name..ch] = tex
390 local function make_line_texture(line, lineno, pos)
396 local n = minetest.registered_nodes[minetest.get_node(pos).name]
397 local default_color = n.default_color or 0
399 local cur_color = tonumber(default_color, 16)
401 -- We check which chars are available here.
402 for word_i, word in ipairs(line) do
405 word = string.gsub(word, "%^[12345678abcdefgh]", {
406 ["^1"] = string.char(0x81),
407 ["^2"] = string.char(0x82),
408 ["^3"] = string.char(0x83),
409 ["^4"] = string.char(0x84),
410 ["^5"] = string.char(0x85),
411 ["^6"] = string.char(0x86),
412 ["^7"] = string.char(0x87),
413 ["^8"] = string.char(0x88),
414 ["^a"] = string.char(0x8a),
415 ["^b"] = string.char(0x8b),
416 ["^c"] = string.char(0x8c),
417 ["^d"] = string.char(0x8d),
418 ["^e"] = string.char(0x8e),
419 ["^f"] = string.char(0x8f),
420 ["^g"] = string.char(0x90),
421 ["^h"] = string.char(0x91)
426 local c = word:sub(i, i)
428 local cc = tonumber(word:sub(i+1, i+1), 16)
434 local w = charwidth[c]
436 width = width + w + 1
437 if width >= (SIGN_WIDTH - charwidth[" "]) then
440 maxw = math_max(width, maxw)
442 if #chars < MAX_INPUT_CHARS then
443 table.insert(chars, {
445 tex = char_tex(font_name, c),
446 col = ("%X"):format(cur_color),
449 ch_offs = ch_offs + w
454 width = width + charwidth[" "] + 1
455 maxw = math_max(width, maxw)
456 table.insert(words, { chars=chars, w=ch_offs })
459 -- Okay, we actually build the "line texture" here.
463 local start_xpos = math.floor((SIGN_WIDTH - maxw) / 2)
465 local xpos = start_xpos
466 local ypos = (LINE_HEIGHT * lineno)
470 for word_i, word in ipairs(words) do
471 local xoffs = (xpos - start_xpos)
472 if (xoffs > 0) and ((xoffs + word.w) > maxw) then
473 table.insert(texture, fill_line(xpos, ypos, maxw, "n"))
475 ypos = ypos + LINE_HEIGHT
477 if lineno >= NUMBER_OF_LINES then break end
478 table.insert(texture, fill_line(xpos, ypos, maxw, cur_color))
480 for ch_i, ch in ipairs(word.chars) do
481 if ch.col ~= cur_color then
483 table.insert(texture, fill_line(xpos + ch.off, ypos, maxw, cur_color))
485 table.insert(texture, (":%d,%d=%s"):format(xpos + ch.off, ypos, ch.tex))
489 (":%d,%d="):format(xpos + word.w, ypos) .. char_tex(font_name, " ")
491 xpos = xpos + word.w + charwidth[" "]
492 if xpos >= (SIGN_WIDTH + charwidth[" "]) then break end
495 table.insert(texture, fill_line(xpos, ypos, maxw, "n"))
496 table.insert(texture, fill_line(start_xpos, ypos + LINE_HEIGHT, maxw, "n"))
498 return table.concat(texture), lineno
501 local function make_sign_texture(lines, pos)
502 local texture = { ("[combine:%dx%d"):format(SIGN_WIDTH, LINE_HEIGHT * NUMBER_OF_LINES) }
505 if lineno >= NUMBER_OF_LINES then break end
506 local linetex, ln = make_line_texture(lines[i], lineno, pos)
507 table.insert(texture, linetex)
510 table.insert(texture, "^[makealpha:0,0,0")
511 return table.concat(texture, "")
514 local function set_obj_text(obj, text, new, pos)
515 local split = new and split_lines_and_words or split_lines_and_words_old
516 local text_ansi = Utf8ToAnsi(text)
517 local n = minetest.registered_nodes[minetest.get_node(pos).name]
518 local text_scale = (n and n.text_scale) or DEFAULT_TEXT_SCALE
520 textures={make_sign_texture(split(text_ansi), pos)},
521 visual_size = text_scale,
525 signs_lib.construct_sign = function(pos, locked)
526 local meta = minetest.get_meta(pos)
530 "textarea[0,-0.3;6.5,3;text;;${text}]"..
531 "button_exit[2,3.4;2,1;ok;"..S("Write").."]"..
532 "background[-0.5,-0.5;7,5;bg_signs_lib.jpg]")
533 meta:set_string("infotext", "")
536 signs_lib.destruct_sign = function(pos)
537 local objects = minetest.get_objects_inside_radius(pos, 0.5)
538 for _, v in ipairs(objects) do
539 local e = v:get_luaentity()
540 if e and e.name == "signs:text" then
546 local function make_infotext(text)
547 text = trim_input(text)
548 local lines = split_lines_and_words(text) or {}
550 for _, line in ipairs(lines) do
551 table.insert(lines2, (table.concat(line, " "):gsub("#[0-9a-fA-F]", ""):gsub("##", "#")))
553 return table.concat(lines2, "\n")
556 signs_lib.update_sign = function(pos, fields, owner, node)
558 -- First, check if the interact keyword from CWz's mod is being set,
559 -- or has been changed since the last restart...
561 local meta = minetest.get_meta(pos)
562 local stored_text = meta:get_string("text") or ""
563 current_keyword = rawget(_G, "mki_interact_keyword") or current_keyword
565 if fields then -- ...we're editing the sign.
566 if fields.text and string.find(dump(fields.text), "@KEYWORD") then
567 meta:set_string("keyword", current_keyword)
569 meta:set_string("keyword", nil)
571 elseif string.find(dump(stored_text), "@KEYWORD") then -- we need to check if the password is being set/changed
573 local stored_keyword = meta:get_string("keyword")
574 if stored_keyword and stored_keyword ~= "" and stored_keyword ~= current_keyword then
575 signs_lib.destruct_sign(pos)
576 meta:set_string("keyword", current_keyword)
578 if owner then ownstr = S("Locked sign, owned by @1\n", owner) end
579 meta:set_string("infotext", ownstr..string.gsub(make_infotext(stored_text), "@KEYWORD", current_keyword).." ")
587 fields.text = trim_input(fields.text)
590 if owner then ownstr = S("Locked sign, owned by @1\n", owner) end
592 meta:set_string("infotext", ownstr..string.gsub(make_infotext(fields.text), "@KEYWORD", current_keyword).." ")
593 meta:set_string("text", fields.text)
595 meta:set_int("__signslib_new_format", 1)
598 new = (meta:get_int("__signslib_new_format") ~= 0)
600 signs_lib.destruct_sign(pos)
601 local text = meta:get_string("text")
602 if text == nil or text == "" then return end
604 local signnode = node or minetest.get_node(pos)
605 local signname = signnode.name
606 local textpos = minetest.registered_nodes[signname].textpos
608 sign_info = textpos[minetest.get_node(pos).param2 + 1]
609 elseif signnode.name == "signs:sign_yard" then
610 sign_info = signs_lib.yard_sign_model.textpos[minetest.get_node(pos).param2 + 1]
611 elseif signnode.name == "signs:sign_hanging" then
612 sign_info = signs_lib.hanging_sign_model.textpos[minetest.get_node(pos).param2 + 1]
613 elseif string.find(signnode.name, "sign_wall") then
614 if signnode.name == default_sign
615 or signnode.name == default_sign_metal
616 or signnode.name == "locked_sign:sign_wall_locked" then
617 sign_info = signs_lib.regular_wall_sign_model.textpos[minetest.get_node(pos).param2 + 1]
619 sign_info = signs_lib.metal_wall_sign_model.textpos[minetest.get_node(pos).param2 + 1]
621 else -- ...it must be a sign on a fence post.
622 sign_info = signs_lib.sign_post_model.textpos[minetest.get_node(pos).param2 + 1]
624 if sign_info == nil then
627 local text = minetest.add_entity({x = pos.x + sign_info.delta.x,
628 y = pos.y + sign_info.delta.y,
629 z = pos.z + sign_info.delta.z}, "signs:text")
630 text:setyaw(sign_info.yaw)
633 -- What kind of sign do we need to place, anyway?
635 function signs_lib.determine_sign_type(itemstack, placer, pointed_thing, locked)
637 name = minetest.get_node(pointed_thing.under).name
638 if fences_with_sign[name] then
639 if minetest.is_protected(pointed_thing.under, placer:get_player_name()) then
640 minetest.record_protection_violation(pointed_thing.under,
641 placer:get_player_name())
645 name = minetest.get_node(pointed_thing.above).name
646 local def = minetest.registered_nodes[name]
647 if not def.buildable_to then
650 if minetest.is_protected(pointed_thing.above, placer:get_player_name()) then
651 minetest.record_protection_violation(pointed_thing.above,
652 placer:get_player_name())
657 local node=minetest.get_node(pointed_thing.under)
659 if minetest.registered_nodes[node.name] and
660 minetest.registered_nodes[node.name].on_rightclick and
661 not placer:get_player_control().sneak then
662 return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack, pointed_thing)
664 local above = pointed_thing.above
665 local under = pointed_thing.under
666 local dir = {x = under.x - above.x,
667 y = under.y - above.y,
668 z = under.z - above.z}
670 local wdir = minetest.dir_to_wallmounted(dir)
672 local placer_pos = placer:getpos()
675 x = above.x - placer_pos.x,
676 y = above.y - placer_pos.y,
677 z = above.z - placer_pos.z
680 local finalpos = above
682 local fdir = minetest.dir_to_facedir(dir)
683 local pt_name = minetest.get_node(under).name
684 local signname = itemstack:get_name()
686 if fences_with_sign[pt_name] and signname == default_sign then
687 minetest.add_node(under, {name = fences_with_sign[pt_name], param2 = fdir})
689 elseif wdir == 0 and signname == default_sign then
690 minetest.add_node(above, {name = "signs:sign_hanging", param2 = fdir})
691 elseif wdir == 1 and signname == default_sign then
692 minetest.add_node(above, {name = "signs:sign_yard", param2 = fdir})
693 elseif signname == default_sign
694 or signname == default_sign_metal
695 or signname == "locked_sign:sign_wall_locked" then
696 minetest.add_node(above, {name = signname, param2 = wdir })
698 minetest.add_node(above, {name = signname, param2 = fdir}) -- it must be a colored metal sign
702 local meta = minetest.get_meta(finalpos)
703 local owner = placer:get_player_name()
704 meta:set_string("owner", owner)
707 if not signs_lib.expect_infinite_stacks then
708 itemstack:take_item()
714 function signs_lib.receive_fields(pos, formname, fields, sender, lock)
715 if minetest.is_protected(pos, sender:get_player_name()) then
716 minetest.record_protection_violation(pos,
717 sender:get_player_name())
720 local lockstr = lock and S("locked ") or ""
721 if fields and fields.text and fields.ok then
722 minetest.log("action", S("@1 wrote \"@2\" to @3sign at @4",
723 (sender:get_player_name() or ""),
724 fields.text:gsub('\\', '\\\\'):gsub("\n", "\\n"),
726 minetest.pos_to_string(pos)
729 signs_lib.update_sign(pos, fields, sender:get_player_name())
731 signs_lib.update_sign(pos, fields)
736 minetest.register_node(":"..default_sign, {
737 description = S("Sign"),
738 inventory_image = default_sign_image,
739 wield_image = default_sign_image,
740 node_placement_prediction = "",
741 sunlight_propagates = true,
743 paramtype2 = "wallmounted",
744 drawtype = "nodebox",
745 node_box = signs_lib.regular_wall_sign_model.nodebox,
746 tiles = {"signs_wall_sign.png"},
747 groups = sign_groups,
749 on_place = function(itemstack, placer, pointed_thing)
750 return signs_lib.determine_sign_type(itemstack, placer, pointed_thing)
752 on_construct = function(pos)
753 signs_lib.construct_sign(pos)
755 on_destruct = function(pos)
756 signs_lib.destruct_sign(pos)
758 on_receive_fields = function(pos, formname, fields, sender)
759 signs_lib.receive_fields(pos, formname, fields, sender)
761 on_punch = function(pos, node, puncher)
762 signs_lib.update_sign(pos,nil,nil,node)
764 on_rotate = signs_lib.wallmounted_rotate
767 minetest.register_node(":signs:sign_yard", {
769 sunlight_propagates = true,
770 paramtype2 = "facedir",
771 drawtype = "nodebox",
772 node_box = signs_lib.yard_sign_model.nodebox,
775 fixed = {-0.4375, -0.5, -0.0625, 0.4375, 0.375, 0}
777 tiles = {"signs_top.png", "signs_bottom.png", "signs_side.png", "signs_side.png", "signs_back.png", "signs_front.png"},
778 groups = {choppy=2, dig_immediate=2},
781 on_construct = function(pos)
782 signs_lib.construct_sign(pos)
784 on_destruct = function(pos)
785 signs_lib.destruct_sign(pos)
787 on_receive_fields = function(pos, formname, fields, sender)
788 signs_lib.receive_fields(pos, formname, fields, sender)
790 on_punch = function(pos, node, puncher)
791 signs_lib.update_sign(pos,nil,nil,node)
793 on_rotate = signs_lib.facedir_rotate_simple
797 minetest.register_node(":signs:sign_hanging", {
799 sunlight_propagates = true,
800 paramtype2 = "facedir",
801 drawtype = "nodebox",
802 node_box = signs_lib.hanging_sign_model.nodebox,
805 fixed = {-0.45, -0.275, -0.049, 0.45, 0.5, 0.049}
808 "signs_hanging_top.png",
809 "signs_hanging_bottom.png",
810 "signs_hanging_side.png",
811 "signs_hanging_side.png",
812 "signs_hanging_back.png",
813 "signs_hanging_front.png"
815 groups = {choppy=2, dig_immediate=2},
818 on_construct = function(pos)
819 signs_lib.construct_sign(pos)
821 on_destruct = function(pos)
822 signs_lib.destruct_sign(pos)
824 on_receive_fields = function(pos, formname, fields, sender)
825 signs_lib.receive_fields(pos, formname, fields, sender)
827 on_punch = function(pos, node, puncher)
828 signs_lib.update_sign(pos,nil,nil,node)
830 on_rotate = signs_lib.facedir_rotate_simple
833 minetest.register_node(":signs:sign_post", {
835 sunlight_propagates = true,
836 paramtype2 = "facedir",
837 drawtype = "nodebox",
838 node_box = signs_lib.sign_post_model.nodebox,
840 "signs_post_top.png",
841 "signs_post_bottom.png",
842 "signs_post_side.png",
843 "signs_post_side.png",
844 "signs_post_back.png",
845 "signs_post_front.png",
847 groups = {choppy=2, dig_immediate=2},
851 { items = { default_sign }},
852 { items = { "default:fence_wood" }},
855 on_rotate = signs_lib.facedir_rotate_simple
860 minetest.register_privilege("sign_editor", S("Can edit all locked signs"))
862 minetest.register_node(":locked_sign:sign_wall_locked", {
863 description = S("Locked Sign"),
864 inventory_image = "signs_locked_inv.png",
865 wield_image = "signs_locked_inv.png",
866 node_placement_prediction = "",
867 sunlight_propagates = true,
869 paramtype2 = "wallmounted",
870 drawtype = "nodebox",
871 node_box = signs_lib.regular_wall_sign_model.nodebox,
872 tiles = { "signs_wall_sign_locked.png" },
873 groups = sign_groups,
874 on_place = function(itemstack, placer, pointed_thing)
875 return signs_lib.determine_sign_type(itemstack, placer, pointed_thing, true)
877 on_construct = function(pos)
878 signs_lib.construct_sign(pos, true)
880 on_destruct = function(pos)
881 signs_lib.destruct_sign(pos)
883 on_receive_fields = function(pos, formname, fields, sender)
884 local meta = minetest.get_meta(pos)
885 local owner = meta:get_string("owner")
886 local pname = sender:get_player_name() or ""
887 if pname ~= owner and pname ~= minetest.settings:get("name")
888 and not minetest.check_player_privs(pname, {sign_editor=true}) then
891 signs_lib.receive_fields(pos, formname, fields, sender, true)
893 on_punch = function(pos, node, puncher)
894 signs_lib.update_sign(pos,nil,nil,node)
896 can_dig = function(pos, player)
897 local meta = minetest.get_meta(pos)
898 local owner = meta:get_string("owner")
899 local pname = player:get_player_name()
900 return pname == owner or pname == minetest.settings:get("name")
901 or minetest.check_player_privs(pname, {sign_editor=true})
903 on_rotate = function(pos, node, user, mode)
904 local meta = minetest.get_meta(pos)
905 local owner = meta:get_string("owner")
906 if owner == user:get_player_name() then
907 signs_lib.wallmounted_rotate(pos, node, user, mode)
914 -- default metal sign
916 minetest.register_node(":"..default_sign_metal, {
917 description = S("Sign"),
918 inventory_image = default_sign_metal_image,
919 wield_image = default_sign_metal_image,
920 node_placement_prediction = "",
921 sunlight_propagates = true,
923 paramtype2 = "wallmounted",
924 drawtype = "nodebox",
925 node_box = signs_lib.regular_wall_sign_model.nodebox,
926 tiles = {"signs_wall_sign_metal.png"},
927 groups = sign_groups,
928 on_place = function(itemstack, placer, pointed_thing)
929 return signs_lib.determine_sign_type(itemstack, placer, pointed_thing, true)
931 on_construct = function(pos)
932 signs_lib.construct_sign(pos, true)
934 on_destruct = function(pos)
935 signs_lib.destruct_sign(pos)
937 on_receive_fields = function(pos, formname, fields, sender)
938 local meta = minetest.get_meta(pos)
939 local owner = meta:get_string("owner")
940 local pname = sender:get_player_name() or ""
941 if pname ~= owner and pname ~= minetest.settings:get("name")
942 and not minetest.check_player_privs(pname, {sign_editor=true}) then
945 signs_lib.receive_fields(pos, formname, fields, sender, true)
947 on_punch = function(pos, node, puncher)
948 signs_lib.update_sign(pos,nil,nil,node)
950 can_dig = function(pos, player)
951 local meta = minetest.get_meta(pos)
952 local owner = meta:get_string("owner")
953 local pname = player:get_player_name()
954 return pname == owner or pname == minetest.settings:get("name")
955 or minetest.check_player_privs(pname, {sign_editor=true})
957 on_rotate = function(pos, node, user, mode)
958 local meta = minetest.get_meta(pos)
959 local owner = meta:get_string("owner")
960 if owner == user:get_player_name() then
961 signs_lib.wallmounted_rotate(pos, node, user, mode)
968 -- metal, colored signs
969 if enable_colored_metal_signs then
970 -- array : color, translated color, default text color
971 local sign_colors = {
972 {"green", S("green"), "f"},
973 {"yellow", S("yellow"), "0"},
974 {"red", S("red"), "f"},
975 {"white_red", S("white_red"), "4"},
976 {"white_black", S("white_black"), "0"},
977 {"orange", S("orange"), "0"},
978 {"blue", S("blue"), "f"},
979 {"brown", S("brown"), "f"},
982 for i, color in ipairs(sign_colors) do
983 minetest.register_node(":signs:sign_wall_"..color[1], {
984 description = S("Sign (@1, metal)", color[2]),
985 inventory_image = "signs_"..color[1].."_inv.png",
986 wield_image = "signs_"..color[1].."_inv.png",
987 node_placement_prediction = "",
989 sunlight_propagates = true,
990 paramtype2 = "facedir",
991 drawtype = "nodebox",
992 node_box = signs_lib.metal_wall_sign_model.nodebox,
994 "signs_metal_tb.png",
995 "signs_metal_tb.png",
996 "signs_metal_sides.png",
997 "signs_metal_sides.png",
998 "signs_metal_back.png",
999 "signs_"..color[1].."_front.png"
1001 default_color = color[3],
1002 groups = sign_groups,
1003 on_place = function(itemstack, placer, pointed_thing)
1004 return signs_lib.determine_sign_type(itemstack, placer, pointed_thing)
1006 on_construct = function(pos)
1007 signs_lib.construct_sign(pos)
1009 on_destruct = function(pos)
1010 signs_lib.destruct_sign(pos)
1012 on_receive_fields = function(pos, formname, fields, sender)
1013 signs_lib.receive_fields(pos, formname, fields, sender)
1015 on_punch = function(pos, node, puncher)
1016 signs_lib.update_sign(pos,nil,nil,node)
1018 on_rotate = signs_lib.facedir_rotate
1023 local signs_text_on_activate
1025 signs_text_on_activate = function(self)
1026 local pos = self.object:getpos()
1027 local meta = minetest.get_meta(pos)
1028 local text = meta:get_string("text")
1029 local new = (meta:get_int("__signslib_new_format") ~= 0)
1030 if text and minetest.registered_nodes[minetest.get_node(pos).name] then
1031 text = trim_input(text)
1032 set_obj_text(self.object, text, new, pos)
1036 minetest.register_entity(":signs:text", {
1037 collisionbox = { 0, 0, 0, 0, 0, 0 },
1038 visual = "upright_sprite",
1041 on_activate = signs_text_on_activate,
1044 -- And the good stuff here! :-)
1046 function signs_lib.register_fence_with_sign(fencename, fencewithsignname)
1047 local def = minetest.registered_nodes[fencename]
1048 local def_sign = minetest.registered_nodes[fencewithsignname]
1049 if not (def and def_sign) then
1050 minetest.log("warning", "[signs_lib] "..S("Attempt to register unknown node as fence"))
1053 def = signs_lib.table_copy(def)
1054 def_sign = signs_lib.table_copy(def_sign)
1055 fences_with_sign[fencename] = fencewithsignname
1057 def_sign.on_place = function(itemstack, placer, pointed_thing, ...)
1058 local node_above = minetest.get_node_or_nil(pointed_thing.above)
1059 local node_under = minetest.get_node_or_nil(pointed_thing.under)
1060 local def_above = node_above and minetest.registered_nodes[node_above.name]
1061 local def_under = node_under and minetest.registered_nodes[node_under.name]
1062 local fdir = minetest.dir_to_facedir(placer:get_look_dir())
1063 local playername = placer:get_player_name()
1065 if minetest.is_protected(pointed_thing.under, playername) then
1066 minetest.record_protection_violation(pointed_thing.under, playername)
1070 if minetest.is_protected(pointed_thing.above, playername) then
1071 minetest.record_protection_violation(pointed_thing.above, playername)
1075 if def_under and def_under.on_rightclick then
1076 return def_under.on_rightclick(pointed_thing.under, node_under, placer, itemstack, pointed_thing) or itemstack
1077 elseif def_under and def_under.buildable_to then
1078 minetest.add_node(pointed_thing.under, {name = fencename, param2 = fdir})
1079 if not signs_lib.expect_infinite_stacks then
1080 itemstack:take_item()
1082 placer:set_wielded_item(itemstack)
1083 elseif def_above and def_above.buildable_to then
1084 minetest.add_node(pointed_thing.above, {name = fencename, param2 = fdir})
1085 if not signs_lib.expect_infinite_stacks then
1086 itemstack:take_item()
1088 placer:set_wielded_item(itemstack)
1092 def_sign.on_construct = function(pos, ...)
1093 signs_lib.construct_sign(pos)
1095 def_sign.on_destruct = function(pos, ...)
1096 signs_lib.destruct_sign(pos)
1098 def_sign.on_receive_fields = function(pos, formname, fields, sender)
1099 signs_lib.receive_fields(pos, formname, fields, sender)
1101 def_sign.on_punch = function(pos, node, puncher, ...)
1102 signs_lib.update_sign(pos,nil,nil,node)
1104 local fencename = fencename
1105 def_sign.after_dig_node = function(pos, node, ...)
1106 node.name = fencename
1107 minetest.add_node(pos, node)
1109 def_sign.on_rotate = signs_lib.facedir_rotate_simple
1111 def_sign.drop = default_sign
1112 minetest.register_node(":"..fencename, def)
1113 minetest.register_node(":"..fencewithsignname, def_sign)
1114 table.insert(signs_lib.sign_node_list, fencewithsignname)
1115 minetest.log("verbose", S("Registered @1 and @2", fencename, fencewithsignname))
1120 minetest.register_alias("homedecor:fence_wood_with_sign", "signs:sign_post")
1121 minetest.register_alias("sign_wall_locked", "locked_sign:sign_wall_locked")
1123 signs_lib.register_fence_with_sign("default:fence_wood", "signs:sign_post")
1125 -- restore signs' text after /clearobjects and the like, the next time
1126 -- a block is reloaded by the server.
1128 minetest.register_lbm({
1129 nodenames = signs_lib.sign_node_list,
1130 name = "signs_lib:restore_sign_text",
1131 label = "Restore sign text",
1132 run_at_every_load = true,
1133 action = function(pos, node)
1134 signs_lib.update_sign(pos,nil,nil,node)
1140 minetest.register_craft({
1141 output = "locked_sign:sign_wall_locked",
1144 {"basic_materials:padlock"},
1148 -- craft recipes for the metal signs
1149 if enable_colored_metal_signs then
1151 minetest.register_craft( {
1152 output = "signs:sign_wall_green",
1154 { "dye:dark_green", "dye:white", "dye:dark_green" },
1155 { "", default_sign_metal, "" }
1159 minetest.register_craft( {
1160 output = "signs:sign_wall_green 2",
1162 { "dye:dark_green", "dye:white", "dye:dark_green" },
1163 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1167 minetest.register_craft( {
1168 output = "signs:sign_wall_yellow",
1170 { "dye:yellow", "dye:black", "dye:yellow" },
1171 { "", default_sign_metal, "" }
1175 minetest.register_craft( {
1176 output = "signs:sign_wall_yellow 2",
1178 { "dye:yellow", "dye:black", "dye:yellow" },
1179 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1183 minetest.register_craft( {
1184 output = "signs:sign_wall_red",
1186 { "dye:red", "dye:white", "dye:red" },
1187 { "", default_sign_metal, "" }
1191 minetest.register_craft( {
1192 output = "signs:sign_wall_red 2",
1194 { "dye:red", "dye:white", "dye:red" },
1195 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1199 minetest.register_craft( {
1200 output = "signs:sign_wall_white_red",
1202 { "dye:white", "dye:red", "dye:white" },
1203 { "", default_sign_metal, "" }
1207 minetest.register_craft( {
1208 output = "signs:sign_wall_white_red 2",
1210 { "dye:white", "dye:red", "dye:white" },
1211 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1215 minetest.register_craft( {
1216 output = "signs:sign_wall_white_black",
1218 { "dye:white", "dye:black", "dye:white" },
1219 { "", default_sign_metal, "" }
1223 minetest.register_craft( {
1224 output = "signs:sign_wall_white_black 2",
1226 { "dye:white", "dye:black", "dye:white" },
1227 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1231 minetest.register_craft( {
1232 output = "signs:sign_wall_orange",
1234 { "dye:orange", "dye:black", "dye:orange" },
1235 { "", default_sign_metal, "" }
1239 minetest.register_craft( {
1240 output = "signs:sign_wall_orange 2",
1242 { "dye:orange", "dye:black", "dye:orange" },
1243 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1247 minetest.register_craft( {
1248 output = "signs:sign_wall_blue",
1250 { "dye:blue", "dye:white", "dye:blue" },
1251 { "", default_sign_metal, "" }
1255 minetest.register_craft( {
1256 output = "signs:sign_wall_blue 2",
1258 { "dye:blue", "dye:white", "dye:blue" },
1259 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1263 minetest.register_craft( {
1264 output = "signs:sign_wall_brown",
1266 { "dye:brown", "dye:white", "dye:brown" },
1267 { "", default_sign_metal, "" }
1271 minetest.register_craft( {
1272 output = "signs:sign_wall_brown 2",
1274 { "dye:brown", "dye:white", "dye:brown" },
1275 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1280 if minetest.settings:get("log_mods") then
1281 minetest.log("action", S("[MOD] signs loaded"))