env.lua 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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_perlin(seed, octaves, persist, spread)
  27. local params
  28. if type(seed) == "table" then
  29. params = table.copy(seed)
  30. else
  31. assert(type(seed) == "number")
  32. params = {
  33. seed = seed,
  34. octaves = octaves,
  35. persist = persist,
  36. spread = {x=spread, y=spread, z=spread},
  37. }
  38. end
  39. params.seed = core.get_seed(params.seed) -- add mapgen seed
  40. return PerlinNoise(params)
  41. end
  42. function core.get_perlin_map(params, size)
  43. local params2 = table.copy(params)
  44. params2.seed = core.get_seed(params.seed) -- add mapgen seed
  45. return PerlinNoiseMap(params2, size)
  46. end