api.lua 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. local carpet_proto = {
  2. drawtype = "nodebox",
  3. paramtype = "light",
  4. paramtype2 = "facedir",
  5. node_box = {
  6. type = "fixed",
  7. fixed = {-0.5, -0.5, -0.5, 0.5, -0.45, 0.5}
  8. },
  9. groups = {
  10. snappy = 2,
  11. flammable = 3,
  12. oddly_breakable_by_hand = 3,
  13. choppy = 2,
  14. carpet = 1,
  15. }
  16. }
  17. -- Register the carpet and recipe using material
  18. -- material - already registered material item the textures and sounds applied from
  19. -- def - optional additional - or overriding data passed to minetest.register_node()
  20. carpets = {}
  21. function carpets.register(material, def)
  22. local node = table.copy(carpet_proto)
  23. if def then
  24. for k,v in pairs(def) do
  25. node[k] = v
  26. end
  27. end
  28. local material_def = minetest.registered_nodes[material]
  29. node.description = node.description or material_def.description.." Carpet"
  30. node.sounds = table.copy(node.sounds or material_def.sounds or default.node_sound_defaults())
  31. node.groups = table.copy(node.groups)
  32. if node.tiles then
  33. node.tiles = table.copy(node.tiles)
  34. elseif material_def.tiles[6] then
  35. node.tiles = {material_def.tiles[6]}
  36. else
  37. node.tiles = table.copy(material_def.tiles)
  38. end
  39. local name = "carpet:" .. (node.name or material:gsub(":", "_"))
  40. node.name = nil
  41. minetest.register_node(":" .. name, node)
  42. minetest.register_craft({
  43. output = name .. " 32",
  44. recipe = {
  45. {"group:wool", "group:wool", "group:wool"},
  46. {"group:wool", material, "group:wool"}
  47. }
  48. })
  49. end