api.lua 1016 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. function toppings_api.register_topped(base_name, topping)
  2. local base = minetest.registered_nodes[base_name]
  3. assert(base, base_name .. " is not registered")
  4. --copy definition
  5. local topped = {}
  6. for k, v in pairs(base)
  7. do
  8. topped[k] = v
  9. end
  10. --creating texture
  11. local basetext = {}
  12. local tiles = topped.tiles
  13. if #tiles == 1
  14. then
  15. basetext.top = tiles[1]
  16. basetext.bottom = tiles[1]
  17. basetext.sides = tiles[1]
  18. elseif #tiles == 3 --we assume that it's already topped
  19. then
  20. basetext.top = tiles[1]
  21. basetext.bottom = tiles[2]
  22. basetext.sides = tiles[3].name
  23. end
  24. topped.tiles =
  25. {
  26. basetext.top .. "^" .. topping.top,
  27. basetext.bottom,
  28. {
  29. name = basetext.sides .. "^" .. topping.sides,
  30. tileable_vertical = false,
  31. }
  32. }
  33. topped.description = topping.description
  34. --overwriting sounds is optional
  35. if topping.sounds
  36. then
  37. topped.sounds = topping.sounds
  38. end
  39. --registering the node
  40. minetest.register_node(topping.name, topped)
  41. erosion.register_erosion({topping.name, base_name})
  42. end