nodes.lua 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. --[[
  2. steles mod for Minetest. Steles / graves with text on it.
  3. (c) Pierre-Yves Rollo
  4. This file is part of steles.
  5. steles is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. steles is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with steles. If not, see <http://www.gnu.org/licenses/>.
  15. --]]
  16. local S = steles.intllib
  17. local F = function(...) return minetest.formspec_escape(S(...)) end
  18. display_api.register_display_entity("steles:text")
  19. for i, material in ipairs(steles.materials) do
  20. local ndef = minetest.registered_nodes[material]
  21. if ndef then
  22. local groups = table.copy(ndef.groups)
  23. local parts = material:split(":")
  24. groups.display_api = 1
  25. minetest.register_node("steles:"..parts[2].."_stele", {
  26. description = steles.materials_desc[i],
  27. sunlight_propagates = true,
  28. paramtype = "light",
  29. paramtype2 = "facedir",
  30. tiles = ndef.tiles,
  31. drawtype = "nodebox",
  32. node_box = {
  33. type = "fixed",
  34. fixed = {
  35. {-5/16, -5/16, -2/16, 5/16, 0.5, 2/16},
  36. {-7/16, -0.5, -4/16, 7/16, -5/16, 4/16}
  37. },
  38. },
  39. groups = groups,
  40. display_entities = {
  41. ["steles:text"] = {
  42. on_display_update = font_api.on_display_update,
  43. depth = -2/16 - display_api.entity_spacing,
  44. top = -2/16,
  45. aspect_ratio = 0.4,
  46. size = { x = 10/16, y = 12/16 },
  47. maxlines = 3,
  48. },
  49. },
  50. on_place = function(itemstack, placer, pointed_thing)
  51. minetest.rotate_node(itemstack, placer, pointed_thing)
  52. return display_api.on_place(itemstack, placer, pointed_thing)
  53. end,
  54. on_construct = function(pos)
  55. local meta = minetest.get_meta(pos)
  56. meta:set_string("formspec", string.format([=[
  57. size[6,4]%s%s%s
  58. textarea[0.5,0.7;5.5,2;display_text;%s;${display_text}]
  59. button[1,3;2,1;font;%s]
  60. button_exit[3,3;2,1;ok;%s]]=],
  61. default.gui_bg, default.gui_bg_img, default.gui_slots,
  62. F("Displayed text (3 lines max)"),
  63. F("Font"), F("Write")))
  64. display_api.on_construct(pos)
  65. end,
  66. on_destruct = display_api.on_destruct,
  67. on_rotate = display_api.on_rotate,
  68. on_receive_fields = function(pos, formname, fields, player)
  69. if not minetest.is_protected(pos, player:get_player_name()) then
  70. local meta = minetest.get_meta(pos)
  71. if fields.ok or fields.font then
  72. meta:set_string("display_text", fields.display_text)
  73. meta:set_string("infotext", "\""..fields.display_text.."\"")
  74. display_api.update_entities(pos)
  75. end
  76. if fields.font then
  77. font_api.show_font_list(player, pos)
  78. end
  79. end
  80. end,
  81. on_punch = display_api.update_entities,
  82. })
  83. end
  84. end