init.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. signs = signs or {}
  2. signs.modpath = minetest.get_modpath("signs")
  3. function signs.on_punch(pos, node, puncher, pt)
  4. minetest.get_meta(pos):set_string("formspec", nil)
  5. end
  6. function signs.on_construct(pos)
  7. --local n = minetest.get_node(pos)
  8. --local meta = minetest.get_meta(pos)
  9. --meta:set_string("formspec", "field[text;;${text}]")
  10. end
  11. function signs.on_rightclick(pos, node, clicker, itemstack, pt)
  12. local pname = clicker:get_player_name()
  13. local text = minetest.get_meta(pos):get_string("text")
  14. --local formspec = "field[text;;${text}]"
  15. local formspec = ""
  16. formspec = formspec ..
  17. "size[5,2.3]" ..
  18. default.gui_bg ..
  19. default.gui_bg_img ..
  20. default.gui_slots ..
  21. "item_image[1,1;1,1;" .. minetest.formspec_escape(node.name) .. "]" ..
  22. "field[0.3,0.3;5,1;text;;" .. minetest.formspec_escape(text) .. "]" ..
  23. "button_exit[2,1;2,1;proceed;Proceed]" ..
  24. "label[0,2;`%n' inserts a new line.]"
  25. local formname = "signs:input_" .. minetest.pos_to_string(pos)
  26. minetest.show_formspec(pname, formname, formspec)
  27. end
  28. function signs.on_receive_fields(pos, formname, fields, sender)
  29. local pname = sender:get_player_name()
  30. if minetest.test_protection(pos, pname) then
  31. return
  32. end
  33. local meta = minetest.get_meta(pos)
  34. if not fields.text or type(fields.text) ~= "string" then
  35. return
  36. end
  37. local message = utility.trim_remove_special_chars(fields.text)
  38. if anticurse.check(pname, message, "foul") then
  39. anticurse.log(pname, message)
  40. minetest.chat_send_player(pname, "# Server: Please do not write dirty talk on a sign.")
  41. return
  42. elseif anticurse.check(pname, message, "curse") then
  43. anticurse.log(pname, message)
  44. minetest.chat_send_player(pname, "# Server: Please do not curse on a sign.")
  45. return
  46. end
  47. minetest.log("action", pname .. " wrote \"" ..
  48. message .. "\" to sign at " .. minetest.pos_to_string(pos))
  49. meta:set_string("text", message)
  50. meta:set_string("author", pname)
  51. meta:mark_as_private({"text", "author"})
  52. -- Translate escape sequences.
  53. message = string.gsub(message, "%%[nN]", "\n")
  54. meta:set_string("infotext", message)
  55. -- Zero-out old stuff.
  56. meta:set_string("formspec", nil)
  57. end
  58. function signs.on_player_receive_fields(player, formname, fields)
  59. if not string.find(formname, "^signs:input_") then
  60. return
  61. end
  62. if not player or not player:is_player() then
  63. return true
  64. end
  65. local pos = minetest.string_to_pos(string.sub(formname, string.len("signs:input_") + 1))
  66. if not pos then
  67. return true
  68. end
  69. -- Make sure player is actually using a sign.
  70. local node = minetest.get_node(pos)
  71. local name = node.name
  72. if name ~= "signs:sign_wall_wood" and name ~= "signs:sign_wall_steel" and name ~= "signs:sign_wall_tin" then
  73. return true
  74. end
  75. signs.on_receive_fields(pos, "", fields, player)
  76. return true
  77. end
  78. if not signs.run_once then
  79. local function register_sign(material, desc, def)
  80. minetest.register_node("signs:sign_wall_" .. material, {
  81. description = desc .. " Sign",
  82. drawtype = "nodebox",
  83. tiles = {"default_sign_wall_" .. material .. ".png"},
  84. inventory_image = "default_sign_" .. material .. ".png",
  85. wield_image = "default_sign_" .. material .. ".png",
  86. paramtype = "light",
  87. paramtype2 = "wallmounted",
  88. sunlight_propagates = true,
  89. is_ground_content = false,
  90. walkable = false,
  91. floodable = true,
  92. node_box = {
  93. type = "wallmounted",
  94. wall_top = {-0.4375, 0.4375, -0.3125, 0.4375, 0.5, 0.3125},
  95. wall_bottom = {-0.4375, -0.5, -0.3125, 0.4375, -0.4375, 0.3125},
  96. wall_side = {-0.5, -0.3125, -0.4375, -0.4375, 0.3125, 0.4375},
  97. },
  98. groups = def.groups,
  99. legacy_wallmounted = true,
  100. sounds = def.sounds,
  101. on_construct = function(...)
  102. return signs.on_construct(...)
  103. end,
  104. on_receive_fields = function(...)
  105. return signs.on_receive_fields(...)
  106. end,
  107. on_rightclick = function(...)
  108. return signs.on_rightclick(...)
  109. end,
  110. on_punch = function(...)
  111. return signs.on_punch(...)
  112. end,
  113. })
  114. end
  115. register_sign("wood", "Wooden", {
  116. sounds = default.node_sound_wood_defaults(),
  117. groups = utility.dig_groups("bigitem", {attached_node = 1, flammable = 2})
  118. })
  119. register_sign("steel", "Iron", {
  120. sounds = default.node_sound_metal_defaults(),
  121. groups = utility.dig_groups("bigitem", {attached_node = 1})
  122. })
  123. register_sign("tin", "Tin", {
  124. sounds = default.node_sound_metal_defaults(),
  125. groups = utility.dig_groups("bigitem", {attached_node = 1})
  126. })
  127. minetest.register_craft({
  128. output = 'signs:sign_wall_steel 3',
  129. recipe = {
  130. {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
  131. {'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
  132. {'', 'group:stick', ''},
  133. }
  134. })
  135. minetest.register_craft({
  136. output = 'signs:sign_wall_tin 3',
  137. recipe = {
  138. {'moreores:tin_ingot', 'moreores:tin_ingot', 'moreores:tin_ingot'},
  139. {'moreores:tin_ingot', 'moreores:tin_ingot', 'moreores:tin_ingot'},
  140. {'', 'group:stick', ''},
  141. }
  142. })
  143. minetest.register_craft({
  144. output = 'signs:sign_wall_wood 3',
  145. recipe = {
  146. {'group:wood', 'group:wood', 'group:wood'},
  147. {'group:wood', 'group:wood', 'group:wood'},
  148. {'', 'group:stick', ''},
  149. }
  150. })
  151. minetest.register_alias("default:sign_wall_wood", "signs:sign_wall_wood")
  152. minetest.register_alias("default:sign_wall_steel", "signs:sign_wall_steel")
  153. minetest.register_on_player_receive_fields(function(...)
  154. return signs.on_player_receive_fields(...) end)
  155. local c = "signs:core"
  156. local f = signs.modpath .. "/init.lua"
  157. reload.register_file(c, f, false)
  158. signs.run_once = true
  159. end