functions.lua 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. local c_air = minetest.get_content_id("air")
  2. vines.destroy_rope_starting = function(p, targetnode, bottomnode, topnode)
  3. local n = minetest.get_node(p).name
  4. if n ~= targetnode and n ~= bottomnode then
  5. return
  6. end
  7. local y1 = p.y
  8. local tab = {}
  9. local i = 1
  10. while n == targetnode do
  11. --print("test2")
  12. tab[i] = p
  13. i = i+1
  14. p.y = p.y-1
  15. n = minetest.get_node(p).name
  16. end
  17. --print("test10")
  18. if n == bottomnode then
  19. tab[i] = p
  20. end
  21. if #tab == 0 then
  22. return
  23. end
  24. local y0 = p.y
  25. --print("test5")
  26. local manip = minetest.get_voxel_manip()
  27. local p0 = {x=p.x, y=y0, z=p.z}
  28. local p1 = {x=p.x, y=y0+1, z=p.z}
  29. local p2 = {x=p.x, y=y1, z=p.z}
  30. local pos1, pos2 = manip:read_from_map(p0, p2)
  31. local area = VoxelArea:new({MinEdge=pos1, MaxEdge=pos2})
  32. local nodes = manip:get_data()
  33. --print("test6")
  34. --print(minetest.pos_to_string(p1) .. ", " .. minetest.pos_to_string(p2))
  35. for i in area:iterp(utility.sort_positions(p1, p2)) do
  36. nodes[i] = c_air
  37. --print("doing " .. i)
  38. end
  39. --print("test11")
  40. nodes[area:indexp(p0)] = minetest.get_content_id(topnode)
  41. --print("test7")
  42. manip:set_data(nodes)
  43. manip:write_to_map()
  44. manip:update_map() -- <— this takes time
  45. --print("test8")
  46. local timer = minetest.get_node_timer( p0 )
  47. timer:start( 1 )
  48. --print("test9")
  49. end