env.lua 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. core.bulk_swap_node = core.bulk_set_node
  21. function core.remove_node(pos)
  22. return core.vmanip:set_node_at(pos, {name="air"})
  23. end
  24. function core.get_node(pos)
  25. return core.vmanip:get_node_at(pos)
  26. end
  27. function core.get_perlin(seed, octaves, persist, spread)
  28. local params
  29. if type(seed) == "table" then
  30. params = table.copy(seed)
  31. else
  32. assert(type(seed) == "number")
  33. params = {
  34. seed = seed,
  35. octaves = octaves,
  36. persist = persist,
  37. spread = {x=spread, y=spread, z=spread},
  38. }
  39. end
  40. params.seed = core.get_seed(params.seed) -- add mapgen seed
  41. return PerlinNoise(params)
  42. end
  43. function core.get_perlin_map(params, size)
  44. local params2 = table.copy(params)
  45. params2.seed = core.get_seed(params.seed) -- add mapgen seed
  46. return PerlinNoiseMap(params2, size)
  47. end