utility.lua 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. function serveressentials.get_short_stack_desc(stack)
  2. local def = minetest.registered_items[stack:get_name()]
  3. local meta = stack:get_meta()
  4. local description = meta:get_string("description")
  5. if description ~= "" then
  6. return utility.get_short_desc(description):trim()
  7. elseif def and def.description then
  8. return utility.get_short_desc(def.description):trim()
  9. end
  10. end
  11. -- Get the number of seconds until the next schedualed reset of the Outback.
  12. -- This is also used by the calendar item.
  13. function serveressentials.get_outback_timeout()
  14. local meta = serveressentials.modstorage
  15. local stime = meta:get_string("outback_reset_time")
  16. -- If timestamp is missing, then initialize it to the current time.
  17. if not stime or stime == "" then
  18. stime = tostring(os.time())
  19. meta:set_string("outback_reset_time", stime)
  20. end
  21. local time = tonumber(stime) -- Time of last reset (or initialization).
  22. local days = 30 -- Timeout in days.
  23. local timeout = 60 * 60 * 24 * days
  24. local now = os.time() -- Current time.
  25. local later = time + timeout -- Time of next reset.
  26. return (later - now)
  27. end