terrain_generator.gd 829 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. class_name TerrainGenerator
  2. extends Resource
  3. const RANDOM_BLOCK_PROBABILITY = 0.015
  4. static func empty() -> Dictionary:
  5. return {}
  6. static func random_blocks() -> Dictionary:
  7. var random_data := {}
  8. for x in Chunk.CHUNK_SIZE:
  9. for y in Chunk.CHUNK_SIZE:
  10. for z in Chunk.CHUNK_SIZE:
  11. var vec := Vector3i(x, y, z)
  12. if randf() < RANDOM_BLOCK_PROBABILITY:
  13. random_data[vec] = randi() % 29 + 1
  14. return random_data
  15. static func flat(chunk_position: Vector3i) -> Dictionary:
  16. var data := {}
  17. if chunk_position.y != -1:
  18. return data
  19. for x in Chunk.CHUNK_SIZE:
  20. for z in Chunk.CHUNK_SIZE:
  21. data[Vector3i(x, 0, z)] = 3
  22. return data
  23. # Used to create the project icon.
  24. static func origin_grass(chunk_position: Vector3i) -> Dictionary:
  25. if chunk_position == Vector3i.ZERO:
  26. return { Vector3i.ZERO: 3 }
  27. return {}