palm.lua 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. moretrees = moretrees or {}
  2. local SAPLING_TIME_MIN = 60*20
  3. local SAPLING_TIME_MAX = 60*40
  4. local SAPLING_CHANCE = 40
  5. local SCHEMATIC_MINP = {x=-4, y=0, z=-4}
  6. local SCHEMATIC_MAXP = {x=4, y=13, z=4}
  7. local SCHEMATIC_RELP = {x=-4, y=0, z=-4}
  8. minetest.register_node("moretrees:palm_tree", {
  9. drawtype = "nodebox",
  10. paramtype = "light",
  11. node_box = {
  12. type = "fixed",
  13. fixed = basictrees.trunk_nodebox,
  14. },
  15. description = "Palm Tree",
  16. tiles = {
  17. "moretrees_palm_trunk_top.png",
  18. "moretrees_palm_trunk_top.png",
  19. "moretrees_palm_trunk.png"
  20. },
  21. paramtype2 = "facedir",
  22. groups = moretrees.tree_groups,
  23. sounds = default.node_sound_wood_defaults(),
  24. on_place = minetest.rotate_node,
  25. movement_speed_multiplier = default.NORM_SPEED,
  26. on_destruct = enhanced_leafdecay.make_tree_destructor({
  27. leaves = {
  28. "moretrees:palm_leaves",
  29. "moretrees:coconut",
  30. "group:dry_leaves",
  31. },
  32. }),
  33. })
  34. minetest.register_node("moretrees:palm_leaves", {
  35. description = "Palm Leaves",
  36. drawtype = "allfaces_optional",
  37. visual_scale = 1.3,
  38. tiles = {"moretrees_palm_leaves.png"},
  39. paramtype = "light",
  40. waving = 1,
  41. groups = moretrees.leaves_groups,
  42. drop = moretrees.get_leafdrop_table(SAPLING_CHANCE, "moretrees:palm_sapling", "moretrees:palm_leaves"),
  43. sounds = default.node_sound_leaves_defaults(),
  44. movement_speed_multiplier = default.SLOW_SPEED,
  45. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  46. on_timer = enhanced_leafdecay.make_leaf_nodetimer({tree="moretrees:palm_tree"}),
  47. })
  48. minetest.register_node("moretrees:palm_wood", {
  49. description = "Palm Planks",
  50. paramtype2 = "facedir",
  51. place_param2 = 0,
  52. tiles = {"moretrees_palm_wood.png"},
  53. groups = moretrees.get_wood_groups({wood_dark = 1}),
  54. sounds = default.node_sound_wood_defaults(),
  55. })
  56. minetest.register_node("moretrees:palm_sapling", {
  57. description = "Palm Sapling\n\nWill not grow in deep caves.\nGrows coconuts.",
  58. drawtype = "plantlike",
  59. --visual_scale = 1.0,
  60. tiles = {"moretrees_palm_sapling.png"},
  61. paramtype = "light",
  62. sunlight_propagates = true,
  63. walkable = false,
  64. selection_box = moretrees.sapling_selection_box,
  65. groups = moretrees.sapling_groups,
  66. sounds = default.node_sound_leaves_defaults(),
  67. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  68. on_timer = function(pos, elapsed)
  69. if mtflower.can_grow(pos) then
  70. if mtflower.try_grow(pos, "moretrees:palm_tree", "moretrees:palm_leaves", "glowstone:minerals", "glowstone:minerals") then
  71. return
  72. end
  73. end
  74. if not moretrees.can_grow(pos) then
  75. minetest.get_node_timer(pos):start(math.random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  76. return
  77. end
  78. minetest.set_node(pos, {name='air'}) -- Remove sapling first.
  79. local path = moretrees.modpath .. "/schematics/palm.mts"
  80. minetest.place_schematic(vector.add(vector.add(pos, {x=0, y=math.random(-1, 1), z=0}), SCHEMATIC_RELP), path, "random", nil, false)
  81. trunkgen.check_trunk(pos, 3, "moretrees:palm_tree")
  82. snowscatter.dump_snowdust_on_tree(pos, SCHEMATIC_MINP, SCHEMATIC_MAXP)
  83. ambiance.spawn_sound_beacon_inside_area("soundbeacon:trees", pos, SCHEMATIC_MINP, SCHEMATIC_MAXP, 40, 3)
  84. fruitscatter.scatter_fruit_under_leaves(
  85. pos,
  86. "moretrees:palm_leaves",
  87. "moretrees:coconut",
  88. SCHEMATIC_MINP,
  89. SCHEMATIC_MAXP,
  90. math.random(5, 6)
  91. )
  92. end,
  93. on_construct = function(pos)
  94. minetest.get_node_timer(pos):start(math.random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  95. end,
  96. on_place = function(itemstack, placer, pointed_thing)
  97. itemstack = default.sapling_on_place(itemstack, placer, pointed_thing,
  98. "moretrees:palm_sapling", SCHEMATIC_MINP, SCHEMATIC_MAXP, 4)
  99. return itemstack
  100. end,
  101. })
  102. minetest.register_node("moretrees:coconut", {
  103. description = "Coconut",
  104. drawtype = "plantlike",
  105. visual_scale = 0.8,
  106. tiles = {"moretrees_coconut.png"},
  107. inventory_image = "moretrees_coconut.png",
  108. paramtype = "light",
  109. sunlight_propagates = true,
  110. walkable = false,
  111. selection_box = {
  112. type = "fixed",
  113. fixed = {-0.2, -0.5, -0.2, 0.2, 0, 0.2},
  114. },
  115. -- Nuts do not rot.
  116. groups = {fleshy=3, dig_immediate=3, flammable=2, leafdecay=3, leafdecay_drop=1},
  117. sounds = default.node_sound_defaults(),
  118. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  119. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  120. on_timer = enhanced_leafdecay.make_leaf_nodetimer({tree="moretrees:palm_tree"}),
  121. after_dig_node = hb4.fruitregrow.after_dig_node(),
  122. after_place_node = hb4.fruitregrow.after_place_node(),
  123. on_finish_collapse = hb4.fruitregrow.on_finish_collapse(),
  124. })
  125. minetest.register_craftitem("moretrees:raw_coconut", {
  126. description = "Raw Coconut",
  127. inventory_image = "moretrees_raw_coconut.png",
  128. on_use = minetest.item_eat(4),
  129. groups = {foodrot=1},
  130. })
  131. -- This food is stored in a glass and does not rot.
  132. minetest.register_craftitem("moretrees:coconut_milk", {
  133. description = "Coconut Milk\n\nAn energy drink.\nConsume to refresh stamina.",
  134. inventory_image = "moretrees_coconut_milk.png",
  135. wield_image = "moretrees_coconut_milk.png",
  136. on_use = function(itemstack, user, pointed_thing)
  137. sprint.add_stamina(user, 6)
  138. user:get_inventory():add_item("main", ItemStack("vessels:drinking_glass"))
  139. local func = minetest.item_eat(1)
  140. return func(itemstack, user, pointed_thing)
  141. end,
  142. })
  143. local cutting_tools = {
  144. "default:axe_bronze",
  145. "default:axe_diamond",
  146. "default:axe_mese",
  147. "default:axe_steel",
  148. "moreores:axe_mithril",
  149. "moreores:axe_silver",
  150. }
  151. for i in ipairs(cutting_tools) do
  152. local tool = cutting_tools[i]
  153. minetest.register_craft({
  154. type = "shapeless",
  155. output = "moretrees:coconut_milk",
  156. recipe = {
  157. "moretrees:coconut",
  158. "vessels:drinking_glass",
  159. tool,
  160. },
  161. replacements = {
  162. { "moretrees:coconut", "moretrees:raw_coconut" },
  163. { tool, tool },
  164. }
  165. })
  166. end
  167. minetest.register_craft({
  168. output = 'moretrees:palm_wood 4',
  169. recipe = {
  170. {'moretrees:palm_tree'},
  171. }
  172. })
  173. minetest.register_craft({
  174. output = "default:fence_wood 4",
  175. recipe = {
  176. {"moretrees:palm_wood", 'group:stick', "moretrees:palm_wood"},
  177. {"moretrees:palm_wood", 'group:stick', "moretrees:palm_wood"},
  178. }
  179. })
  180. minetest.register_craft({
  181. output = "doors:gate_wood_closed",
  182. recipe = {
  183. {"group:stick", "moretrees:palm_wood", "group:stick"},
  184. {"group:stick", "moretrees:palm_wood", "group:stick"}
  185. }
  186. })
  187. stairs.register_stair_and_slab(
  188. "palm",
  189. "moretrees:palm_wood",
  190. moretrees.stair_groups,
  191. {"moretrees_palm_wood.png"},
  192. "Palm Plank",
  193. default.node_sound_wood_defaults()
  194. )