A minetest mod for mapmaking
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.7KB

  1. -- Arguments
  2. -- util: API for uncategorized utility methods
  3. local util = ...;
  4. local biome_lookup = {};
  5. -- Contains functions for registering and getting biome-related mapping information
  6. return {
  7. -- Register a biome with textures to display
  8. --
  9. -- name: A string containing the biome name
  10. -- textures: A table of texture names.
  11. -- These should correspond with detail levels,
  12. -- any detail level past the length of the table will return the last texture
  13. -- (Optional) min_height: The minimum Y position where this biome data should be used
  14. -- (Optional) max_height: The maximum Y position where this biome data should be used
  15. add = function (name, textures, min_height, max_height)
  16. biome_lookup[#biome_lookup + 1] = {
  17. name = name,
  18. textures = textures,
  19. min_height = min_height,
  20. max_height = max_height,
  21. };
  22. end,
  23. -- Get the texture name (minus index/extension) for the given biome, height, and detail level.
  24. --
  25. -- name: A string containing the biome name
  26. -- height: A number representing the Y position of the biome
  27. -- detail: The detail level
  28. --
  29. -- Returns a string with a texture name, or nil if no matching biome entry was found.
  30. get_texture = function (name, height, detail)
  31. for _,biome in ipairs(biome_lookup) do
  32. local matches_height = (not biome.min_height or height >= biome.min_height)
  33. and (not biome.max_height or height <= biome.max_height);
  34. if biome.name == name and matches_height then
  35. return util.get_clamped(biome.textures, detail);
  36. end
  37. end
  38. return nil;
  39. end,
  40. };