palm.lua 6.6 KB

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