api.lua 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  1. -- signs_lib api, backported from street_signs
  2. local S = signs_lib.gettext
  3. signs_lib.lbm_restore_nodes = {}
  4. signs_lib.old_fenceposts = {}
  5. signs_lib.old_fenceposts_replacement_signs = {}
  6. signs_lib.old_fenceposts_with_signs = {}
  7. -- Settings used for a standard wood or steel wall sign
  8. signs_lib.standard_lines = 6
  9. signs_lib.standard_hscale = 1
  10. signs_lib.standard_vscale = 1
  11. signs_lib.standard_lspace = 1
  12. signs_lib.standard_fsize = 15
  13. signs_lib.standard_xoffs = 4
  14. signs_lib.standard_yoffs = 0
  15. signs_lib.standard_cpl = 35
  16. signs_lib.standard_wood_groups = table.copy(minetest.registered_items["default:sign_wall_wood"].groups)
  17. signs_lib.standard_wood_groups.sign = 1
  18. signs_lib.standard_wood_groups.attached_node = nil
  19. signs_lib.standard_steel_groups = table.copy(minetest.registered_items["default:sign_wall_steel"].groups)
  20. signs_lib.standard_steel_groups.sign = 1
  21. signs_lib.standard_steel_groups.attached_node = nil
  22. signs_lib.standard_wood_sign_sounds = table.copy(minetest.registered_items["default:sign_wall_wood"].sounds)
  23. signs_lib.standard_steel_sign_sounds = table.copy(minetest.registered_items["default:sign_wall_steel"].sounds)
  24. signs_lib.default_text_scale = {x=10, y=10}
  25. signs_lib.old_widefont_signs = {}
  26. signs_lib.block_list = {}
  27. signs_lib.totalblocks = 0
  28. signs_lib.standard_yaw = {
  29. 0,
  30. math.pi / -2,
  31. math.pi,
  32. math.pi / 2,
  33. }
  34. signs_lib.wallmounted_yaw = {
  35. nil,
  36. nil,
  37. math.pi / -2,
  38. math.pi / 2,
  39. 0,
  40. math.pi,
  41. }
  42. signs_lib.fdir_to_back = {
  43. { 0, -1 },
  44. { -1, 0 },
  45. { 0, 1 },
  46. { 1, 0 },
  47. }
  48. signs_lib.wall_fdir_to_back = {
  49. nil,
  50. nil,
  51. { 0, 1 },
  52. { 0, -1 },
  53. { -1, 0 },
  54. { 1, 0 },
  55. }
  56. signs_lib.fdir_flip_to_back = {
  57. [0] = { 0, 2 },
  58. [1] = { 2, 0 },
  59. [2] = { 0, -2 },
  60. [3] = { -2, 0 }
  61. }
  62. signs_lib.wall_fdir_flip_to_back = {
  63. [2] = { 2, 0 },
  64. [3] = { -2, 0 },
  65. [4] = { 0, 2 },
  66. [5] = { 0, -2 },
  67. }
  68. signs_lib.fdir_to_back_left = {
  69. [0] = { -1, 1 },
  70. [1] = { 1, 1 },
  71. [2] = { 1, -1 },
  72. [3] = { -1, -1 }
  73. }
  74. signs_lib.wall_fdir_to_back_left = {
  75. [2] = { 1, 1 },
  76. [3] = { -1, -1 },
  77. [4] = { -1, 1 },
  78. [5] = { 1, -1 }
  79. }
  80. signs_lib.rotate_walldir = {
  81. [0] = 4,
  82. [1] = 0,
  83. [2] = 5,
  84. [3] = 1,
  85. [4] = 2,
  86. [5] = 3
  87. }
  88. signs_lib.rotate_walldir_simple = {
  89. [0] = 4,
  90. [1] = 4,
  91. [2] = 5,
  92. [3] = 4,
  93. [4] = 2,
  94. [5] = 3
  95. }
  96. signs_lib.rotate_facedir = {
  97. [0] = 1,
  98. [1] = 2,
  99. [2] = 3,
  100. [3] = 4,
  101. [4] = 6,
  102. [5] = 6,
  103. [6] = 0
  104. }
  105. signs_lib.rotate_facedir_simple = {
  106. [0] = 1,
  107. [1] = 2,
  108. [2] = 3,
  109. [3] = 0,
  110. [4] = 0,
  111. [5] = 0
  112. }
  113. signs_lib.flip_facedir = {
  114. [0] = 2,
  115. [1] = 3,
  116. [2] = 0,
  117. [3] = 1,
  118. [4] = 6,
  119. [5] = 4,
  120. [6] = 4
  121. }
  122. signs_lib.flip_walldir = {
  123. [0] = 1,
  124. [1] = 0,
  125. [2] = 3,
  126. [3] = 2,
  127. [4] = 5,
  128. [5] = 4
  129. }
  130. -- Initialize character texture cache
  131. local ctexcache = {}
  132. -- entity handling
  133. minetest.register_entity("signs_lib:text", {
  134. collisionbox = { 0, 0, 0, 0, 0, 0 },
  135. visual = "mesh",
  136. mesh = "signs_lib_standard_sign_entity_wall.obj",
  137. textures = {},
  138. static_save = false,
  139. backface_culling = false
  140. })
  141. function signs_lib.delete_objects(pos)
  142. local objects = minetest.get_objects_inside_radius(pos, 0.5)
  143. for _, v in ipairs(objects) do
  144. if v then
  145. local e = v:get_luaentity()
  146. if e and string.match(e.name, "sign.*text") then
  147. v:remove()
  148. end
  149. end
  150. end
  151. end
  152. function signs_lib.spawn_entity(pos, texture)
  153. local node = minetest.get_node(pos)
  154. local def = minetest.registered_items[node.name]
  155. if not def or not def.entity_info then return end
  156. local text_scale = (node and node.text_scale) or signs_lib.default_text_scale
  157. local objects = minetest.get_objects_inside_radius(pos, 0.5)
  158. local obj
  159. if #objects > 0 then
  160. for _, v in ipairs(objects) do
  161. if v then
  162. local e = v:get_luaentity()
  163. if e and e.name == "signs_lib:text" then
  164. obj = v
  165. end
  166. end
  167. end
  168. end
  169. if not obj then
  170. obj = minetest.add_entity(pos, "signs_lib:text")
  171. end
  172. local yaw = def.entity_info.yaw[node.param2 + 1]
  173. local pitch = 0
  174. if not string.find(node.name, "onpole") and not string.find(node.name, "hanging") then
  175. local rot90 = math.pi/2
  176. if def.paramtype2 == "wallmounted" then
  177. if node.param2 == 1 then -- on floor
  178. pitch = -rot90
  179. yaw = 0
  180. elseif node.param2 == 0 then -- on ceiling
  181. pitch = rot90
  182. yaw = math.pi
  183. end
  184. elseif def.paramtype2 == "facedir" then
  185. if node.param2 == 4 then
  186. pitch = -rot90
  187. yaw = 0
  188. elseif node.param2 == 6 then
  189. pitch = rot90
  190. yaw = math.pi
  191. end
  192. end
  193. end
  194. if yaw then
  195. obj:set_rotation({x = pitch, y = yaw, z=0})
  196. if not texture then
  197. obj:set_properties({
  198. mesh = def.entity_info.mesh,
  199. visual_size = text_scale,
  200. })
  201. else
  202. obj:set_properties({
  203. mesh = def.entity_info.mesh,
  204. visual_size = text_scale,
  205. textures={texture},
  206. })
  207. end
  208. end
  209. end
  210. function signs_lib.set_obj_text(pos, text)
  211. local split = signs_lib.split_lines_and_words
  212. local text_ansi = Utf8ToAnsi(text)
  213. local n = minetest.registered_nodes[minetest.get_node(pos).name]
  214. signs_lib.delete_objects(pos)
  215. signs_lib.spawn_entity(pos, signs_lib.make_sign_texture(split(text_ansi), pos) )
  216. end
  217. -- rotation
  218. function signs_lib.handle_rotation(pos, node, user, mode)
  219. if not signs_lib.can_modify(pos, user)
  220. or mode ~= screwdriver.ROTATE_FACE then
  221. return false
  222. end
  223. local newparam2
  224. local tpos = pos
  225. local def = minetest.registered_items[node.name]
  226. if string.match(node.name, "_onpole") then
  227. if not string.match(node.name, "_horiz") then
  228. newparam2 = signs_lib.rotate_walldir_simple[node.param2] or 4
  229. local t = signs_lib.wall_fdir_to_back_left
  230. if def.paramtype2 ~= "wallmounted" then
  231. newparam2 = signs_lib.rotate_facedir_simple[node.param2] or 0
  232. t = signs_lib.fdir_to_back_left
  233. end
  234. tpos = {
  235. x = pos.x + t[node.param2][1],
  236. y = pos.y,
  237. z = pos.z + t[node.param2][2]
  238. }
  239. else
  240. -- flip the sign to the other side of the horizontal pole
  241. newparam2 = signs_lib.flip_walldir[node.param2] or 4
  242. local t = signs_lib.wall_fdir_flip_to_back
  243. if def.paramtype2 ~= "wallmounted" then
  244. newparam2 = signs_lib.flip_facedir[node.param2] or 0
  245. t = signs_lib.fdir_flip_to_back
  246. end
  247. tpos = {
  248. x = pos.x + t[node.param2][1],
  249. y = pos.y,
  250. z = pos.z + t[node.param2][2]
  251. }
  252. end
  253. local node2 = minetest.get_node(tpos)
  254. local def2 = minetest.registered_items[node2.name]
  255. if not def2 or not def2.buildable_to then return true end -- undefined, or not buildable_to.
  256. minetest.set_node(tpos, {name = node.name, param2 = newparam2})
  257. minetest.get_meta(tpos):from_table(minetest.get_meta(pos):to_table())
  258. minetest.remove_node(pos)
  259. signs_lib.delete_objects(pos)
  260. elseif string.match(node.name, "_hanging") or string.match(node.name, "yard") then
  261. minetest.swap_node(tpos, { name = node.name, param2 = signs_lib.rotate_facedir_simple[node.param2] or 0 })
  262. elseif minetest.registered_items[node.name].paramtype2 == "wallmounted" then
  263. minetest.swap_node(tpos, { name = node.name, param2 = signs_lib.rotate_walldir[node.param2] or 0 })
  264. else
  265. minetest.swap_node(tpos, { name = node.name, param2 = signs_lib.rotate_facedir[node.param2] or 0 })
  266. end
  267. signs_lib.update_sign(tpos)
  268. return true
  269. end
  270. -- infinite stacks
  271. if not minetest.settings:get_bool("creative_mode") then
  272. signs_lib.expect_infinite_stacks = false
  273. else
  274. signs_lib.expect_infinite_stacks = true
  275. end
  276. -- CONSTANTS
  277. -- Path to the textures.
  278. local TP = signs_lib.path .. "/textures"
  279. -- Font file formatter
  280. local CHAR_FILE = "%s_%02x.png"
  281. -- Fonts path
  282. local CHAR_PATH = TP .. "/" .. CHAR_FILE
  283. -- Lots of overkill here. KISS advocates, go away, shoo! ;) -- kaeza
  284. local PNG_HDR = string.char(0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A)
  285. -- check if a file does exist
  286. -- to avoid reopening file after checking again
  287. -- pass TRUE as second argument
  288. local function file_exists(name, return_handle, mode)
  289. mode = mode or "r";
  290. local f = io.open(name, mode)
  291. if f ~= nil then
  292. if (return_handle) then
  293. return f
  294. end
  295. io.close(f)
  296. return true
  297. else
  298. return false
  299. end
  300. end
  301. -- Read the image size from a PNG file.
  302. -- Returns image_w, image_h.
  303. -- Only the LSB is read from each field!
  304. function signs_lib.read_image_size(filename)
  305. local f = file_exists(filename, true, "rb")
  306. -- file might not exist (don't crash the game)
  307. if (not f) then
  308. return 0, 0
  309. end
  310. f:seek("set", 0x0)
  311. local hdr = f:read(string.len(PNG_HDR))
  312. if hdr ~= PNG_HDR then
  313. f:close()
  314. return
  315. end
  316. f:seek("set", 0x13)
  317. local ws = f:read(1)
  318. f:seek("set", 0x17)
  319. local hs = f:read(1)
  320. f:close()
  321. return ws:byte(), hs:byte()
  322. end
  323. -- 4 rows, max 80 chars per, plus a bit of fudge to
  324. -- avoid excess trimming (e.g. due to color codes)
  325. local MAX_INPUT_CHARS = 400
  326. -- helper functions to trim sign text input/output
  327. local function trim_input(text)
  328. return text:sub(1, math.min(MAX_INPUT_CHARS, text:len()))
  329. end
  330. local function build_char_db(font_size)
  331. local cw = {}
  332. -- To calculate average char width.
  333. local total_width = 0
  334. local char_count = 0
  335. for c = 32, 255 do
  336. local w, h = signs_lib.read_image_size(CHAR_PATH:format("signs_lib_font_"..font_size.."px", c))
  337. if w and h then
  338. local ch = string.char(c)
  339. cw[ch] = w
  340. total_width = total_width + w
  341. char_count = char_count + 1
  342. end
  343. end
  344. local cbw, cbh = signs_lib.read_image_size(TP.."/signs_lib_color_"..font_size.."px_n.png")
  345. assert(cbw and cbh, "error reading bg dimensions")
  346. return cw, cbw, cbh, (total_width / char_count)
  347. end
  348. signs_lib.charwidth15,
  349. signs_lib.colorbgw15,
  350. signs_lib.lineheight15,
  351. signs_lib.avgwidth15 = build_char_db(15)
  352. signs_lib.charwidth31,
  353. signs_lib.colorbgw31,
  354. signs_lib.lineheight31,
  355. signs_lib.avgwidth31 = build_char_db(31)
  356. local sign_groups = {choppy=2, dig_immediate=2}
  357. local fences_with_sign = { }
  358. -- some local helper functions
  359. local math_max = math.max
  360. local function fill_line(x, y, w, c, font_size, colorbgw)
  361. c = c or "0"
  362. local tex = { }
  363. for xx = 0, math.max(0, w), colorbgw do
  364. table.insert(tex, (":%d,%d=signs_lib_color_"..font_size.."px_%s.png"):format(x + xx, y, c))
  365. end
  366. return table.concat(tex)
  367. end
  368. -- make char texture file name
  369. -- if texture file does not exist use fallback texture instead
  370. local function char_tex(font_name, ch)
  371. if ctexcache[font_name..ch] then
  372. return ctexcache[font_name..ch], true
  373. else
  374. local c = ch:byte()
  375. local exists, tex = file_exists(CHAR_PATH:format(font_name, c))
  376. if exists and c ~= 14 then
  377. tex = CHAR_FILE:format(font_name, c)
  378. else
  379. tex = CHAR_FILE:format(font_name, 0x0)
  380. end
  381. ctexcache[font_name..ch] = tex
  382. return tex, exists
  383. end
  384. end
  385. local function make_line_texture(line, lineno, pos, line_width, line_height, cwidth_tab, font_size, colorbgw)
  386. local width = 0
  387. local maxw = 0
  388. local font_name = "signs_lib_font_"..font_size.."px"
  389. local words = { }
  390. local node = minetest.get_node(pos)
  391. local def = minetest.registered_items[node.name]
  392. local default_color = def.default_color or 0
  393. local cur_color = tonumber(default_color, 16)
  394. -- We check which chars are available here.
  395. for word_i, word in ipairs(line) do
  396. local chars = { }
  397. local ch_offs = 0
  398. word = string.gsub(word, "%^[12345678abcdefgh]", {
  399. ["^1"] = string.char(0x81),
  400. ["^2"] = string.char(0x82),
  401. ["^3"] = string.char(0x83),
  402. ["^4"] = string.char(0x84),
  403. ["^5"] = string.char(0x85),
  404. ["^6"] = string.char(0x86),
  405. ["^7"] = string.char(0x87),
  406. ["^8"] = string.char(0x88),
  407. ["^a"] = string.char(0x8a),
  408. ["^b"] = string.char(0x8b),
  409. ["^c"] = string.char(0x8c),
  410. ["^d"] = string.char(0x8d),
  411. ["^e"] = string.char(0x8e),
  412. ["^f"] = string.char(0x8f),
  413. ["^g"] = string.char(0x90),
  414. ["^h"] = string.char(0x91)
  415. })
  416. local word_l = #word
  417. local i = 1
  418. while i <= word_l do
  419. local c = word:sub(i, i)
  420. if c == "#" then
  421. local cc = tonumber(word:sub(i+1, i+1), 16)
  422. if cc then
  423. i = i + 1
  424. cur_color = cc
  425. end
  426. else
  427. local w = cwidth_tab[c]
  428. if w then
  429. width = width + w + 1
  430. if width >= (line_width - cwidth_tab[" "]) then
  431. width = 0
  432. else
  433. maxw = math_max(width, maxw)
  434. end
  435. if #chars < MAX_INPUT_CHARS then
  436. table.insert(chars, {
  437. off = ch_offs,
  438. tex = char_tex(font_name, c),
  439. col = ("%X"):format(cur_color),
  440. })
  441. end
  442. ch_offs = ch_offs + w
  443. end
  444. end
  445. i = i + 1
  446. end
  447. width = width + cwidth_tab[" "] + 1
  448. maxw = math_max(width, maxw)
  449. table.insert(words, { chars=chars, w=ch_offs })
  450. end
  451. -- Okay, we actually build the "line texture" here.
  452. local texture = { }
  453. local start_xpos = math.floor((line_width - maxw) / 2) + def.x_offset
  454. local xpos = start_xpos
  455. local ypos = (line_height + def.line_spacing)* lineno + def.y_offset
  456. cur_color = nil
  457. for word_i, word in ipairs(words) do
  458. local xoffs = (xpos - start_xpos)
  459. if (xoffs > 0) and ((xoffs + word.w) > maxw) then
  460. table.insert(texture, fill_line(xpos, ypos, maxw, "n", font_size, colorbgw))
  461. xpos = start_xpos
  462. ypos = ypos + line_height + def.line_spacing
  463. lineno = lineno + 1
  464. if lineno >= def.number_of_lines then break end
  465. table.insert(texture, fill_line(xpos, ypos, maxw, cur_color, font_size, colorbgw))
  466. end
  467. for ch_i, ch in ipairs(word.chars) do
  468. if ch.col ~= cur_color then
  469. cur_color = ch.col
  470. table.insert(texture, fill_line(xpos + ch.off, ypos, maxw, cur_color, font_size, colorbgw))
  471. end
  472. table.insert(texture, (":%d,%d=%s"):format(xpos + ch.off, ypos, ch.tex))
  473. end
  474. table.insert(
  475. texture,
  476. (":%d,%d="):format(xpos + word.w, ypos) .. char_tex(font_name, " ")
  477. )
  478. xpos = xpos + word.w + cwidth_tab[" "]
  479. if xpos >= (line_width + cwidth_tab[" "]) then break end
  480. end
  481. table.insert(texture, fill_line(xpos, ypos, maxw, "n", font_size, colorbgw))
  482. table.insert(texture, fill_line(start_xpos, ypos + line_height, maxw, "n", font_size, colorbgw))
  483. return table.concat(texture), lineno
  484. end
  485. function signs_lib.make_sign_texture(lines, pos)
  486. local node = minetest.get_node(pos)
  487. local meta = minetest.get_meta(pos)
  488. local def = minetest.registered_items[node.name]
  489. if not def or not def.entity_info then return end
  490. local font_size
  491. local line_width
  492. local line_height
  493. local char_width
  494. local colorbgw
  495. local widemult = 1
  496. if meta:get_int("widefont") == 1 then
  497. widemult = 0.5
  498. end
  499. if def.font_size and def.font_size == 31 then
  500. font_size = 31
  501. line_width = math.floor(signs_lib.avgwidth31 * def.chars_per_line) * (def.horiz_scaling * widemult)
  502. line_height = signs_lib.lineheight31
  503. char_width = signs_lib.charwidth31
  504. colorbgw = signs_lib.colorbgw31
  505. else
  506. font_size = 15
  507. line_width = math.floor(signs_lib.avgwidth15 * def.chars_per_line) * (def.horiz_scaling * widemult)
  508. line_height = signs_lib.lineheight15
  509. char_width = signs_lib.charwidth15
  510. colorbgw = signs_lib.colorbgw15
  511. end
  512. local texture = { ("[combine:%dx%d"):format(line_width, (line_height + def.line_spacing) * def.number_of_lines * def.vert_scaling) }
  513. local lineno = 0
  514. for i = 1, #lines do
  515. if lineno >= def.number_of_lines then break end
  516. local linetex, ln = make_line_texture(lines[i], lineno, pos, line_width, line_height, char_width, font_size, colorbgw)
  517. table.insert(texture, linetex)
  518. lineno = ln + 1
  519. end
  520. table.insert(texture, "^[makealpha:0,0,0")
  521. return table.concat(texture, "")
  522. end
  523. function signs_lib.split_lines_and_words(text)
  524. if not text then return end
  525. local lines = { }
  526. for _, line in ipairs(text:split("\n", true)) do
  527. table.insert(lines, line:split(" "))
  528. end
  529. return lines
  530. end
  531. function signs_lib.construct_sign(pos)
  532. local form = "size[6,4]"..
  533. "textarea[0,-0.3;6.5,3;text;;${text}]"..
  534. "background[-0.5,-0.5;7,5;signs_lib_sign_bg.jpg]"
  535. local node = minetest.get_node(pos)
  536. local def = minetest.registered_items[node.name]
  537. local meta = minetest.get_meta(pos)
  538. if def.allow_widefont then
  539. local state = "off"
  540. if meta:get_int("widefont") == 1 then state = "on" end
  541. form = form.."label[1,3.4;Use wide font]"..
  542. "image_button[1.1,3.7;1,0.6;signs_lib_switch_"..
  543. state..".png;"..
  544. state..";;;false;signs_lib_switch_interm.png]"..
  545. "button_exit[3,3.4;2,1;ok;"..S("Write").."]"
  546. else
  547. form = form.."button_exit[2,3.4;2,1;ok;"..S("Write").."]"
  548. end
  549. meta:set_string("formspec", form)
  550. local i = meta:get_string("infotext")
  551. if i == "" then -- it wasn't even set, so set it.
  552. meta:set_string("infotext", "")
  553. end
  554. end
  555. function signs_lib.destruct_sign(pos)
  556. signs_lib.delete_objects(pos)
  557. end
  558. local function make_infotext(text)
  559. text = trim_input(text)
  560. local lines = signs_lib.split_lines_and_words(text) or {}
  561. local lines2 = { }
  562. for _, line in ipairs(lines) do
  563. table.insert(lines2, (table.concat(line, " "):gsub("#[0-9a-fA-F]", ""):gsub("##", "#")))
  564. end
  565. return table.concat(lines2, "\n")
  566. end
  567. function signs_lib.update_sign(pos, fields)
  568. local meta = minetest.get_meta(pos)
  569. local text = fields and fields.text or meta:get_string("text")
  570. text = trim_input(text)
  571. local owner = meta:get_string("owner")
  572. local ownstr = ""
  573. if owner ~= "" then ownstr = S("Locked sign, owned by @1\n", owner) end
  574. meta:set_string("text", text)
  575. meta:set_string("infotext", ownstr..make_infotext(text).." ")
  576. signs_lib.set_obj_text(pos, text)
  577. end
  578. function signs_lib.receive_fields(pos, formname, fields, sender)
  579. if not fields or not signs_lib.can_modify(pos, sender) then return end
  580. if fields.text and fields.ok then
  581. minetest.log("action", S("@1 wrote \"@2\" to sign at @3",
  582. (sender:get_player_name() or ""),
  583. fields.text:gsub('\\', '\\\\'):gsub("\n", "\\n"),
  584. minetest.pos_to_string(pos)
  585. ))
  586. signs_lib.update_sign(pos, fields)
  587. elseif fields.on or fields.off then
  588. local node = minetest.get_node(pos)
  589. local meta = minetest.get_meta(pos)
  590. local change
  591. if fields.on and meta:get_int("widefont") == 1 then
  592. meta:set_int("widefont", 0)
  593. change = true
  594. elseif fields.off and meta:get_int("widefont") == 0 then
  595. meta:set_int("widefont", 1)
  596. change = true
  597. end
  598. if change then
  599. minetest.log("action", S("@1 flipped the wide-font switch to \"@2\" at @3",
  600. (sender:get_player_name() or ""),
  601. (fields.on and "off" or "on"),
  602. minetest.pos_to_string(pos)
  603. ))
  604. signs_lib.construct_sign(pos)
  605. signs_lib.update_sign(pos, fields)
  606. end
  607. end
  608. end
  609. function signs_lib.can_modify(pos, player)
  610. local meta = minetest.get_meta(pos)
  611. local owner = meta:get_string("owner")
  612. local playername = player:get_player_name()
  613. if minetest.is_protected(pos, playername) then
  614. minetest.record_protection_violation(pos, playername)
  615. return false
  616. end
  617. if owner == ""
  618. or playername == owner
  619. or (minetest.check_player_privs(playername, {sign_editor=true}))
  620. or (playername == minetest.settings:get("name")) then
  621. return true
  622. end
  623. minetest.record_protection_violation(pos, playername)
  624. return false
  625. end
  626. -- make selection boxes
  627. -- sizex/sizey specified in inches because that's what MUTCD uses.
  628. function signs_lib.make_selection_boxes(sizex, sizey, foo, xoffs, yoffs, zoffs, is_facedir)
  629. local tx = (sizex * 0.0254 ) / 2
  630. local ty = (sizey * 0.0254 ) / 2
  631. local xo = xoffs and xoffs * 0.0254 or 0
  632. local yo = yoffs and yoffs * 0.0254 or 0
  633. local zo = zoffs and zoffs * 0.0254 or 0
  634. if not is_facedir then
  635. return {
  636. type = "wallmounted",
  637. wall_side = { -0.5 + zo, -ty + yo, -tx + xo, -0.4375 + zo, ty + yo, tx + xo },
  638. wall_top = { -tx - xo, 0.5 + zo, -ty + yo, tx - xo, 0.4375 + zo, ty + yo},
  639. wall_bottom = { -tx - xo, -0.5 + zo, -ty + yo, tx - xo, -0.4375 + zo, ty + yo }
  640. }
  641. else
  642. return {
  643. type = "fixed",
  644. fixed = { -tx + xo, -ty + yo, 0.5 + zo, tx + xo, ty + yo, 0.4375 + zo}
  645. }
  646. end
  647. end
  648. function signs_lib.check_for_pole(pos, pointed_thing)
  649. local ppos = minetest.get_pointed_thing_position(pointed_thing)
  650. local pnode = minetest.get_node(ppos)
  651. local pdef = minetest.registered_items[pnode.name]
  652. if not pdef then return end
  653. if signs_lib.check_for_ceiling(pointed_thing) or signs_lib.check_for_floor(pointed_thing) then
  654. return false
  655. end
  656. if type(pdef.check_for_pole) == "function" then
  657. local node = minetest.get_node(pos)
  658. local def = minetest.registered_items[node.name]
  659. return pdef.check_for_pole(pos, node, def, ppos, pnode, pdef)
  660. elseif pdef.check_for_pole
  661. or pdef.drawtype == "fencelike"
  662. or string.find(pnode.name, "_post")
  663. or string.find(pnode.name, "fencepost") then
  664. return true
  665. end
  666. end
  667. function signs_lib.check_for_horizontal_pole(pos, pointed_thing)
  668. local ppos = minetest.get_pointed_thing_position(pointed_thing)
  669. local pnode = minetest.get_node(ppos)
  670. local pdef = minetest.registered_items[pnode.name]
  671. if not pdef then return end
  672. if signs_lib.check_for_ceiling(pointed_thing) or signs_lib.check_for_floor(pointed_thing) then
  673. return false
  674. end
  675. if type(pdef.check_for_horiz_pole) == "function" then
  676. local node = minetest.get_node(pos)
  677. local def = minetest.registered_items[node.name]
  678. return pdef.check_for_horiz_pole(pos, node, def, ppos, pnode, pdef)
  679. end
  680. end
  681. function signs_lib.check_for_ceiling(pointed_thing)
  682. if pointed_thing.above.x == pointed_thing.under.x
  683. and pointed_thing.above.z == pointed_thing.under.z
  684. and pointed_thing.above.y < pointed_thing.under.y then
  685. return true
  686. end
  687. end
  688. function signs_lib.check_for_floor(pointed_thing)
  689. if pointed_thing.above.x == pointed_thing.under.x
  690. and pointed_thing.above.z == pointed_thing.under.z
  691. and pointed_thing.above.y > pointed_thing.under.y then
  692. return true
  693. end
  694. end
  695. function signs_lib.after_place_node(pos, placer, itemstack, pointed_thing, locked)
  696. local playername = placer:get_player_name()
  697. local controls = placer:get_player_control()
  698. local signname = itemstack:get_name()
  699. local no_wall_name = string.gsub(signname, "_wall", "")
  700. local def = minetest.registered_items[signname]
  701. local ppos = minetest.get_pointed_thing_position(pointed_thing)
  702. local pnode = minetest.get_node(ppos)
  703. local pdef = minetest.registered_items[pnode.name]
  704. if def.allow_onpole and signs_lib.check_for_pole(pos, pointed_thing) and not controls.sneak then
  705. local newparam2
  706. local lookdir = minetest.yaw_to_dir(placer:get_look_horizontal())
  707. if def.paramtype2 == "wallmounted" then
  708. newparam2 = minetest.dir_to_wallmounted(lookdir)
  709. else
  710. newparam2 = minetest.dir_to_facedir(lookdir)
  711. end
  712. local node = minetest.get_node(pos)
  713. minetest.swap_node(pos, {name = no_wall_name.."_onpole", param2 = newparam2})
  714. elseif def.allow_onpole_horizontal and signs_lib.check_for_horizontal_pole(pos, pointed_thing) and not controls.sneak then
  715. local newparam2
  716. local lookdir = minetest.yaw_to_dir(placer:get_look_horizontal())
  717. if def.paramtype2 == "wallmounted" then
  718. newparam2 = minetest.dir_to_wallmounted(lookdir)
  719. else
  720. newparam2 = minetest.dir_to_facedir(lookdir)
  721. end
  722. local node = minetest.get_node(pos)
  723. minetest.swap_node(pos, {name = no_wall_name.."_onpole_horiz", param2 = newparam2})
  724. elseif def.allow_hanging and signs_lib.check_for_ceiling(pointed_thing) and not controls.sneak then
  725. local newparam2 = minetest.dir_to_facedir(placer:get_look_dir())
  726. local node = minetest.get_node(pos)
  727. minetest.swap_node(pos, {name = no_wall_name.."_hanging", param2 = newparam2})
  728. elseif def.allow_yard and signs_lib.check_for_floor(pointed_thing) and not controls.sneak then
  729. local newparam2 = minetest.dir_to_facedir(placer:get_look_dir())
  730. local node = minetest.get_node(pos)
  731. minetest.swap_node(pos, {name = no_wall_name.."_yard", param2 = newparam2})
  732. elseif def.paramtype2 == "facedir" and signs_lib.check_for_ceiling(pointed_thing) then
  733. minetest.swap_node(pos, {name = signname, param2 = 6})
  734. elseif def.paramtype2 == "facedir" and signs_lib.check_for_floor(pointed_thing) then
  735. minetest.swap_node(pos, {name = signname, param2 = 4})
  736. end
  737. if locked then
  738. local meta = minetest.get_meta(pos)
  739. meta:set_string("owner", playername)
  740. meta:set_string("infotext", S("Locked sign, owned by @1\n", playername))
  741. end
  742. end
  743. function signs_lib.register_fence_with_sign()
  744. minetest.log("warning", "[signs_lib] ".."Attempt to call no longer used function signs_lib.register_fence_with_sign()")
  745. end
  746. function signs_lib.register_sign(name, raw_def)
  747. local def = table.copy(raw_def)
  748. if raw_def.entity_info == "standard" then
  749. def.entity_info = {
  750. mesh = "signs_lib_standard_sign_entity_wall.obj",
  751. yaw = signs_lib.wallmounted_yaw
  752. }
  753. elseif raw_def.entity_info then
  754. def.entity_info = raw_def.entity_info
  755. end
  756. def.after_place_node = raw_def.after_place_node or signs_lib.after_place_node
  757. if raw_def.entity_info then
  758. def.on_rightclick = raw_def.on_rightclick or signs_lib.construct_sign
  759. def.on_construct = raw_def.on_construct or signs_lib.construct_sign
  760. def.on_destruct = raw_def.on_destruct or signs_lib.destruct_sign
  761. def.on_receive_fields = raw_def.on_receive_fields or signs_lib.receive_fields
  762. def.on_punch = raw_def.on_punch or signs_lib.update_sign
  763. def.number_of_lines = raw_def.number_of_lines or signs_lib.standard_lines
  764. def.horiz_scaling = raw_def.horiz_scaling or signs_lib.standard_hscale
  765. def.vert_scaling = raw_def.vert_scaling or signs_lib.standard_vscale
  766. def.line_spacing = raw_def.line_spacing or signs_lib.standard_lspace
  767. def.font_size = raw_def.font_size or signs_lib.standard_fsize
  768. def.x_offset = raw_def.x_offset or signs_lib.standard_xoffs
  769. def.y_offset = raw_def.y_offset or signs_lib.standard_yoffs
  770. def.chars_per_line = raw_def.chars_per_line or signs_lib.standard_cpl
  771. def.default_color = raw_def.default_color or "0"
  772. if raw_def.locked and not raw_def.after_place_node then
  773. def.after_place_node = function(pos, placer, itemstack, pointed_thing)
  774. signs_lib.after_place_node(pos, placer, itemstack, pointed_thing, true)
  775. end
  776. end
  777. end
  778. def.paramtype = raw_def.paramtype or "light"
  779. def.drawtype = raw_def.drawtype or "mesh"
  780. def.mesh = raw_def.mesh or "signs_lib_standard_sign_wall.obj"
  781. def.wield_image = raw_def.wield_image or def.inventory_image
  782. def.drop = raw_def.drop or name
  783. def.sounds = raw_def.sounds or signs_lib.standard_wood_sign_sounds
  784. def.paramtype2 = raw_def.paramtype2 or "wallmounted"
  785. def.on_rotate = raw_def.on_rotate or signs_lib.handle_rotation
  786. if raw_def.groups then
  787. def.groups = raw_def.groups
  788. else
  789. def.groups = signs_lib.standard_wood_groups
  790. end
  791. local cbox = signs_lib.make_selection_boxes(35, 25)
  792. def.selection_box = raw_def.selection_box or cbox
  793. def.node_box = table.copy(raw_def.node_box or raw_def.selection_box or cbox)
  794. if def.sunlight_propagates ~= false then
  795. def.sunlight_propagates = true
  796. end
  797. def.tiles[3] = "signs_lib_blank.png"
  798. def.tiles[4] = "signs_lib_blank.png"
  799. def.tiles[5] = "signs_lib_blank.png"
  800. def.tiles[6] = "signs_lib_blank.png"
  801. minetest.register_node(":"..name, def)
  802. table.insert(signs_lib.lbm_restore_nodes, name)
  803. local no_wall_name = string.gsub(name, "_wall", "")
  804. local othermounts_def = table.copy(def)
  805. if raw_def.allow_onpole or raw_def.allow_onpole_horizontal then
  806. local offset = 0.3125
  807. if othermounts_def.uses_slim_pole_mount then
  808. offset = 0.35
  809. end
  810. othermounts_def.selection_box = raw_def.onpole_selection_box or othermounts_def.selection_box
  811. othermounts_def.node_box = raw_def.onpole_node_box or othermounts_def.selection_box
  812. if othermounts_def.paramtype2 == "wallmounted" then
  813. othermounts_def.node_box.wall_side[1] = def.node_box.wall_side[1] - offset
  814. othermounts_def.node_box.wall_side[4] = def.node_box.wall_side[4] - offset
  815. othermounts_def.selection_box.wall_side[1] = def.selection_box.wall_side[1] - offset
  816. othermounts_def.selection_box.wall_side[4] = def.selection_box.wall_side[4] - offset
  817. else
  818. othermounts_def.node_box.fixed[3] = def.node_box.fixed[3] + offset
  819. othermounts_def.node_box.fixed[6] = def.node_box.fixed[6] + offset
  820. othermounts_def.selection_box.fixed[3] = def.selection_box.fixed[3] + offset
  821. othermounts_def.selection_box.fixed[6] = def.selection_box.fixed[6] + offset
  822. end
  823. othermounts_def.groups.not_in_creative_inventory = 1
  824. othermounts_def.mesh = raw_def.onpole_mesh or string.gsub(othermounts_def.mesh, "wall.obj$", "onpole.obj")
  825. if othermounts_def.entity_info then
  826. othermounts_def.entity_info.mesh = string.gsub(othermounts_def.entity_info.mesh, "entity_wall.obj$", "entity_onpole.obj")
  827. end
  828. end
  829. -- setting one of item 3 or 4 to a texture and leaving the other "blank",
  830. -- reveals either the vertical or horizontal pole mount part of the model
  831. if raw_def.allow_onpole then
  832. othermounts_def.tiles[3] = raw_def.tiles[3] or "signs_lib_pole_mount.png"
  833. othermounts_def.tiles[4] = "signs_lib_blank.png"
  834. othermounts_def.tiles[5] = "signs_lib_blank.png"
  835. othermounts_def.tiles[6] = "signs_lib_blank.png"
  836. minetest.register_node(":"..no_wall_name.."_onpole", othermounts_def)
  837. table.insert(signs_lib.lbm_restore_nodes, no_wall_name.."_onpole")
  838. end
  839. if raw_def.allow_onpole_horizontal then
  840. local onpole_horiz_def = table.copy(othermounts_def)
  841. onpole_horiz_def.tiles[3] = "signs_lib_blank.png"
  842. onpole_horiz_def.tiles[4] = raw_def.tiles[3] or "signs_lib_pole_mount.png"
  843. onpole_horiz_def.tiles[5] = "signs_lib_blank.png"
  844. onpole_horiz_def.tiles[6] = "signs_lib_blank.png"
  845. minetest.register_node(":"..no_wall_name.."_onpole_horiz", onpole_horiz_def)
  846. table.insert(signs_lib.lbm_restore_nodes, no_wall_name.."_onpole_horiz")
  847. end
  848. if raw_def.allow_hanging then
  849. local hanging_def = table.copy(def)
  850. hanging_def.paramtype2 = "facedir"
  851. local hcbox = signs_lib.make_selection_boxes(35, 32, nil, 0, 3, -18.5, true)
  852. hanging_def.selection_box = raw_def.hanging_selection_box or hcbox
  853. hanging_def.node_box = raw_def.hanging_node_box or raw_def.hanging_selection_box or hcbox
  854. hanging_def.groups.not_in_creative_inventory = 1
  855. hanging_def.tiles[3] = raw_def.tiles[4] or "signs_lib_hangers.png"
  856. hanging_def.tiles[4] = "signs_lib_blank.png"
  857. hanging_def.tiles[5] = "signs_lib_blank.png"
  858. hanging_def.tiles[6] = "signs_lib_blank.png"
  859. hanging_def.mesh = raw_def.hanging_mesh or string.gsub(string.gsub(hanging_def.mesh, "wall.obj$", "hanging.obj"), "_facedir", "")
  860. if hanging_def.entity_info then
  861. hanging_def.entity_info.mesh = string.gsub(string.gsub(hanging_def.entity_info.mesh, "entity_wall.obj$", "entity_hanging.obj"), "_facedir", "")
  862. hanging_def.entity_info.yaw = signs_lib.standard_yaw
  863. end
  864. minetest.register_node(":"..no_wall_name.."_hanging", hanging_def)
  865. table.insert(signs_lib.lbm_restore_nodes, no_wall_name.."_hanging")
  866. end
  867. if raw_def.allow_yard then
  868. local ydef = table.copy(def)
  869. ydef.paramtype2 = "facedir"
  870. local ycbox = signs_lib.make_selection_boxes(35, 34.5, false, 0, -1.25, -19.69, true)
  871. ydef.selection_box = raw_def.yard_selection_box or ycbox
  872. ydef.tiles[3] = raw_def.tiles[5] or "default_wood.png"
  873. ydef.tiles[4] = "signs_lib_blank.png"
  874. ydef.tiles[5] = "signs_lib_blank.png"
  875. ydef.tiles[6] = "signs_lib_blank.png"
  876. ydef.node_box = raw_def.yard_node_box or raw_def.yard_selection_box or ycbox
  877. ydef.groups.not_in_creative_inventory = 1
  878. ydef.mesh = raw_def.yard_mesh or string.gsub(string.gsub(ydef.mesh, "wall.obj$", "yard.obj"), "_facedir", "")
  879. if ydef.entity_info then
  880. ydef.entity_info.mesh = string.gsub(string.gsub(ydef.entity_info.mesh, "entity_wall.obj$", "entity_yard.obj"), "_facedir", "")
  881. ydef.entity_info.yaw = signs_lib.standard_yaw
  882. end
  883. minetest.register_node(":"..no_wall_name.."_yard", ydef)
  884. table.insert(signs_lib.lbm_restore_nodes, no_wall_name.."_yard")
  885. end
  886. if raw_def.allow_widefont then
  887. table.insert(signs_lib.old_widefont_signs, name.."_widefont")
  888. table.insert(signs_lib.old_widefont_signs, name.."_widefont_onpole")
  889. table.insert(signs_lib.old_widefont_signs, name.."_widefont_hanging")
  890. table.insert(signs_lib.old_widefont_signs, name.."_widefont_yard")
  891. end
  892. end
  893. -- restore signs' text after /clearobjects and the like, the next time
  894. -- a block is reloaded by the server.
  895. minetest.register_lbm({
  896. nodenames = signs_lib.lbm_restore_nodes,
  897. name = "signs_lib:restore_sign_text",
  898. label = "Restore sign text",
  899. run_at_every_load = true,
  900. action = function(pos, node)
  901. signs_lib.update_sign(pos,nil,nil,node)
  902. end
  903. })
  904. -- Convert old signs on fenceposts into signs on.. um.. fence posts :P
  905. minetest.register_lbm({
  906. nodenames = signs_lib.old_fenceposts_with_signs,
  907. name = "signs_lib:fix_fencepost_signs",
  908. label = "Change single-node signs on fences into normal",
  909. run_at_every_load = true,
  910. action = function(pos, node)
  911. local fdir = node.param2 % 8
  912. local signpos = {
  913. x = pos.x + signs_lib.fdir_to_back[fdir+1][1],
  914. y = pos.y,
  915. z = pos.z + signs_lib.fdir_to_back[fdir+1][2]
  916. }
  917. if minetest.get_node(signpos).name == "air" then
  918. local new_wmdir = minetest.dir_to_wallmounted(minetest.facedir_to_dir(fdir))
  919. local oldfence = signs_lib.old_fenceposts[node.name]
  920. local newsign = signs_lib.old_fenceposts_replacement_signs[node.name]
  921. signs_lib.delete_objects(pos)
  922. local oldmeta = minetest.get_meta(pos):to_table()
  923. minetest.set_node(pos, {name = oldfence})
  924. minetest.set_node(signpos, { name = newsign, param2 = new_wmdir })
  925. local newmeta = minetest.get_meta(signpos)
  926. newmeta:from_table(oldmeta)
  927. signs_lib.update_sign(signpos)
  928. end
  929. end
  930. })
  931. -- Convert widefont sign nodes to use one base node with meta flag to select wide mode
  932. minetest.register_lbm({
  933. nodenames = signs_lib.old_widefont_signs,
  934. name = "signs_lib:convert_widefont_signs",
  935. label = "Convert widefont sign nodes",
  936. run_at_every_load = false,
  937. action = function(pos, node)
  938. local basename = string.gsub(node.name, "_widefont", "")
  939. minetest.swap_node(pos, {name = basename, param2 = node.param2})
  940. local meta = minetest.get_meta(pos)
  941. meta:set_int("widefont", 1)
  942. signs_lib.update_sign(pos)
  943. end
  944. })
  945. -- Maintain a list of currently-loaded blocks
  946. minetest.register_lbm({
  947. nodenames = {"group:sign"},
  948. name = "signs_lib:update_block_list",
  949. label = "Update list of loaded blocks, log only those with signs",
  950. run_at_every_load = true,
  951. action = function(pos, node)
  952. -- yeah, yeah... I know I'm hashing a block pos, but it's still just a set of coords
  953. local hash = minetest.hash_node_position(vector.floor(vector.divide(pos, core.MAP_BLOCKSIZE)))
  954. if not signs_lib.block_list[hash] then
  955. signs_lib.block_list[hash] = true
  956. signs_lib.totalblocks = signs_lib.totalblocks + 1
  957. end
  958. end
  959. })
  960. minetest.register_chatcommand("regen_signs", {
  961. params = "",
  962. privs = {server = true},
  963. description = "Skims through all currently-loaded sign-bearing mapblocks, clears away any entities within each sign's node space, and regenerates their text entities, if any.",
  964. func = function(player_name, params)
  965. local allsigns = {}
  966. local totalsigns = 0
  967. for b in pairs(signs_lib.block_list) do
  968. local blockpos = minetest.get_position_from_hash(b)
  969. local pos1 = vector.multiply(blockpos, core.MAP_BLOCKSIZE)
  970. local pos2 = vector.add(pos1, core.MAP_BLOCKSIZE - 1)
  971. if minetest.get_node_or_nil(vector.add(pos1, core.MAP_BLOCKSIZE/2)) then
  972. local signs_in_block = minetest.find_nodes_in_area(pos1, pos2, {"group:sign"})
  973. allsigns[#allsigns + 1] = signs_in_block
  974. totalsigns = totalsigns + #signs_in_block
  975. else
  976. signs_lib.block_list[b] = nil -- if the block is no longer loaded, remove it from the table
  977. signs_lib.totalblocks = signs_lib.totalblocks - 1
  978. end
  979. end
  980. if signs_lib.totalblocks < 0 then signs_lib.totalblocks = 0 end
  981. if totalsigns == 0 then
  982. minetest.chat_send_player(player_name, "There are no signs in the currently-loaded terrain.")
  983. signs_lib.block_list = {}
  984. return
  985. end
  986. minetest.chat_send_player(player_name, "Found a total of "..totalsigns.." sign nodes across "..signs_lib.totalblocks.." blocks.")
  987. minetest.chat_send_player(player_name, "Regenerating sign entities...")
  988. for _, b in pairs(allsigns) do
  989. for _, pos in ipairs(b) do
  990. signs_lib.delete_objects(pos)
  991. local node = minetest.get_node(pos)
  992. local def = minetest.registered_items[node.name]
  993. if def and def.entity_info then
  994. signs_lib.update_sign(pos)
  995. end
  996. end
  997. end
  998. minetest.chat_send_player(player_name, "Finished.")
  999. end
  1000. })