minetest.register_node('furniture:news_stand', {
   description = 'News Stand',
   drawtype = 'mesh',
   mesh = 'furniture_news_stand.obj',
   tiles = {'furniture_news_stand.png'},
   paramtype = 'light',
   paramtype2 = 'facedir',
   groups = {breakable=1},
   selection_box = {
      type = 'fixed',
      fixed = {-.3125, -.5, -.4375, .3125, .75, .25},
      },
   collision_box = {
      type = 'fixed',
      fixed = {-.3125, -.5, -.4375, .3125, .75, .25},
      },
   after_place_node = function(pos, placer)
      local meta = minetest.get_meta(pos)
      meta:set_string('owner', placer:get_player_name())
      meta:set_string('infotext', 'Server News')
      meta:set_string('title', '')
      meta:set_string('content', '')
   end,
   on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
      local name = clicker:get_player_name()
      local meta = minetest.get_meta(pos)
      local owner = meta:get_string('owner')
      local title = meta:get_string('title')
      local content = meta:get_string('content')
      if owner == name then
         meta:set_string('formspec', furniture.news_stand_edit(title, content))
      else
         if content ~= '' then
            minetest.show_formspec(name, 'furniture:news', furniture.news_stand_view(title, content))
         else
            minetest.show_formspec(name, 'furniture:news', news_formspec)
         end
      end
   end,
   on_receive_fields = function(pos, formname, fields, sender)
      local meta = minetest.get_meta(pos)
      if fields ['save'] then
         local player_name = sender:get_player_name()
         meta:set_string('infotext', fields.title)
         meta:set_string('title', fields.title)
         meta:set_string('content', fields.content)
         minetest.log("action", (player_name or "").." wrote \""..fields.title.."\" to news stand at "..minetest.pos_to_string(pos))
      end
   end,
   on_punch = function(pos, node, puncher)
      local name = puncher:get_player_name()
      local meta = minetest.get_meta(pos)
      local content = meta:get_string('content')
      local title = meta:get_string('title')
      if content ~= '' then
         minetest.show_formspec(name, 'furniture:news', furniture.news_stand_view(title, content))
      else
         minetest.show_formspec(name, 'furniture:news', news_formspec)
      end
   end
})

local news = [[
   3/5/22
Express yourself with custom clothing. Feel free to make requests for other styles and designs. Purchase clothing with your XP in the shop.

   2/21/22
Run the /stats command with no arguments to see stats on all your levels* (*This only works for levels with auto-assigned IDs)

   2/12/22
Stats on levels is now visible with the /stats command.

   2/7/22
Level buttons have an option to disallow solo playing, edit your buttons accordingly.

   1/23/22
Platforms have been updated to entities. Any existing platforms will need to be manually replaced.

   1/19/22
Added the Terraform mod, contact Admin if you want/need the privilege to use it.

   1/7/22
Updated textures/UVs on a bunch of the furniture models.

   1/8/22
Added news stand. Fixed some rare bugs with the map buttons.

   1/10/22
Added placeblock command. Places a block at your feet. Thanks to PoohBear to letting me know we needed such a feature.

]]

news_formspec =
   'formspec_version[3]'..
   'size[11,10]'..
   'bgcolor[#080808BB;true]'..
   'background[0,0;11,10;furniture_news_stand_fs_bg.png]'..
   'hypertext[0,.2;11,1.2;;<center><style color=black size=40>~~News~~</style></center>]'..
   'textarea[.25,1.5;10.5,8.5;;;'..news..']'
