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 }
13 -- CWz's keyword interact mod uses this setting.
14 local current_keyword = minetest.setting_get("interact_keyword") or "iaccept"
17 screwdriver = screwdriver or {}
19 signs_lib.wallmounted_rotate = function(pos, node, user, mode, new_param2)
20 if mode ~= screwdriver.ROTATE_AXIS then return false end
21 minetest.swap_node(pos, {name = node.name, param2 = (node.param2 + 1) % 6})
22 for _, v in ipairs(minetest.get_objects_inside_radius(pos, 0.5)) do
23 local e = v:get_luaentity()
24 if e and e.name == "signs:text" then
28 signs_lib.update_sign(pos)
32 signs_lib.modpath = minetest.get_modpath("signs_lib")
34 local DEFAULT_TEXT_SCALE = {x=0.8, y=0.5}
36 signs_lib.regular_wall_sign_model = {
39 wall_side = { -0.5, -0.25, -0.4375, -0.4375, 0.375, 0.4375 },
40 wall_bottom = { -0.4375, -0.5, -0.25, 0.4375, -0.4375, 0.375 },
41 wall_top = { -0.4375, 0.4375, -0.375, 0.4375, 0.5, 0.25 }
46 {delta = { x = 0.41, y = 0.07, z = 0 }, yaw = math.pi / -2},
47 {delta = { x = -0.41, y = 0.07, z = 0 }, yaw = math.pi / 2},
48 {delta = { x = 0, y = 0.07, z = 0.41 }, yaw = 0},
49 {delta = { x = 0, y = 0.07, z = -0.41 }, yaw = math.pi},
53 signs_lib.metal_wall_sign_model = {
56 fixed = {-0.4375, -0.25, 0.4375, 0.4375, 0.375, 0.5}
59 {delta = { x = 0, y = 0.07, z = 0.41 }, yaw = 0},
60 {delta = { x = 0.41, y = 0.07, z = 0 }, yaw = math.pi / -2},
61 {delta = { x = 0, y = 0.07, z = -0.41 }, yaw = math.pi},
62 {delta = { x = -0.41, y = 0.07, z = 0 }, yaw = math.pi / 2},
66 signs_lib.yard_sign_model = {
70 {-0.4375, -0.25, -0.0625, 0.4375, 0.375, 0},
71 {-0.0625, -0.5, -0.0625, 0.0625, -0.1875, 0},
75 {delta = { x = 0, y = 0.07, z = -0.08 }, yaw = 0},
76 {delta = { x = -0.08, y = 0.07, z = 0 }, yaw = math.pi / -2},
77 {delta = { x = 0, y = 0.07, z = 0.08 }, yaw = math.pi},
78 {delta = { x = 0.08, y = 0.07, z = 0 }, yaw = math.pi / 2},
82 signs_lib.hanging_sign_model = {
86 {-0.4375, -0.3125, -0.0625, 0.4375, 0.3125, 0},
87 {-0.4375, 0.25, -0.03125, 0.4375, 0.5, -0.03125},
91 {delta = { x = 0, y = -0.02, z = -0.08 }, yaw = 0},
92 {delta = { x = -0.08, y = -0.02, z = 0 }, yaw = math.pi / -2},
93 {delta = { x = 0, y = -0.02, z = 0.08 }, yaw = math.pi},
94 {delta = { x = 0.08, y = -0.02, z = 0 }, yaw = math.pi / 2},
98 signs_lib.sign_post_model = {
102 {-0.4375, -0.25, -0.1875, 0.4375, 0.375, -0.125},
103 {-0.125, -0.5, -0.125, 0.125, 0.5, 0.125},
107 {delta = { x = 0, y = 0.07, z = -0.2 }, yaw = 0},
108 {delta = { x = -0.2, y = 0.07, z = 0 }, yaw = math.pi / -2},
109 {delta = { x = 0, y = 0.07, z = 0.2 }, yaw = math.pi},
110 {delta = { x = 0.2, y = 0.07, z = 0 }, yaw = math.pi / 2},
114 -- Boilerplate to support localized strings if intllib mod is installed.
115 local S = rawget(_G, "intllib") and intllib.Getter() or function(s) return s end
116 signs_lib.gettext = S
118 -- the list of standard sign nodes
120 signs_lib.sign_node_list = {
121 "default:sign_wall_wood",
122 "default:sign_wall_steel",
124 "signs:sign_hanging",
125 "signs:sign_wall_green",
126 "signs:sign_wall_yellow",
127 "signs:sign_wall_red",
128 "signs:sign_wall_white_red",
129 "signs:sign_wall_white_black",
130 "signs:sign_wall_orange",
131 "signs:sign_wall_blue",
132 "signs:sign_wall_brown",
133 "locked_sign:sign_wall_locked"
136 local default_sign, default_sign_image
138 -- Default sign was renamed in 0.4.14. Support both & old versions.
139 if minetest.registered_nodes["default:sign_wall_wood"] then
140 default_sign = "default:sign_wall_wood"
141 default_sign_image = "default_sign_wood.png"
143 default_sign = "default:sign_wall"
144 default_sign_image = "default_sign_wall.png"
147 default_sign_metal = "default:sign_wall_steel"
148 default_sign_metal_image = "default_sign_steel.png"
152 function signs_lib.table_copy(t)
154 for k, v in pairs(t) do
155 if type(v) == "table" then
156 nt[k] = signs_lib.table_copy(v)
166 if minetest.get_modpath("unified_inventory") or not minetest.setting_getbool("creative_mode") then
167 signs_lib.expect_infinite_stacks = false
169 signs_lib.expect_infinite_stacks = true
174 local MP = minetest.get_modpath("signs_lib")
176 -- Used by `build_char_db' to locate the file.
177 local FONT_FMT = "%s/hdf_%02x.png"
179 -- Simple texture name for building text texture.
180 local FONT_FMT_SIMPLE = "hdf_%02x.png"
182 -- Path to the textures.
183 local TP = MP.."/textures"
185 -- Lots of overkill here. KISS advocates, go away, shoo! ;) -- kaeza
187 local PNG_HDR = string.char(0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A)
189 -- Read the image size from a PNG file.
190 -- Returns image_w, image_h.
191 -- Only the LSB is read from each field!
192 local function read_image_size(filename)
193 local f = io.open(filename, "rb")
195 local hdr = f:read(8)
196 if hdr ~= PNG_HDR then
205 return ws:byte(), hs:byte()
208 -- Set by build_char_db()
211 local COLORBGW, COLORBGH
213 -- Size of the canvas, in characters.
214 -- Please note that CHARS_PER_LINE is multiplied by the average character
215 -- width to get the total width of the canvas, so for proportional fonts,
216 -- either more or fewer characters may fit on a line.
217 local CHARS_PER_LINE = 30
218 local NUMBER_OF_LINES = 6
220 -- 6 rows, max 80 chars per, plus a bit of fudge to
221 -- avoid excess trimming (e.g. due to color codes)
223 local MAX_INPUT_CHARS = 600
225 -- This holds the individual character widths.
226 -- Indexed by the actual character (e.g. charwidth["A"])
229 -- helper functions to trim sign text input/output
231 local function trim_input(text)
232 return text:sub(1, math.min(MAX_INPUT_CHARS, text:len()))
235 local function build_char_db()
239 -- To calculate average char width.
240 local total_width = 0
244 local w, h = read_image_size(FONT_FMT:format(TP, c))
246 local ch = string.char(c)
248 total_width = total_width + w
249 char_count = char_count + 1
253 COLORBGW, COLORBGH = read_image_size(TP.."/slc_n.png")
254 assert(COLORBGW and COLORBGH, "error reading bg dimensions")
255 LINE_HEIGHT = COLORBGH
257 -- XXX: Is there a better way to calc this?
258 SIGN_WIDTH = math.floor((total_width / char_count) * CHARS_PER_LINE)
262 local sign_groups = {choppy=2, dig_immediate=2}
264 local fences_with_sign = { }
266 -- some local helper functions
268 local function split_lines_and_words_old(text)
271 if not text then return end
272 for word in text:gmatch("%S+") do
274 table.insert(lines, line)
275 if #lines >= NUMBER_OF_LINES then break end
277 elseif word == "\\|" then
278 table.insert(line, "|")
280 table.insert(line, word)
283 table.insert(lines, line)
287 local function split_lines_and_words(text)
288 if not text then return end
289 text = string.gsub(text, "@KEYWORD", current_keyword)
291 for _, line in ipairs(text:split("\n")) do
292 table.insert(lines, line:split(" "))
297 local math_max = math.max
299 local function fill_line(x, y, w, c)
302 for xx = 0, math.max(0, w), COLORBGW do
303 table.insert(tex, (":%d,%d=slc_%s.png"):format(x + xx, y, c))
305 return table.concat(tex)
308 local function make_line_texture(line, lineno, pos)
314 local n = minetest.registered_nodes[minetest.get_node(pos).name]
315 local defaultcolor = n.defaultcolor or 0
317 local cur_color = tonumber(defaultcolor, 16)
319 -- We check which chars are available here.
320 for word_i, word in ipairs(line) do
326 local c = word:sub(i, i)
328 local cc = tonumber(word:sub(i+1, i+1), 16)
334 local w = charwidth[c]
336 width = width + w + 1
337 if width >= (SIGN_WIDTH - charwidth[" "]) then
340 maxw = math_max(width, maxw)
342 if #chars < MAX_INPUT_CHARS then
343 table.insert(chars, {
345 tex=FONT_FMT_SIMPLE:format(c:byte()),
346 col=("%X"):format(cur_color),
349 ch_offs = ch_offs + w
354 width = width + charwidth[" "] + 1
355 maxw = math_max(width, maxw)
356 table.insert(words, { chars=chars, w=ch_offs })
359 -- Okay, we actually build the "line texture" here.
363 local start_xpos = math.floor((SIGN_WIDTH - maxw) / 2)
365 local xpos = start_xpos
366 local ypos = (LINE_HEIGHT * lineno)
370 for word_i, word in ipairs(words) do
371 local xoffs = (xpos - start_xpos)
372 if (xoffs > 0) and ((xoffs + word.w) > maxw) then
373 table.insert(texture, fill_line(xpos, ypos, maxw, "n"))
375 ypos = ypos + LINE_HEIGHT
377 if lineno >= NUMBER_OF_LINES then break end
378 table.insert(texture, fill_line(xpos, ypos, maxw, cur_color))
380 for ch_i, ch in ipairs(word.chars) do
381 if ch.col ~= cur_color then
383 table.insert(texture, fill_line(xpos + ch.off, ypos, maxw, cur_color))
385 table.insert(texture, (":%d,%d=%s"):format(xpos + ch.off, ypos, ch.tex))
387 table.insert(texture, (":%d,%d=hdf_20.png"):format(xpos + word.w, ypos))
388 xpos = xpos + word.w + charwidth[" "]
389 if xpos >= (SIGN_WIDTH + charwidth[" "]) then break end
392 table.insert(texture, fill_line(xpos, ypos, maxw, "n"))
393 table.insert(texture, fill_line(start_xpos, ypos + LINE_HEIGHT, maxw, "n"))
395 return table.concat(texture), lineno
398 local function make_sign_texture(lines, pos)
399 local texture = { ("[combine:%dx%d"):format(SIGN_WIDTH, LINE_HEIGHT * NUMBER_OF_LINES) }
402 if lineno >= NUMBER_OF_LINES then break end
403 local linetex, ln = make_line_texture(lines[i], lineno, pos)
404 table.insert(texture, linetex)
407 table.insert(texture, "^[makealpha:0,0,0")
408 return table.concat(texture, "")
411 local function set_obj_text(obj, text, new, pos)
412 local split = new and split_lines_and_words or split_lines_and_words_old
413 local n = minetest.registered_nodes[minetest.get_node(pos).name]
414 local text_scale = n.text_scale or DEFAULT_TEXT_SCALE
416 textures={make_sign_texture(split(text), pos)},
417 visual_size = text_scale,
421 signs_lib.construct_sign = function(pos, locked)
422 local meta = minetest.get_meta(pos)
426 "textarea[0,-0.3;6.5,3;text;;${text}]"..
427 "button_exit[2,3.4;2,1;ok;Write]"..
428 "background[-0.5,-0.5;7,5;bg_signs_lib.jpg]")
429 meta:set_string("infotext", "")
432 signs_lib.destruct_sign = function(pos)
433 local objects = minetest.get_objects_inside_radius(pos, 0.5)
434 for _, v in ipairs(objects) do
435 local e = v:get_luaentity()
436 if e and e.name == "signs:text" then
442 local function make_infotext(text)
443 text = trim_input(text)
444 local lines = split_lines_and_words(text) or {}
446 for _, line in ipairs(lines) do
447 table.insert(lines2, (table.concat(line, " "):gsub("#[0-9a-fA-F]", ""):gsub("##", "#")))
449 return table.concat(lines2, "\n")
452 signs_lib.update_sign = function(pos, fields, owner)
454 -- First, check if the interact keyword from CWz's mod is being set,
455 -- or has been changed since the last restart...
457 local meta = minetest.get_meta(pos)
458 local stored_text = meta:get_string("text") or ""
459 current_keyword = rawget(_G, "mki_interact_keyword") or current_keyword
461 if fields then -- ...we're editing the sign.
462 if fields.text and string.find(dump(fields.text), "@KEYWORD") then
463 meta:set_string("keyword", current_keyword)
465 meta:set_string("keyword", nil)
467 elseif string.find(dump(stored_text), "@KEYWORD") then -- we need to check if the password is being set/changed
469 local stored_keyword = meta:get_string("keyword")
470 if stored_keyword and stored_keyword ~= "" and stored_keyword ~= current_keyword then
471 signs_lib.destruct_sign(pos)
472 meta:set_string("keyword", current_keyword)
474 if owner then ownstr = "Locked sign, owned by "..owner.."\n" end
475 meta:set_string("infotext", ownstr..string.gsub(make_infotext(stored_text), "@KEYWORD", current_keyword).." ")
483 fields.text = trim_input(fields.text)
486 if owner then ownstr = "Locked sign, owned by "..owner.."\n" end
488 meta:set_string("infotext", ownstr..string.gsub(make_infotext(fields.text), "@KEYWORD", current_keyword).." ")
489 meta:set_string("text", fields.text)
491 meta:set_int("__signslib_new_format", 1)
494 new = (meta:get_int("__signslib_new_format") ~= 0)
496 local text = meta:get_string("text")
497 if text == nil then return end
498 local objects = minetest.get_objects_inside_radius(pos, 0.5)
500 for _, v in ipairs(objects) do
501 local e = v:get_luaentity()
502 if e and e.name == "signs:text" then
506 set_obj_text(v, text, new, pos)
515 -- if there is no entity
517 local signnode = minetest.get_node(pos)
518 local signname = signnode.name
519 local textpos = minetest.registered_nodes[signname].textpos
521 sign_info = textpos[minetest.get_node(pos).param2 + 1]
522 elseif signnode.name == "signs:sign_yard" then
523 sign_info = signs_lib.yard_sign_model.textpos[minetest.get_node(pos).param2 + 1]
524 elseif signnode.name == "signs:sign_hanging" then
525 sign_info = signs_lib.hanging_sign_model.textpos[minetest.get_node(pos).param2 + 1]
526 elseif string.find(signnode.name, "sign_wall") then
527 if signnode.name == default_sign
528 or signnode.name == default_sign_metal
529 or signnode.name == "locked_sign:sign_wall_locked" then
530 sign_info = signs_lib.regular_wall_sign_model.textpos[minetest.get_node(pos).param2 + 1]
532 sign_info = signs_lib.metal_wall_sign_model.textpos[minetest.get_node(pos).param2 + 1]
534 else -- ...it must be a sign on a fence post.
535 sign_info = signs_lib.sign_post_model.textpos[minetest.get_node(pos).param2 + 1]
537 if sign_info == nil then
540 local text = minetest.add_entity({x = pos.x + sign_info.delta.x,
541 y = pos.y + sign_info.delta.y,
542 z = pos.z + sign_info.delta.z}, "signs:text")
543 text:setyaw(sign_info.yaw)
546 -- What kind of sign do we need to place, anyway?
548 function signs_lib.determine_sign_type(itemstack, placer, pointed_thing, locked)
550 name = minetest.get_node(pointed_thing.under).name
551 if fences_with_sign[name] then
552 if minetest.is_protected(pointed_thing.under, placer:get_player_name()) then
553 minetest.record_protection_violation(pointed_thing.under,
554 placer:get_player_name())
558 name = minetest.get_node(pointed_thing.above).name
559 local def = minetest.registered_nodes[name]
560 if not def.buildable_to then
563 if minetest.is_protected(pointed_thing.above, placer:get_player_name()) then
564 minetest.record_protection_violation(pointed_thing.above,
565 placer:get_player_name())
570 local node=minetest.get_node(pointed_thing.under)
572 if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
573 return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack)
575 local above = pointed_thing.above
576 local under = pointed_thing.under
577 local dir = {x = under.x - above.x,
578 y = under.y - above.y,
579 z = under.z - above.z}
581 local wdir = minetest.dir_to_wallmounted(dir)
583 local placer_pos = placer:getpos()
586 x = above.x - placer_pos.x,
587 y = above.y - placer_pos.y,
588 z = above.z - placer_pos.z
592 local fdir = minetest.dir_to_facedir(dir)
593 local pt_name = minetest.get_node(under).name
594 local signname = itemstack:get_name()
596 if fences_with_sign[pt_name] and signname == default_sign then
597 minetest.add_node(under, {name = fences_with_sign[pt_name], param2 = fdir})
598 elseif wdir == 0 and signname == default_sign then
599 minetest.add_node(above, {name = "signs:sign_hanging", param2 = fdir})
600 elseif wdir == 1 and signname == default_sign then
601 minetest.add_node(above, {name = "signs:sign_yard", param2 = fdir})
602 elseif signname == default_sign_metal then
603 minetest.add_node(above, {name = signname, param2 = wdir })
604 elseif signname ~= default_sign
605 and signname ~= default_sign_metal
606 and signname ~= "locked_sign:sign_wall_locked" then -- it's a signs_lib colored metal wall sign.
607 minetest.add_node(above, {name = signname, param2 = fdir})
608 else -- it must be a default or locked wooden wall sign
609 minetest.add_node(above, {name = signname, param2 = wdir }) -- note it's wallmounted here!
611 local meta = minetest.get_meta(above)
612 local owner = placer:get_player_name()
613 meta:set_string("owner", owner)
617 if not signs_lib.expect_infinite_stacks then
618 itemstack:take_item()
624 function signs_lib.receive_fields(pos, formname, fields, sender, lock)
625 if minetest.is_protected(pos, sender:get_player_name()) then
626 minetest.record_protection_violation(pos,
627 sender:get_player_name())
630 local lockstr = lock and "locked " or ""
631 if fields and fields.text and fields.ok then
632 minetest.log("action", S("%s wrote \"%s\" to "..lockstr.."sign at %s"):format(
633 (sender:get_player_name() or ""),
635 minetest.pos_to_string(pos)
638 signs_lib.update_sign(pos, fields, sender:get_player_name())
640 signs_lib.update_sign(pos, fields)
645 minetest.register_node(":"..default_sign, {
646 description = S("Sign"),
647 inventory_image = default_sign_image,
648 wield_image = default_sign_image,
649 node_placement_prediction = "",
650 sunlight_propagates = true,
652 paramtype2 = "wallmounted",
653 drawtype = "nodebox",
654 node_box = signs_lib.regular_wall_sign_model.nodebox,
655 tiles = {"signs_wall_sign.png"},
656 groups = sign_groups,
658 on_place = function(itemstack, placer, pointed_thing)
659 return signs_lib.determine_sign_type(itemstack, placer, pointed_thing)
661 on_construct = function(pos)
662 signs_lib.construct_sign(pos)
664 on_destruct = function(pos)
665 signs_lib.destruct_sign(pos)
667 on_receive_fields = function(pos, formname, fields, sender)
668 signs_lib.receive_fields(pos, formname, fields, sender)
670 on_punch = function(pos, node, puncher)
671 signs_lib.update_sign(pos)
673 on_rotate = signs_lib.wallmounted_rotate
676 minetest.register_node(":signs:sign_yard", {
678 sunlight_propagates = true,
679 paramtype2 = "facedir",
680 drawtype = "nodebox",
681 node_box = signs_lib.yard_sign_model.nodebox,
684 fixed = {-0.4375, -0.5, -0.0625, 0.4375, 0.375, 0}
686 tiles = {"signs_top.png", "signs_bottom.png", "signs_side.png", "signs_side.png", "signs_back.png", "signs_front.png"},
687 groups = {choppy=2, dig_immediate=2},
690 on_construct = function(pos)
691 signs_lib.construct_sign(pos)
693 on_destruct = function(pos)
694 signs_lib.destruct_sign(pos)
696 on_receive_fields = function(pos, formname, fields, sender)
697 signs_lib.receive_fields(pos, formname, fields, sender)
699 on_punch = function(pos, node, puncher)
700 signs_lib.update_sign(pos)
704 minetest.register_node(":signs:sign_hanging", {
706 sunlight_propagates = true,
707 paramtype2 = "facedir",
708 drawtype = "nodebox",
709 node_box = signs_lib.hanging_sign_model.nodebox,
712 fixed = {-0.45, -0.275, -0.049, 0.45, 0.5, 0.049}
715 "signs_hanging_top.png",
716 "signs_hanging_bottom.png",
717 "signs_hanging_side.png",
718 "signs_hanging_side.png",
719 "signs_hanging_back.png",
720 "signs_hanging_front.png"
722 groups = {choppy=2, dig_immediate=2},
725 on_construct = function(pos)
726 signs_lib.construct_sign(pos)
728 on_destruct = function(pos)
729 signs_lib.destruct_sign(pos)
731 on_receive_fields = function(pos, formname, fields, sender)
732 signs_lib.receive_fields(pos, formname, fields, sender)
734 on_punch = function(pos, node, puncher)
735 signs_lib.update_sign(pos)
739 minetest.register_node(":signs:sign_post", {
741 sunlight_propagates = true,
742 paramtype2 = "facedir",
743 drawtype = "nodebox",
744 node_box = signs_lib.sign_post_model.nodebox,
746 "signs_post_top.png",
747 "signs_post_bottom.png",
748 "signs_post_side.png",
749 "signs_post_side.png",
750 "signs_post_back.png",
751 "signs_post_front.png",
753 groups = {choppy=2, dig_immediate=2},
757 { items = { default_sign }},
758 { items = { "default:fence_wood" }},
765 minetest.register_privilege("sign_editor", "Can edit all locked signs")
767 minetest.register_node(":locked_sign:sign_wall_locked", {
768 description = S("Sign"),
769 inventory_image = "signs_locked_inv.png",
770 wield_image = "signs_locked_inv.png",
771 node_placement_prediction = "",
772 sunlight_propagates = true,
774 paramtype2 = "wallmounted",
775 drawtype = "nodebox",
776 node_box = signs_lib.regular_wall_sign_model.nodebox,
777 tiles = { "signs_wall_sign_locked.png" },
778 groups = sign_groups,
779 on_place = function(itemstack, placer, pointed_thing)
780 return signs_lib.determine_sign_type(itemstack, placer, pointed_thing, true)
782 on_construct = function(pos)
783 signs_lib.construct_sign(pos, true)
785 on_destruct = function(pos)
786 signs_lib.destruct_sign(pos)
788 on_receive_fields = function(pos, formname, fields, sender)
789 local meta = minetest.get_meta(pos)
790 local owner = meta:get_string("owner")
791 local pname = sender:get_player_name() or ""
792 if pname ~= owner and pname ~= minetest.setting_get("name")
793 and not minetest.check_player_privs(pname, {sign_editor=true}) then
796 signs_lib.receive_fields(pos, formname, fields, sender, true)
798 on_punch = function(pos, node, puncher)
799 signs_lib.update_sign(pos)
801 can_dig = function(pos, player)
802 local meta = minetest.get_meta(pos)
803 local owner = meta:get_string("owner")
804 local pname = player:get_player_name()
805 return pname == owner or pname == minetest.setting_get("name")
806 or minetest.check_player_privs(pname, {sign_editor=true})
808 on_rotate = signs_lib.wallmounted_rotate
811 -- default metal sign, if defined
813 if minetest.registered_nodes["default:sign_wall_steel"] then
814 minetest.register_node(":"..default_sign_metal, {
815 description = S("Sign"),
816 inventory_image = default_sign_metal_image,
817 wield_image = default_sign_metal_image,
818 node_placement_prediction = "",
819 sunlight_propagates = true,
821 paramtype2 = "wallmounted",
822 drawtype = "nodebox",
823 node_box = signs_lib.regular_wall_sign_model.nodebox,
824 tiles = {"signs_wall_sign_metal.png"},
825 groups = sign_groups,
827 on_place = function(itemstack, placer, pointed_thing)
828 return signs_lib.determine_sign_type(itemstack, placer, pointed_thing)
830 on_construct = function(pos)
831 signs_lib.construct_sign(pos)
833 on_destruct = function(pos)
834 signs_lib.destruct_sign(pos)
836 on_receive_fields = function(pos, formname, fields, sender)
837 signs_lib.receive_fields(pos, formname, fields, sender)
839 on_punch = function(pos, node, puncher)
840 signs_lib.update_sign(pos)
842 on_rotate = signs_lib.wallmounted_rotate
846 -- metal, colored signs
848 local sign_colors = { "green", "yellow", "red", "white_red", "white_black", "orange", "blue", "brown" }
849 local sign_default_text_colors = { "f", "0", "f", "4", "0", "0", "f", "f" }
851 for i, color in ipairs(sign_colors) do
852 minetest.register_node(":signs:sign_wall_"..color, {
853 description = S("Sign ("..color..", metal)"),
854 inventory_image = "signs_"..color.."_inv.png",
855 wield_image = "signs_"..color.."_inv.png",
856 node_placement_prediction = "",
858 sunlight_propagates = true,
859 paramtype2 = "facedir",
860 drawtype = "nodebox",
861 node_box = signs_lib.metal_wall_sign_model.nodebox,
863 "signs_metal_tb.png",
864 "signs_metal_tb.png",
865 "signs_metal_sides.png",
866 "signs_metal_sides.png",
867 "signs_metal_back.png",
868 "signs_"..color.."_front.png"
870 defaultcolor = sign_default_text_colors[i],
871 groups = sign_groups,
872 on_place = function(itemstack, placer, pointed_thing)
873 return signs_lib.determine_sign_type(itemstack, placer, pointed_thing)
875 on_construct = function(pos)
876 signs_lib.construct_sign(pos)
878 on_destruct = function(pos)
879 signs_lib.destruct_sign(pos)
881 on_receive_fields = function(pos, formname, fields, sender)
882 signs_lib.receive_fields(pos, formname, fields, sender)
884 on_punch = function(pos, node, puncher)
885 signs_lib.update_sign(pos)
890 local signs_text_on_activate
892 signs_text_on_activate = function(self)
893 local pos = self.object:getpos()
894 local meta = minetest.get_meta(pos)
895 local text = meta:get_string("text")
896 local new = (meta:get_int("__signslib_new_format") ~= 0)
898 text = trim_input(text)
899 set_obj_text(self.object, text, new, pos)
903 minetest.register_entity(":signs:text", {
904 collisionbox = { 0, 0, 0, 0, 0, 0 },
905 visual = "upright_sprite",
908 on_activate = signs_text_on_activate,
911 -- And the good stuff here! :-)
913 function signs_lib.register_fence_with_sign(fencename, fencewithsignname)
914 local def = minetest.registered_nodes[fencename]
915 local def_sign = minetest.registered_nodes[fencewithsignname]
916 if not (def and def_sign) then
917 minetest.log("warning", "[signs_lib] Attempt to register unknown node as fence")
920 def = signs_lib.table_copy(def)
921 def_sign = signs_lib.table_copy(def_sign)
922 fences_with_sign[fencename] = fencewithsignname
924 def_sign.on_place = function(itemstack, placer, pointed_thing, ...)
925 local node_above = minetest.get_node_or_nil(pointed_thing.above)
926 local node_under = minetest.get_node_or_nil(pointed_thing.under)
927 local def_above = node_above and minetest.registered_nodes[node_above.name]
928 local def_under = node_under and minetest.registered_nodes[node_under.name]
929 local fdir = minetest.dir_to_facedir(placer:get_look_dir())
930 local playername = placer:get_player_name()
932 if minetest.is_protected(pointed_thing.under, playername) then
933 minetest.record_protection_violation(pointed_thing.under, playername)
937 if minetest.is_protected(pointed_thing.above, playername) then
938 minetest.record_protection_violation(pointed_thing.above, playername)
942 if def_under and def_under.on_rightclick then
943 return def_under.on_rightclick(pointed_thing.under, node_under, placer, itemstack) or itemstack
944 elseif def_under and def_under.buildable_to then
945 minetest.add_node(pointed_thing.under, {name = fencename, param2 = fdir})
946 if not signs_lib.expect_infinite_stacks then
947 itemstack:take_item()
949 placer:set_wielded_item(itemstack)
950 elseif def_above and def_above.buildable_to then
951 minetest.add_node(pointed_thing.above, {name = fencename, param2 = fdir})
952 if not signs_lib.expect_infinite_stacks then
953 itemstack:take_item()
955 placer:set_wielded_item(itemstack)
959 def_sign.on_construct = function(pos, ...)
960 signs_lib.construct_sign(pos)
962 def_sign.on_destruct = function(pos, ...)
963 signs_lib.destruct_sign(pos)
965 def_sign.on_receive_fields = function(pos, formname, fields, sender)
966 signs_lib.receive_fields(pos, formname, fields, sender)
968 def_sign.on_punch = function(pos, node, puncher, ...)
969 signs_lib.update_sign(pos)
971 local fencename = fencename
972 def_sign.after_dig_node = function(pos, node, ...)
973 node.name = fencename
974 minetest.add_node(pos, node)
976 def_sign.drop = default_sign
977 minetest.register_node(":"..fencename, def)
978 minetest.register_node(":"..fencewithsignname, def_sign)
979 table.insert(signs_lib.sign_node_list, fencewithsignname)
980 minetest.log("verbose", S("Registered %s and %s"):format(fencename, fencewithsignname))
985 minetest.register_alias("homedecor:fence_wood_with_sign", "signs:sign_post")
986 minetest.register_alias("sign_wall_locked", "locked_sign:sign_wall_locked")
988 signs_lib.register_fence_with_sign("default:fence_wood", "signs:sign_post")
990 -- restore signs' text after /clearobjects and the like, the next time
991 -- a block is reloaded by the server.
993 minetest.register_lbm({
994 nodenames = signs_lib.sign_node_list,
995 name = "signs_lib:restore_sign_text",
996 label = "Restore sign text",
997 run_at_every_load = true,
998 action = function(pos, node)
999 signs_lib.update_sign(pos)
1005 minetest.register_craft({
1006 output = "locked_sign:sign_wall_locked",
1008 {"group:wood", "group:wood", "group:wood"},
1009 {"group:wood", "group:wood", "default:steel_ingot"},
1010 {"", "group:stick", ""},
1016 minetest.register_craft({
1017 output = "locked_sign:sign_wall_locked",
1020 {"default:steel_ingot"},
1024 -- craft recipes for the metal signs
1026 minetest.register_craft( {
1027 output = "signs:sign_wall_green",
1029 { "dye:dark_green", "dye:white", "dye:dark_green" },
1030 { "", default_sign_metal, "" }
1034 minetest.register_craft( {
1035 output = "signs:sign_wall_green 2",
1037 { "dye:dark_green", "dye:white", "dye:dark_green" },
1038 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1042 minetest.register_craft( {
1043 output = "signs:sign_wall_yellow",
1045 { "dye:yellow", "dye:black", "dye:yellow" },
1046 { "", default_sign_metal, "" }
1050 minetest.register_craft( {
1051 output = "signs:sign_wall_yellow 2",
1053 { "dye:yellow", "dye:black", "dye:yellow" },
1054 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1058 minetest.register_craft( {
1059 output = "signs:sign_wall_red",
1061 { "dye:red", "dye:white", "dye:red" },
1062 { "", default_sign_metal, "" }
1066 minetest.register_craft( {
1067 output = "signs:sign_wall_red 2",
1069 { "dye:red", "dye:white", "dye:red" },
1070 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1074 minetest.register_craft( {
1075 output = "signs:sign_wall_white_red",
1077 { "dye:white", "dye:red", "dye:white" },
1078 { "", default_sign_metal, "" }
1082 minetest.register_craft( {
1083 output = "signs:sign_wall_white_red 2",
1085 { "dye:white", "dye:red", "dye:white" },
1086 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1090 minetest.register_craft( {
1091 output = "signs:sign_wall_white_black",
1093 { "dye:white", "dye:black", "dye:white" },
1094 { "", default_sign_metal, "" }
1098 minetest.register_craft( {
1099 output = "signs:sign_wall_white_black 2",
1101 { "dye:white", "dye:black", "dye:white" },
1102 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1106 minetest.register_craft( {
1107 output = "signs:sign_wall_orange",
1109 { "dye:orange", "dye:black", "dye:orange" },
1110 { "", default_sign_metal, "" }
1114 minetest.register_craft( {
1115 output = "signs:sign_wall_orange 2",
1117 { "dye:orange", "dye:black", "dye:orange" },
1118 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1122 minetest.register_craft( {
1123 output = "signs:sign_wall_blue",
1125 { "dye:blue", "dye:white", "dye:blue" },
1126 { "", default_sign_metal, "" }
1130 minetest.register_craft( {
1131 output = "signs:sign_wall_blue 2",
1133 { "dye:blue", "dye:white", "dye:blue" },
1134 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1138 minetest.register_craft( {
1139 output = "signs:sign_wall_brown",
1141 { "dye:brown", "dye:white", "dye:brown" },
1142 { "", default_sign_metal, "" }
1146 minetest.register_craft( {
1147 output = "signs:sign_wall_brown 2",
1149 { "dye:brown", "dye:white", "dye:brown" },
1150 { "steel:sheet_metal", "steel:sheet_metal", "steel:sheet_metal" }
1154 if minetest.setting_get("log_mods") then
1155 minetest.log("action", S("signs loaded"))