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 signs_lib.sign_node_list = {
173 "default:sign_wall_wood",
174 "default:sign_wall_steel",
176 "signs:sign_hanging",
177 "signs:sign_wall_green",
178 "signs:sign_wall_yellow",
179 "signs:sign_wall_red",
180 "signs:sign_wall_white_red",
181 "signs:sign_wall_white_black",
182 "signs:sign_wall_orange",
183 "signs:sign_wall_blue",
184 "signs:sign_wall_brown",
185 "locked_sign:sign_wall_locked"
188 local default_sign, default_sign_image
190 -- Default sign was renamed in 0.4.14. Support both & old versions.
191 if minetest.registered_nodes["default:sign_wall_wood"] then
192 default_sign = "default:sign_wall_wood"
193 default_sign_image = "default_sign_wood.png"
195 default_sign = "default:sign_wall"
196 default_sign_image = "default_sign_wall.png"
199 default_sign_metal = "default:sign_wall_steel"
200 default_sign_metal_image = "default_sign_steel.png"
204 function signs_lib.table_copy(t)
206 for k, v in pairs(t) do
207 if type(v) == "table" then
208 nt[k] = signs_lib.table_copy(v)
218 if not minetest.settings:get_bool("creative_mode") then
219 signs_lib.expect_infinite_stacks = false
221 signs_lib.expect_infinite_stacks = true
226 -- Path to the textures.
227 local TP = signs_lib.path .. "/textures"
228 -- Font file formatter
229 local CHAR_FILE = "%s_%02x.png"
231 local CHAR_PATH = TP .. "/" .. CHAR_FILE
234 local font_name = "hdf"
236 -- Lots of overkill here. KISS advocates, go away, shoo! ;) -- kaeza
238 local PNG_HDR = string.char(0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A)
240 -- check if a file does exist
241 -- to avoid reopening file after checking again
242 -- pass TRUE as second argument
243 function file_exists(name, return_handle, mode)
245 local f = io.open(name, mode)
247 if (return_handle) then
257 -- Read the image size from a PNG file.
258 -- Returns image_w, image_h.
259 -- Only the LSB is read from each field!
260 local function read_image_size(filename)
261 local f = file_exists(filename, true, "rb")
262 -- file might not exist (don't crash the game)
267 local hdr = f:read(string.len(PNG_HDR))
268 if hdr ~= PNG_HDR then
277 return ws:byte(), hs:byte()
280 -- Set by build_char_db()
283 local COLORBGW, COLORBGH
285 -- Size of the canvas, in characters.
286 -- Please note that CHARS_PER_LINE is multiplied by the average character
287 -- width to get the total width of the canvas, so for proportional fonts,
288 -- either more or fewer characters may fit on a line.
289 local CHARS_PER_LINE = 30
290 local NUMBER_OF_LINES = 6
292 -- 6 rows, max 80 chars per, plus a bit of fudge to
293 -- avoid excess trimming (e.g. due to color codes)
295 local MAX_INPUT_CHARS = 600
297 -- This holds the individual character widths.
298 -- Indexed by the actual character (e.g. charwidth["A"])
301 -- helper functions to trim sign text input/output
303 local function trim_input(text)
304 return text:sub(1, math.min(MAX_INPUT_CHARS, text:len()))
307 local function build_char_db()
311 -- To calculate average char width.
312 local total_width = 0
316 local w, h = read_image_size(CHAR_PATH:format(font_name, c))
318 local ch = string.char(c)
320 total_width = total_width + w
321 char_count = char_count + 1
325 COLORBGW, COLORBGH = read_image_size(TP.."/slc_n.png")
326 assert(COLORBGW and COLORBGH, "error reading bg dimensions")
327 LINE_HEIGHT = COLORBGH
329 -- XXX: Is there a better way to calc this?
330 SIGN_WIDTH = math.floor((total_width / char_count) * CHARS_PER_LINE)
334 local sign_groups = {choppy=2, dig_immediate=2}
336 local fences_with_sign = { }
338 -- some local helper functions
340 local function split_lines_and_words_old(text)
343 if not text then return end
344 for word in text:gmatch("%S+") do
346 table.insert(lines, line)
347 if #lines >= NUMBER_OF_LINES then break end
349 elseif word == "\\|" then
350 table.insert(line, "|")
352 table.insert(line, word)
355 table.insert(lines, line)
359 local function split_lines_and_words(text)
360 if not text then return end
361 text = string.gsub(text, "@KEYWORD", current_keyword)
363 for _, line in ipairs(text:split("\n")) do
364 table.insert(lines, line:split(" "))
369 local math_max = math.max
371 local function fill_line(x, y, w, c)
374 for xx = 0, math.max(0, w), COLORBGW do
375 table.insert(tex, (":%d,%d=slc_%s.png"):format(x + xx, y, c))
377 return table.concat(tex)
380 -- make char texture file name
381 -- if texture file does not exist use fallback texture instead
382 local function char_tex(font_name, ch)
383 if ctexcache[font_name..ch] then
384 return ctexcache[font_name..ch], true
387 local exists, tex = file_exists(CHAR_PATH:format(font_name, c))
388 if exists and c ~= 14 then
389 tex = CHAR_FILE:format(font_name, c)
391 tex = CHAR_FILE:format(font_name, 0x0)
393 ctexcache[font_name..ch] = tex
398 local function make_line_texture(line, lineno, pos)
404 local n = minetest.registered_nodes[minetest.get_node(pos).name]
405 local default_color = n.default_color or 0
407 local cur_color = tonumber(default_color, 16)
409 -- We check which chars are available here.
410 for word_i, word in ipairs(line) do
413 word = string.gsub(word, "%^[12345678abcdefgh]", {
414 ["^1"] = string.char(0x81),
415 ["^2"] = string.char(0x82),
416 ["^3"] = string.char(0x83),
417 ["^4"] = string.char(0x84),
418 ["^5"] = string.char(0x85),
419 ["^6"] = string.char(0x86),
420 ["^7"] = string.char(0x87),
421 ["^8"] = string.char(0x88),
422 ["^a"] = string.char(0x8a),
423 ["^b"] = string.char(0x8b),
424 ["^c"] = string.char(0x8c),
425 ["^d"] = string.char(0x8d),
426 ["^e"] = string.char(0x8e),
427 ["^f"] = string.char(0x8f),
428 ["^g"] = string.char(0x90),
429 ["^h"] = string.char(0x91)
434 local c = word:sub(i, i)
436 local cc = tonumber(word:sub(i+1, i+1), 16)
442 local w = charwidth[c]
444 width = width + w + 1
445 if width >= (SIGN_WIDTH - charwidth[" "]) then
448 maxw = math_max(width, maxw)
450 if #chars < MAX_INPUT_CHARS then
451 table.insert(chars, {
453 tex = char_tex(font_name, c),
454 col = ("%X"):format(cur_color),
457 ch_offs = ch_offs + w
462 width = width + charwidth[" "] + 1
463 maxw = math_max(width, maxw)
464 table.insert(words, { chars=chars, w=ch_offs })
467 -- Okay, we actually build the "line texture" here.
471 local start_xpos = math.floor((SIGN_WIDTH - maxw) / 2)
473 local xpos = start_xpos
474 local ypos = (LINE_HEIGHT * lineno)
478 for word_i, word in ipairs(words) do
479 local xoffs = (xpos - start_xpos)
480 if (xoffs > 0) and ((xoffs + word.w) > maxw) then
481 table.insert(texture, fill_line(xpos, ypos, maxw, "n"))
483 ypos = ypos + LINE_HEIGHT
485 if lineno >= NUMBER_OF_LINES then break end
486 table.insert(texture, fill_line(xpos, ypos, maxw, cur_color))
488 for ch_i, ch in ipairs(word.chars) do
489 if ch.col ~= cur_color then
491 table.insert(texture, fill_line(xpos + ch.off, ypos, maxw, cur_color))
493 table.insert(texture, (":%d,%d=%s"):format(xpos + ch.off, ypos, ch.tex))
497 (":%d,%d="):format(xpos + word.w, ypos) .. char_tex(font_name, " ")
499 xpos = xpos + word.w + charwidth[" "]
500 if xpos >= (SIGN_WIDTH + charwidth[" "]) then break end
503 table.insert(texture, fill_line(xpos, ypos, maxw, "n"))
504 table.insert(texture, fill_line(start_xpos, ypos + LINE_HEIGHT, maxw, "n"))
506 return table.concat(texture), lineno
509 local function make_sign_texture(lines, pos)
510 local texture = { ("[combine:%dx%d"):format(SIGN_WIDTH, LINE_HEIGHT * NUMBER_OF_LINES) }
513 if lineno >= NUMBER_OF_LINES then break end
514 local linetex, ln = make_line_texture(lines[i], lineno, pos)
515 table.insert(texture, linetex)
518 table.insert(texture, "^[makealpha:0,0,0")
519 return table.concat(texture, "")
522 local function set_obj_text(obj, text, new, pos)
523 local split = new and split_lines_and_words or split_lines_and_words_old
524 local text_ansi = Utf8ToAnsi(text)
525 local n = minetest.registered_nodes[minetest.get_node(pos).name]
526 local text_scale = (n and n.text_scale) or DEFAULT_TEXT_SCALE
528 textures={make_sign_texture(split(text_ansi), pos)},
529 visual_size = text_scale,
533 signs_lib.construct_sign = function(pos, locked)
534 local meta = minetest.get_meta(pos)
538 "textarea[0,-0.3;6.5,3;text;;${text}]"..
539 "button_exit[2,3.4;2,1;ok;"..S("Write").."]"..
540 "background[-0.5,-0.5;7,5;bg_signs_lib.jpg]")
541 meta:set_string("infotext", "")
544 signs_lib.destruct_sign = function(pos)
545 local objects = minetest.get_objects_inside_radius(pos, 0.5)
546 for _, v in ipairs(objects) do
547 local e = v:get_luaentity()
548 if e and e.name == "signs:text" then
554 local function make_infotext(text)
555 text = trim_input(text)
556 local lines = split_lines_and_words(text) or {}
558 for _, line in ipairs(lines) do
559 table.insert(lines2, (table.concat(line, " "):gsub("#[0-9a-fA-F]", ""):gsub("##", "#")))
561 return table.concat(lines2, "\n")
564 signs_lib.update_sign = function(pos, fields, owner, node)
566 -- First, check if the interact keyword from CWz's mod is being set,
567 -- or has been changed since the last restart...
569 local meta = minetest.get_meta(pos)
570 local stored_text = meta:get_string("text") or ""
571 current_keyword = rawget(_G, "mki_interact_keyword") or current_keyword
573 if fields then -- ...we're editing the sign.
574 if fields.text and string.find(dump(fields.text), "@KEYWORD") then
575 meta:set_string("keyword", current_keyword)
577 meta:set_string("keyword", nil)
579 elseif string.find(dump(stored_text), "@KEYWORD") then -- we need to check if the password is being set/changed
581 local stored_keyword = meta:get_string("keyword")
582 if stored_keyword and stored_keyword ~= "" and stored_keyword ~= current_keyword then
583 signs_lib.destruct_sign(pos)
584 meta:set_string("keyword", current_keyword)
586 if owner then ownstr = S("Locked sign, owned by @1\n", owner) end
587 meta:set_string("infotext", ownstr..string.gsub(make_infotext(stored_text), "@KEYWORD", current_keyword).." ")
595 fields.text = trim_input(fields.text)
598 if owner then ownstr = S("Locked sign, owned by @1\n", owner) end
600 meta:set_string("infotext", ownstr..string.gsub(make_infotext(fields.text), "@KEYWORD", current_keyword).." ")
601 meta:set_string("text", fields.text)
603 meta:set_int("__signslib_new_format", 1)
606 new = (meta:get_int("__signslib_new_format") ~= 0)
608 signs_lib.destruct_sign(pos)
609 local text = meta:get_string("text")
610 if text == nil or text == "" then return end
612 local signnode = node or minetest.get_node(pos)
613 local signname = signnode.name
614 local textpos = minetest.registered_nodes[signname].textpos
616 sign_info = textpos[minetest.get_node(pos).param2 + 1]
617 elseif signnode.name == "signs:sign_yard" then
618 sign_info = signs_lib.yard_sign_model.textpos[minetest.get_node(pos).param2 + 1]
619 elseif signnode.name == "signs:sign_hanging" then
620 sign_info = signs_lib.hanging_sign_model.textpos[minetest.get_node(pos).param2 + 1]
621 elseif string.find(signnode.name, "sign_wall") then
622 if signnode.name == default_sign
623 or signnode.name == default_sign_metal
624 or signnode.name == "locked_sign:sign_wall_locked" then
625 sign_info = signs_lib.regular_wall_sign_model.textpos[minetest.get_node(pos).param2 + 1]
627 sign_info = signs_lib.metal_wall_sign_model.textpos[minetest.get_node(pos).param2 + 1]
629 else -- ...it must be a sign on a fence post.
630 sign_info = signs_lib.sign_post_model.textpos[minetest.get_node(pos).param2 + 1]
632 if sign_info == nil then
635 local text = minetest.add_entity({x = pos.x + sign_info.delta.x,
636 y = pos.y + sign_info.delta.y,
637 z = pos.z + sign_info.delta.z}, "signs:text")
638 text:setyaw(sign_info.yaw)
641 -- What kind of sign do we need to place, anyway?
643 function signs_lib.determine_sign_type(itemstack, placer, pointed_thing, locked)
645 name = minetest.get_node(pointed_thing.under).name
646 if fences_with_sign[name] then
647 if minetest.is_protected(pointed_thing.under, placer:get_player_name()) then
648 minetest.record_protection_violation(pointed_thing.under,
649 placer:get_player_name())
653 name = minetest.get_node(pointed_thing.above).name
654 local def = minetest.registered_nodes[name]
655 if not def.buildable_to then
658 if minetest.is_protected(pointed_thing.above, placer:get_player_name()) then
659 minetest.record_protection_violation(pointed_thing.above,
660 placer:get_player_name())
665 local node=minetest.get_node(pointed_thing.under)
667 if minetest.registered_nodes[node.name] and
668 minetest.registered_nodes[node.name].on_rightclick and
669 not placer:get_player_control().sneak then
670 return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack, pointed_thing)
672 local above = pointed_thing.above
673 local under = pointed_thing.under
674 local dir = {x = under.x - above.x,
675 y = under.y - above.y,
676 z = under.z - above.z}
678 local wdir = minetest.dir_to_wallmounted(dir)
680 local placer_pos = placer:getpos()
683 x = above.x - placer_pos.x,
684 y = above.y - placer_pos.y,
685 z = above.z - placer_pos.z
689 local fdir = minetest.dir_to_facedir(dir)
690 local pt_name = minetest.get_node(under).name
691 local signname = itemstack:get_name()
693 if fences_with_sign[pt_name] and signname == default_sign then
694 minetest.add_node(under, {name = fences_with_sign[pt_name], param2 = fdir})
695 elseif wdir == 0 and signname == default_sign then
696 minetest.add_node(above, {name = "signs:sign_hanging", param2 = fdir})
697 elseif wdir == 1 and signname == default_sign then
698 minetest.add_node(above, {name = "signs:sign_yard", param2 = fdir})
699 elseif signname == default_sign_metal then
700 minetest.add_node(above, {name = signname, param2 = wdir })
701 elseif signname ~= default_sign
702 and signname ~= default_sign_metal
703 and signname ~= "locked_sign:sign_wall_locked" then -- it's a signs_lib colored metal wall sign.
704 minetest.add_node(above, {name = signname, param2 = fdir})
705 else -- it must be a default or locked wooden wall sign
706 minetest.add_node(above, {name = signname, param2 = wdir }) -- note it's wallmounted here!
708 local meta = minetest.get_meta(above)
709 local owner = placer:get_player_name()
710 meta:set_string("owner", owner)
714 if not signs_lib.expect_infinite_stacks then
715 itemstack:take_item()
721 function signs_lib.receive_fields(pos, formname, fields, sender, lock)
722 if minetest.is_protected(pos, sender:get_player_name()) then
723 minetest.record_protection_violation(pos,
724 sender:get_player_name())
727 local lockstr = lock and S("locked ") or ""
728 if fields and fields.text and fields.ok then
729 minetest.log("action", S("@1 wrote \"@2\" to @3sign at @4",
730 (sender:get_player_name() or ""),
731 fields.text:gsub('\\', '\\\\'):gsub("\n", "\\n"),
733 minetest.pos_to_string(pos)
736 signs_lib.update_sign(pos, fields, sender:get_player_name())
738 signs_lib.update_sign(pos, fields)
743 minetest.register_node(":"..default_sign, {
744 description = S("Sign"),
745 inventory_image = default_sign_image,
746 wield_image = default_sign_image,
747 node_placement_prediction = "",
748 sunlight_propagates = true,
750 paramtype2 = "wallmounted",
751 drawtype = "nodebox",
752 node_box = signs_lib.regular_wall_sign_model.nodebox,
753 tiles = {"signs_wall_sign.png"},
754 groups = sign_groups,
756 on_place = function(itemstack, placer, pointed_thing)
757 return signs_lib.determine_sign_type(itemstack, placer, pointed_thing)
759 on_construct = function(pos)
760 signs_lib.construct_sign(pos)
762 on_destruct = function(pos)
763 signs_lib.destruct_sign(pos)
765 on_receive_fields = function(pos, formname, fields, sender)
766 signs_lib.receive_fields(pos, formname, fields, sender)
768 on_punch = function(pos, node, puncher)
769 signs_lib.update_sign(pos,nil,nil,node)
771 on_rotate = signs_lib.wallmounted_rotate
774 minetest.register_node(":signs:sign_yard", {
776 sunlight_propagates = true,
777 paramtype2 = "facedir",
778 drawtype = "nodebox",
779 node_box = signs_lib.yard_sign_model.nodebox,
782 fixed = {-0.4375, -0.5, -0.0625, 0.4375, 0.375, 0}
784 tiles = {"signs_top.png", "signs_bottom.png", "signs_side.png", "signs_side.png", "signs_back.png", "signs_front.png"},
785 groups = {choppy=2, dig_immediate=2},
788 on_construct = function(pos)
789 signs_lib.construct_sign(pos)
791 on_destruct = function(pos)
792 signs_lib.destruct_sign(pos)
794 on_receive_fields = function(pos, formname, fields, sender)
795 signs_lib.receive_fields(pos, formname, fields, sender)
797 on_punch = function(pos, node, puncher)
798 signs_lib.update_sign(pos,nil,nil,node)
800 on_rotate = signs_lib.facedir_rotate_simple
804 minetest.register_node(":signs:sign_hanging", {
806 sunlight_propagates = true,
807 paramtype2 = "facedir",
808 drawtype = "nodebox",
809 node_box = signs_lib.hanging_sign_model.nodebox,
812 fixed = {-0.45, -0.275, -0.049, 0.45, 0.5, 0.049}
815 "signs_hanging_top.png",
816 "signs_hanging_bottom.png",
817 "signs_hanging_side.png",
818 "signs_hanging_side.png",
819 "signs_hanging_back.png",
820 "signs_hanging_front.png"
822 groups = {choppy=2, dig_immediate=2},
825 on_construct = function(pos)
826 signs_lib.construct_sign(pos)
828 on_destruct = function(pos)
829 signs_lib.destruct_sign(pos)
831 on_receive_fields = function(pos, formname, fields, sender)
832 signs_lib.receive_fields(pos, formname, fields, sender)
834 on_punch = function(pos, node, puncher)
835 signs_lib.update_sign(pos,nil,nil,node)
837 on_rotate = signs_lib.facedir_rotate_simple
840 minetest.register_node(":signs:sign_post", {
842 sunlight_propagates = true,
843 paramtype2 = "facedir",
844 drawtype = "nodebox",
845 node_box = signs_lib.sign_post_model.nodebox,
847 "signs_post_top.png",
848 "signs_post_bottom.png",
849 "signs_post_side.png",
850 "signs_post_side.png",
851 "signs_post_back.png",
852 "signs_post_front.png",
854 groups = {choppy=2, dig_immediate=2},
858 { items = { default_sign }},
859 { items = { "default:fence_wood" }},
862 on_rotate = signs_lib.facedir_rotate_simple
867 minetest.register_privilege("sign_editor", S("Can edit all locked signs"))
869 minetest.register_node(":locked_sign:sign_wall_locked", {
870 description = S("Locked Sign"),
871 inventory_image = "signs_locked_inv.png",
872 wield_image = "signs_locked_inv.png",
873 node_placement_prediction = "",
874 sunlight_propagates = true,
876 paramtype2 = "wallmounted",
877 drawtype = "nodebox",
878 node_box = signs_lib.regular_wall_sign_model.nodebox,
879 tiles = { "signs_wall_sign_locked.png" },
880 groups = sign_groups,
881 on_place = function(itemstack, placer, pointed_thing)
882 return signs_lib.determine_sign_type(itemstack, placer, pointed_thing, true)
884 on_construct = function(pos)
885 signs_lib.construct_sign(pos, true)
887 on_destruct = function(pos)
888 signs_lib.destruct_sign(pos)
890 on_receive_fields = function(pos, formname, fields, sender)
891 local meta = minetest.get_meta(pos)
892 local owner = meta:get_string("owner")
893 local pname = sender:get_player_name() or ""
894 if pname ~= owner and pname ~= minetest.settings:get("name")
895 and not minetest.check_player_privs(pname, {sign_editor=true}) then
898 signs_lib.receive_fields(pos, formname, fields, sender, true)
900 on_punch = function(pos, node, puncher)
901 signs_lib.update_sign(pos,nil,nil,node)
903 can_dig = function(pos, player)
904 local meta = minetest.get_meta(pos)
905 local owner = meta:get_string("owner")
906 local pname = player:get_player_name()
907 return pname == owner or pname == minetest.settings:get("name")
908 or minetest.check_player_privs(pname, {sign_editor=true})
910 on_rotate = function(pos, node, user, mode)
911 local meta = minetest.get_meta(pos)
912 local owner = meta:get_string("owner")
913 if owner == user:get_player_name() then
914 signs_lib.wallmounted_rotate(pos, node, user, mode)
921 -- default metal sign, if defined
923 minetest.register_node(":"..default_sign_metal, {
924 description = S("Sign"),
925 inventory_image = default_sign_metal_image,
926 wield_image = default_sign_metal_image,
927 node_placement_prediction = "",
928 sunlight_propagates = true,
930 paramtype2 = "wallmounted",
931 drawtype = "nodebox",
932 node_box = signs_lib.regular_wall_sign_model.nodebox,
933 tiles = {"signs_wall_sign_metal.png"},
934 groups = sign_groups,
936 on_place = function(itemstack, placer, pointed_thing)
937 return signs_lib.determine_sign_type(itemstack, placer, pointed_thing)
939 on_construct = function(pos)
940 signs_lib.construct_sign(pos)
942 on_destruct = function(pos)
943 signs_lib.destruct_sign(pos)
945 on_receive_fields = function(pos, formname, fields, sender)
946 local meta = minetest.get_meta(pos)
947 local owner = meta:get_string("owner")
948 local pname = sender:get_player_name() or ""
949 if pname ~= owner and pname ~= minetest.settings:get("name")
950 and not minetest.check_player_privs(pname, {sign_editor=true}) then
953 signs_lib.receive_fields(pos, formname, fields, sender, true)
955 on_punch = function(pos, node, puncher)
956 signs_lib.update_sign(pos,nil,nil,node)
958 on_rotate = function(pos, node, user, mode)
959 local meta = minetest.get_meta(pos)
960 local owner = meta:get_string("owner")
961 if owner == user:get_player_name() then
962 signs_lib.wallmounted_rotate(pos, node, user, mode)
970 -- metal, colored signs
971 if enable_colored_metal_signs then
972 -- array : color, translated color, default text color
973 local sign_colors = {
974 {"green", S("green"), "f"},
975 {"yellow", S("yellow"), "0"},
976 {"red", S("red"), "f"},
977 {"white_red", S("white_red"), "4"},
978 {"white_black", S("white_black"), "0"},
979 {"orange", S("orange"), "0"},
980 {"blue", S("blue"), "f"},
981 {"brown", S("brown"), "f"},
984 for i, color in ipairs(sign_colors) do
985 minetest.register_node(":signs:sign_wall_"..color[1], {
986 description = S("Sign (@1, metal)", color[2]),
987 inventory_image = "signs_"..color[1].."_inv.png",
988 wield_image = "signs_"..color[1].."_inv.png",
989 node_placement_prediction = "",
991 sunlight_propagates = true,
992 paramtype2 = "facedir",
993 drawtype = "nodebox",
994 node_box = signs_lib.metal_wall_sign_model.nodebox,
996 "signs_metal_tb.png",
997 "signs_metal_tb.png",
998 "signs_metal_sides.png",
999 "signs_metal_sides.png",
1000 "signs_metal_back.png",
1001 "signs_"..color[1].."_front.png"
1003 default_color = color[3],
1004 groups = sign_groups,
1005 on_place = function(itemstack, placer, pointed_thing)
1006 return signs_lib.determine_sign_type(itemstack, placer, pointed_thing)
1008 on_construct = function(pos)
1009 signs_lib.construct_sign(pos)
1011 on_destruct = function(pos)
1012 signs_lib.destruct_sign(pos)
1014 on_receive_fields = function(pos, formname, fields, sender)
1015 signs_lib.receive_fields(pos, formname, fields, sender)
1017 on_punch = function(pos, node, puncher)
1018 signs_lib.update_sign(pos,nil,nil,node)
1020 on_rotate = signs_lib.facedir_rotate
1025 local signs_text_on_activate
1027 signs_text_on_activate = function(self)
1028 local pos = self.object:getpos()
1029 local meta = minetest.get_meta(pos)
1030 local text = meta:get_string("text")
1031 local new = (meta:get_int("__signslib_new_format") ~= 0)
1032 if text and minetest.registered_nodes[minetest.get_node(pos).name] then
1033 text = trim_input(text)
1034 set_obj_text(self.object, text, new, pos)
1038 minetest.register_entity(":signs:text", {
1039 collisionbox = { 0, 0, 0, 0, 0, 0 },
1040 visual = "upright_sprite",
1043 on_activate = signs_text_on_activate,
1046 -- And the good stuff here! :-)
1048 function signs_lib.register_fence_with_sign(fencename, fencewithsignname)
1049 local def = minetest.registered_nodes[fencename]
1050 local def_sign = minetest.registered_nodes[fencewithsignname]
1051 if not (def and def_sign) then
1052 minetest.log("warning", "[signs_lib] "..S("Attempt to register unknown node as fence"))
1055 def = signs_lib.table_copy(def)
1056 def_sign = signs_lib.table_copy(def_sign)
1057 fences_with_sign[fencename] = fencewithsignname
1059 def_sign.on_place = function(itemstack, placer, pointed_thing, ...)
1060 local node_above = minetest.get_node_or_nil(pointed_thing.above)
1061 local node_under = minetest.get_node_or_nil(pointed_thing.under)
1062 local def_above = node_above and minetest.registered_nodes[node_above.name]
1063 local def_under = node_under and minetest.registered_nodes[node_under.name]
1064 local fdir = minetest.dir_to_facedir(placer:get_look_dir())
1065 local playername = placer:get_player_name()
1067 if minetest.is_protected(pointed_thing.under, playername) then
1068 minetest.record_protection_violation(pointed_thing.under, playername)
1072 if minetest.is_protected(pointed_thing.above, playername) then
1073 minetest.record_protection_violation(pointed_thing.above, playername)
1077 if def_under and def_under.on_rightclick then
1078 return def_under.on_rightclick(pointed_thing.under, node_under, placer, itemstack, pointed_thing) or itemstack
1079 elseif def_under and def_under.buildable_to then
1080 minetest.add_node(pointed_thing.under, {name = fencename, param2 = fdir})
1081 if not signs_lib.expect_infinite_stacks then
1082 itemstack:take_item()
1084 placer:set_wielded_item(itemstack)
1085 elseif def_above and def_above.buildable_to then
1086 minetest.add_node(pointed_thing.above, {name = fencename, param2 = fdir})
1087 if not signs_lib.expect_infinite_stacks then
1088 itemstack:take_item()
1090 placer:set_wielded_item(itemstack)
1094 def_sign.on_construct = function(pos, ...)
1095 signs_lib.construct_sign(pos)
1097 def_sign.on_destruct = function(pos, ...)
1098 signs_lib.destruct_sign(pos)
1100 def_sign.on_receive_fields = function(pos, formname, fields, sender)
1101 signs_lib.receive_fields(pos, formname, fields, sender)
1103 def_sign.on_punch = function(pos, node, puncher, ...)
1104 signs_lib.update_sign(pos,nil,nil,node)
1106 local fencename = fencename
1107 def_sign.after_dig_node = function(pos, node, ...)
1108 node.name = fencename
1109 minetest.add_node(pos, node)
1111 def_sign.on_rotate = signs_lib.facedir_rotate_simple
1113 def_sign.drop = default_sign
1114 minetest.register_node(":"..fencename, def)
1115 minetest.register_node(":"..fencewithsignname, def_sign)
1116 table.insert(signs_lib.sign_node_list, fencewithsignname)
1117 minetest.log("verbose", S("Registered @1 and @2", fencename, fencewithsignname))
1122 minetest.register_alias("homedecor:fence_wood_with_sign", "signs:sign_post")
1123 minetest.register_alias("sign_wall_locked", "locked_sign:sign_wall_locked")
1125 signs_lib.register_fence_with_sign("default:fence_wood", "signs:sign_post")
1127 -- restore signs' text after /clearobjects and the like, the next time
1128 -- a block is reloaded by the server.
1130 minetest.register_lbm({
1131 nodenames = signs_lib.sign_node_list,
1132 name = "signs_lib:restore_sign_text",
1133 label = "Restore sign text",
1134 run_at_every_load = true,
1135 action = function(pos, node)
1136 signs_lib.update_sign(pos,nil,nil,node)
1142 minetest.register_craft({
1143 output = "locked_sign:sign_wall_locked",
1146 {"basic_materials:padlock"},
1150 -- craft recipes for the metal signs
1151 if enable_colored_metal_signs then
1153 minetest.register_craft( {
1154 output = "signs:sign_wall_green",
1156 { "dye:dark_green", "dye:white", "dye:dark_green" },
1157 { "", default_sign_metal, "" }
1161 minetest.register_craft( {
1162 output = "signs:sign_wall_green 2",
1164 { "dye:dark_green", "dye:white", "dye:dark_green" },
1165 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1169 minetest.register_craft( {
1170 output = "signs:sign_wall_yellow",
1172 { "dye:yellow", "dye:black", "dye:yellow" },
1173 { "", default_sign_metal, "" }
1177 minetest.register_craft( {
1178 output = "signs:sign_wall_yellow 2",
1180 { "dye:yellow", "dye:black", "dye:yellow" },
1181 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1185 minetest.register_craft( {
1186 output = "signs:sign_wall_red",
1188 { "dye:red", "dye:white", "dye:red" },
1189 { "", default_sign_metal, "" }
1193 minetest.register_craft( {
1194 output = "signs:sign_wall_red 2",
1196 { "dye:red", "dye:white", "dye:red" },
1197 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1201 minetest.register_craft( {
1202 output = "signs:sign_wall_white_red",
1204 { "dye:white", "dye:red", "dye:white" },
1205 { "", default_sign_metal, "" }
1209 minetest.register_craft( {
1210 output = "signs:sign_wall_white_red 2",
1212 { "dye:white", "dye:red", "dye:white" },
1213 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1217 minetest.register_craft( {
1218 output = "signs:sign_wall_white_black",
1220 { "dye:white", "dye:black", "dye:white" },
1221 { "", default_sign_metal, "" }
1225 minetest.register_craft( {
1226 output = "signs:sign_wall_white_black 2",
1228 { "dye:white", "dye:black", "dye:white" },
1229 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1233 minetest.register_craft( {
1234 output = "signs:sign_wall_orange",
1236 { "dye:orange", "dye:black", "dye:orange" },
1237 { "", default_sign_metal, "" }
1241 minetest.register_craft( {
1242 output = "signs:sign_wall_orange 2",
1244 { "dye:orange", "dye:black", "dye:orange" },
1245 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1249 minetest.register_craft( {
1250 output = "signs:sign_wall_blue",
1252 { "dye:blue", "dye:white", "dye:blue" },
1253 { "", default_sign_metal, "" }
1257 minetest.register_craft( {
1258 output = "signs:sign_wall_blue 2",
1260 { "dye:blue", "dye:white", "dye:blue" },
1261 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1265 minetest.register_craft( {
1266 output = "signs:sign_wall_brown",
1268 { "dye:brown", "dye:white", "dye:brown" },
1269 { "", default_sign_metal, "" }
1273 minetest.register_craft( {
1274 output = "signs:sign_wall_brown 2",
1276 { "dye:brown", "dye:white", "dye:brown" },
1277 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1282 if minetest.settings:get("log_mods") then
1283 minetest.log("action", S("[MOD] signs loaded"))