helpers.lua 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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
  6. n = k
  7. end
  8. end
  9. return n
  10. end
  11. -- Returns the length of an hash table.
  12. function xdecor.tablelen(T)
  13. local n = 0
  14. for _ in pairs(T) do
  15. n = n + 1
  16. end
  17. return n
  18. end
  19. -- Deep copy of a table. Borrowed from mesecons mod (https://github.com/Jeija/minetest-mod-mesecons).
  20. function xdecor.tablecopy(T)
  21. if type(T) ~= "table" then
  22. return T -- No need to copy.
  23. end
  24. local new = {}
  25. for k, v in pairs(T) do
  26. if type(v) == "table" then
  27. new[k] = xdecor.tablecopy(v)
  28. else
  29. new[k] = v
  30. end
  31. end
  32. return new
  33. end
  34. function xdecor.stairs_valid_def(def)
  35. return (def.drawtype == "normal" or def.drawtype:sub(1,5) == "glass") and
  36. (def.groups.cracky or def.groups.choppy) and
  37. not def.on_construct and
  38. not def.after_place_node and
  39. not def.on_rightclick and
  40. not def.on_blast and
  41. not def.allow_metadata_inventory_take and
  42. not (def.groups.not_in_creative_inventory == 1) and
  43. not (def.groups.not_cuttable == 1) and
  44. not def.groups.wool and
  45. (def.tiles and type(def.tiles[1]) == "string" and not
  46. def.tiles[1]:find("default_mineral")) and
  47. not def.mesecons and
  48. def.description and
  49. def.description ~= "" and
  50. def.light_source == 0
  51. end