env.lua 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. -- Reimplementations of some environment function on vmanips, since this is
  2. -- what the emerge environment operates on
  3. -- core.vmanip = <VoxelManip> -- set by C++
  4. function core.set_node(pos, node)
  5. return core.vmanip:set_node_at(pos, node)
  6. end
  7. function core.bulk_set_node(pos_list, node)
  8. local vm = core.vmanip
  9. local set_node_at = vm.set_node_at
  10. for _, pos in ipairs(pos_list) do
  11. if not set_node_at(vm, pos, node) then
  12. return false
  13. end
  14. end
  15. return true
  16. end
  17. core.add_node = core.set_node
  18. -- we don't deal with metadata currently
  19. core.swap_node = core.set_node
  20. function core.remove_node(pos)
  21. return core.vmanip:set_node_at(pos, {name="air"})
  22. end
  23. function core.get_node(pos)
  24. return core.vmanip:get_node_at(pos)
  25. end
  26. function core.get_node_or_nil(pos)
  27. local node = core.vmanip:get_node_at(pos)
  28. return node.name ~= "ignore" and node
  29. end
  30. function core.get_perlin(seed, octaves, persist, spread)
  31. local params
  32. if type(seed) == "table" then
  33. params = table.copy(seed)
  34. else
  35. assert(type(seed) == "number")
  36. params = {
  37. seed = seed,
  38. octaves = octaves,
  39. persist = persist,
  40. spread = {x=spread, y=spread, z=spread},
  41. }
  42. end
  43. params.seed = core.get_seed(params.seed) -- add mapgen seed
  44. return PerlinNoise(params)
  45. end
  46. function core.get_perlin_map(params, size)
  47. local params2 = table.copy(params)
  48. params2.seed = core.get_seed(params.seed) -- add mapgen seed
  49. return PerlinNoiseMap(params2, size)
  50. end