terrain_generator.gd 891 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. class_name TerrainGenerator
  2. extends Resource
  3. # Can't be "Chunk.CHUNK_SIZE" due to cyclic dependency issues.
  4. # https://github.com/godotengine/godot/issues/21461
  5. const CHUNK_SIZE = 16
  6. const RANDOM_BLOCK_PROBABILITY = 0.015
  7. static func empty():
  8. return {}
  9. static func random_blocks():
  10. var random_data = {}
  11. for x in range(CHUNK_SIZE):
  12. for y in range(CHUNK_SIZE):
  13. for z in range(CHUNK_SIZE):
  14. var vec = Vector3i(x, y, z)
  15. if randf() < RANDOM_BLOCK_PROBABILITY:
  16. random_data[vec] = randi() % 29 + 1
  17. return random_data
  18. static func flat(chunk_position):
  19. var data = {}
  20. if chunk_position.y != -1:
  21. return data
  22. for x in range(CHUNK_SIZE):
  23. for z in range(CHUNK_SIZE):
  24. data[Vector3i(x, 0, z)] = 3
  25. return data
  26. # Used to create the project icon.
  27. static func origin_grass(chunk_position):
  28. if chunk_position == Vector3i.ZERO:
  29. return {Vector3i.ZERO: 3}
  30. return {}