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.

68 lines
1.9KB

  1. local materials_by_name = {};
  2. local materials_by_group = {};
  3. return {
  4. -- Get the converted material value of the given itemstack
  5. --
  6. -- stack: The itemstack to convert
  7. --
  8. -- Returns a table with the material values
  9. get_stack_value = function(stack)
  10. local item_name = stack:get_name();
  11. local item_count = stack:get_count();
  12. for name,mats in pairs(materials_by_name) do
  13. if name == item_name then
  14. return {
  15. paper = (mats.paper or 0) * item_count,
  16. pigment = (mats.pigment or 0) * item_count,
  17. }
  18. end
  19. end
  20. for group,mats in pairs(materials_by_group) do
  21. if minetest.get_item_group(item_name, group) ~= 0 then
  22. return {
  23. paper = (mats.paper or 0) * item_count,
  24. pigment = (mats.pigment or 0) * item_count,
  25. }
  26. end
  27. end
  28. return {
  29. paper = 0,
  30. pigment = 0,
  31. };
  32. end,
  33. -- Register a material from an item name
  34. --
  35. -- name: The name of the item
  36. -- material: The material type to set
  37. -- value: The material value
  38. register_by_name = function(name, material, value)
  39. if materials_by_name[name] then
  40. materials_by_name[name][material] = value or 1;
  41. else
  42. materials_by_name[name] = {
  43. [material] = value or 1,
  44. };
  45. end
  46. end,
  47. -- Register a material from an item group
  48. --
  49. -- group: The name of the group
  50. -- material: The material type to set
  51. -- value: The material value
  52. register_by_group = function(name, material, value)
  53. if materials_by_group[name] then
  54. materials_by_group[name][material] = value or 1;
  55. else
  56. materials_by_group[name] = {
  57. [material] = value or 1,
  58. };
  59. end
  60. end,
  61. };