search_functions.lua 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. -- function to decide if a node has a wall that's in verticals_list{}
  2. -- returns wall direction of valid node, or nil if invalid.
  3. function biome_lib:find_adjacent_wall(pos, verticals, randomflag)
  4. local verts = dump(verticals)
  5. if randomflag then
  6. local walltab = {}
  7. if string.find(verts, minetest.get_node({ x=pos.x-1, y=pos.y, z=pos.z }).name) then walltab[#walltab + 1] = 3 end
  8. if string.find(verts, minetest.get_node({ x=pos.x+1, y=pos.y, z=pos.z }).name) then walltab[#walltab + 1] = 2 end
  9. if string.find(verts, minetest.get_node({ x=pos.x , y=pos.y, z=pos.z-1 }).name) then walltab[#walltab + 1] = 5 end
  10. if string.find(verts, minetest.get_node({ x=pos.x , y=pos.y, z=pos.z+1 }).name) then walltab[#walltab + 1] = 4 end
  11. if #walltab > 0 then return walltab[math.random(1, #walltab)] end
  12. else
  13. if string.find(verts, minetest.get_node({ x=pos.x-1, y=pos.y, z=pos.z }).name) then return 3 end
  14. if string.find(verts, minetest.get_node({ x=pos.x+1, y=pos.y, z=pos.z }).name) then return 2 end
  15. if string.find(verts, minetest.get_node({ x=pos.x , y=pos.y, z=pos.z-1 }).name) then return 5 end
  16. if string.find(verts, minetest.get_node({ x=pos.x , y=pos.y, z=pos.z+1 }).name) then return 4 end
  17. end
  18. return nil
  19. end
  20. -- Function to search downward from the given position, looking for the first
  21. -- node that matches the ground table. Returns the new position, or nil if
  22. -- height limit is exceeded before finding it.
  23. function biome_lib:search_downward(pos, heightlimit, ground)
  24. for i = 0, heightlimit do
  25. if string.find(dump(ground), minetest.get_node({x=pos.x, y=pos.y-i, z = pos.z}).name) then
  26. return {x=pos.x, y=pos.y-i, z = pos.z}
  27. end
  28. end
  29. return false
  30. end
  31. function biome_lib:find_open_side(pos)
  32. if minetest.get_node({ x=pos.x-1, y=pos.y, z=pos.z }).name == "air" then
  33. return {newpos = { x=pos.x-1, y=pos.y, z=pos.z }, facedir = 2}
  34. end
  35. if minetest.get_node({ x=pos.x+1, y=pos.y, z=pos.z }).name == "air" then
  36. return {newpos = { x=pos.x+1, y=pos.y, z=pos.z }, facedir = 3}
  37. end
  38. if minetest.get_node({ x=pos.x, y=pos.y, z=pos.z-1 }).name == "air" then
  39. return {newpos = { x=pos.x, y=pos.y, z=pos.z-1 }, facedir = 4}
  40. end
  41. if minetest.get_node({ x=pos.x, y=pos.y, z=pos.z+1 }).name == "air" then
  42. return {newpos = { x=pos.x, y=pos.y, z=pos.z+1 }, facedir = 5}
  43. end
  44. return nil
  45. end
  46. -- "Record" the chunks being generated by the core mapgen
  47. minetest.register_on_generated(function(minp, maxp, blockseed)
  48. biome_lib.blocklist_aircheck[#biome_lib.blocklist_aircheck + 1] = { minp, maxp }
  49. biome_lib.blocklist_no_aircheck[#biome_lib.blocklist_no_aircheck + 1] = { minp, maxp }
  50. end)