wood_node_api.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. --api
  2. ------------------------------------------------------------------------
  3. local log_node_prototype =
  4. {
  5. paramtype2 = "facedir",
  6. is_ground_content = false,
  7. groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2},
  8. sounds = generic_media.node_sound_wood_defaults(),
  9. on_place = minetest.rotate_node
  10. }
  11. local plank_node_prototype =
  12. {
  13. paramtype2 = "facedir",
  14. place_param2 = 0,
  15. is_ground_content = false,
  16. groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, wood = 1},
  17. sounds = generic_media.node_sound_wood_defaults(),
  18. }
  19. local leaf_node_prototype =
  20. {
  21. drawtype = "allfaces_optional",
  22. waving = 1,
  23. paramtype = "light",
  24. is_ground_content = false,
  25. groups = {snappy = 3, leafdecay = 3, flammable = 2, leaves = 1},
  26. sounds = generic_media.node_sound_leaves_defaults(),
  27. on_break = function() end,
  28. }
  29. local wood_item_prototype =
  30. {
  31. groups =
  32. {
  33. wood = 1,
  34. }
  35. }
  36. local function get_definition(which)
  37. local orig
  38. if which == "log"
  39. then
  40. orig = log_node_prototype
  41. elseif which == "plank"
  42. then
  43. orig = plank_node_prototype
  44. elseif which == "leaf"
  45. then
  46. orig = leaf_node_prototype
  47. elseif which == "item"
  48. then
  49. orig = wood_item_prototype
  50. end
  51. local def = {}
  52. for k, v in pairs(orig)
  53. do
  54. def[k] = v
  55. end
  56. return def
  57. end
  58. local nodetypes =
  59. {
  60. log = function(name, ndef, def)
  61. ndef.tiles = {def.toptexture, def.toptexture, def.sidetexture}
  62. ndef.drop = "log"
  63. return name .. "_log"
  64. end,
  65. plank = function(name, ndef, def)
  66. ndef.tiles = {def.texture}
  67. ndef.drop = "plank"
  68. return name .. "_plank"
  69. end,
  70. leaf = function(name, ndef, def)
  71. ndef.tiles = {def.normaltexture}
  72. ndef.special_tiles = {def.simpletexture}
  73. ndef.drop = ""
  74. return name .. "_leaves"
  75. end,
  76. }
  77. local function register_node(type, name, def)
  78. if not def --everything's optional
  79. then
  80. return
  81. end
  82. local ndef = get_definition(type)
  83. ndef.description = def.description
  84. local regname = nodetypes[type](name, ndef, def) --node type specific modification
  85. minetest.register_node(regname, ndef)
  86. end
  87. --[[ Unused in The End, but potentially useful for other games
  88. local itemtypes =
  89. {
  90. log = function(name, idef, def)
  91. idef._sawing_result = name .. "_plank_item"
  92. return name .. "_log_item"
  93. end,
  94. plank = function(name, idef, def)
  95. idef._sawing_result = "stick"
  96. return name .. "_plank_item"
  97. end
  98. }
  99. local function register_item(type, name, def)
  100. if not def
  101. then
  102. return
  103. end
  104. local idef = get_definition("item")
  105. idef.description = def.description
  106. idef.inventory_image = def.itemtexture
  107. local regname = itemtypes[type](name, idef, def)
  108. minetest.register_craftitem(regname, idef)
  109. end
  110. ]]
  111. function wood_and_saws.register_wood(name, def)
  112. register_node("log", name, def.log)
  113. register_node("plank", name, def.plank)
  114. register_node("leaf", name, def.leaf)
  115. --register_item("log", name, def.log)
  116. --register_item("plank", name, def.plank)
  117. end