Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. -- fills the marked area, ignored objects are not affected
  2. function io_area_fill (pos, ends, node, force, voxelmanip)
  3. local pos_start = {x = math.min(pos.x, ends.x) + 1, y = math.min(pos.y, ends.y) + 1, z = math.min(pos.z, ends.z) + 1}
  4. local pos_end = {x = math.max(pos.x, ends.x) - 1, y = math.max(pos.y, ends.y) - 1, z = math.max(pos.z, ends.z) - 1}
  5.  
  6. -- create a vm if none is given
  7. local voxelmanip_this = {}
  8. if voxelmanip then
  9. voxelmanip_this = {vm = voxelmanip.vm, emin = voxelmanip.emin, emax = voxelmanip.emax, update = false}
  10. else
  11. voxelmanip_this = {vm = VoxelManip(), emin = pos_start, emax = pos_end, update = true}
  12. end
  13.  
  14. local data = voxelmanip_this.vm:get_data()
  15. local area = VoxelArea:new{MinEdge = voxelmanip_this.emin, MaxEdge = voxelmanip_this.emax}
  16. local node_content = minetest.get_content_id(node)
  17. local node_air_content = minetest.get_content_id("air")
  18.  
  19. -- set each node in the marked area
  20. for i in area:iterp(pos_start, pos_end) do
  21. if data[i] == node_air_content or force == true then
  22. data[i] = node_content
  23. end
  24. end
  25.  
  26. -- write new vm data, preform updates here if we used a local vm
  27. voxelmanip_this.vm:set_data(data)
  28. voxelmanip_this.vm:write_to_map()
  29. if voxelmanip_this.update == true then
  30. io_vm_update(voxelmanip_this)
  31. end
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement