spawn_sanitizer.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. if not minetest.global_exists("spawn_sanitizer") then spawn_sanitizer = {} end
  2. spawn_sanitizer.modpath = minetest.get_modpath("hb4")
  3. spawn_sanitizer.areas = {
  4. -- Lava Pit A.
  5. {minp={x=2, y=-55, z=-12}, maxp={x=-2, y=-53, z=-10}},
  6. -- Lava Pit B.
  7. {minp={x=-2, y=-55, z=12}, maxp={x=2, y=-53, z=10}},
  8. }
  9. function spawn_sanitizer.sanitize_all()
  10. local c_air = minetest.get_content_id("air")
  11. for _, area in ipairs(spawn_sanitizer.areas) do
  12. local minp = {x=area.minp.x, y=area.minp.y, z=area.minp.z}
  13. local maxp = {x=area.maxp.x, y=area.maxp.y, z=area.maxp.z}
  14. -- Sort.
  15. minp, maxp = utility.sort_positions(minp, maxp)
  16. local vm = minetest.get_voxel_manip()
  17. local emin, emax = vm:read_from_map(minp, maxp)
  18. local data = vm:get_data()
  19. local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
  20. for z = minp.z, maxp.z do
  21. for x = minp.x, maxp.x do
  22. for y = minp.y, maxp.y do
  23. --minetest.chat_send_player("MustTest", minetest.pos_to_string({x=x, y=y, z=z}))
  24. local vp = area:index(x, y, z)
  25. data[vp] = c_air
  26. end
  27. end
  28. end
  29. vm:set_data(data)
  30. vm:write_to_map()
  31. end
  32. end
  33. if not spawn_sanitizer.registered then
  34. -- Clean areas after startup.
  35. minetest.after(10, function() spawn_sanitizer.sanitize_all() end)
  36. spawn_sanitizer.registered = true
  37. end