helpers.lua 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. -- Returns the greatest numeric key in a table.
  2. function xdecor.maxn(T)
  3. local n = 0
  4. for k in pairs(T) do
  5. if k > n then n = k end
  6. end
  7. return n
  8. end
  9. -- Returns the length of an hash table.
  10. function xdecor.tablelen(T)
  11. local n = 0
  12. for _ in pairs(T) do n = n + 1 end
  13. return n
  14. end
  15. -- Deep copy of a table. Borrowed from mesecons mod (https://github.com/Jeija/minetest-mod-mesecons).
  16. function xdecor.tablecopy(T)
  17. if type(T) ~= "table" then return T end -- No need to copy.
  18. local new = {}
  19. for k, v in pairs(T) do
  20. if type(v) == "table" then
  21. new[k] = xdecor.tablecopy(v)
  22. else
  23. new[k] = v
  24. end
  25. end
  26. return new
  27. end
  28. function xdecor.stairs_valid_def(def)
  29. if def.nostairs then
  30. return false
  31. end
  32. if def.drawtype then
  33. if def.drawtype ~= "normal" and def.drawtype:sub(1, 5) ~= "glass" then
  34. return false
  35. end
  36. end
  37. if def.on_construct or def.after_place_node or def.on_rightclick or def.on_blast or def.allow_metadata_inventory_take then
  38. return false
  39. end
  40. if def.mesecons then
  41. return false
  42. end
  43. if not def.description or def.description == "" then
  44. return false
  45. end
  46. if def.light_source and def.light_source ~= 0 then
  47. return false
  48. end
  49. if def.groups then
  50. if def.groups.wool then
  51. return false
  52. end
  53. if def.groups.not_in_creative_inventory or def.groups.not_cuttable then
  54. return false
  55. end
  56. if not def.groups.cracky and not def.groups.choppy then
  57. return false
  58. end
  59. end
  60. if def.tiles and type(def.tiles[1]) == "string" then
  61. if def.tiles[1]:find("default_mineral") then
  62. return false
  63. end
  64. end
  65. return true -- All tests passed.
  66. end