util.lua 920 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. function mesecon:swap_node(pos, name)
  2. local node = minetest.env:get_node(pos)
  3. local data = minetest.env:get_meta(pos):to_table()
  4. node.name = name
  5. minetest.env:add_node(pos, node)
  6. minetest.env:get_meta(pos):from_table(data)
  7. end
  8. function mesecon:move_node(pos, newpos)
  9. local node = minetest.env:get_node(pos)
  10. local meta = minetest.env:get_meta(pos):to_table()
  11. minetest.env:remove_node(pos)
  12. minetest.env:add_node(newpos, node)
  13. minetest.env:get_meta(pos):from_table(meta)
  14. end
  15. function mesecon:addPosRule(p, r)
  16. return {x = p.x + r.x, y = p.y + r.y, z = p.z + r.z}
  17. end
  18. function mesecon:cmpPos(p1, p2)
  19. return (p1.x == p2.x and p1.y == p2.y and p1.z == p2.z)
  20. end
  21. function mesecon:tablecopy(table) -- deep table copy
  22. local newtable = {}
  23. for idx, item in pairs(table) do
  24. if type(item) == "table" then
  25. newtable[idx] = mesecon:tablecopy(item)
  26. else
  27. newtable[idx] = item
  28. end
  29. end
  30. return newtable
  31. end