palm.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. if not minetest.global_exists("moretrees") then moretrees = {} end
  2. local SAPLING_TIME_MIN = 60*20
  3. local SAPLING_TIME_MAX = 60*40
  4. local SAPLING_CHANCE = 20
  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. tiles = {"moretrees_palm_leaves.png"},
  40. paramtype = "light",
  41. waving = 1,
  42. groups = moretrees.leaves_groups,
  43. drop = moretrees.get_leafdrop_table(SAPLING_CHANCE, "moretrees:palm_sapling", "moretrees:palm_leaves"),
  44. sounds = default.node_sound_leaves_defaults(),
  45. movement_speed_multiplier = default.SLOW_SPEED,
  46. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  47. on_timer = enhanced_leafdecay.make_leaf_nodetimer({tree="moretrees:palm_tree"}),
  48. })
  49. minetest.register_node("moretrees:palm_wood", {
  50. description = "Palm Planks",
  51. paramtype2 = "facedir",
  52. place_param2 = 0,
  53. tiles = {"moretrees_palm_wood.png"},
  54. groups = moretrees.get_wood_groups({wood_dark = 1}),
  55. sounds = default.node_sound_wood_defaults(),
  56. })
  57. minetest.register_node("moretrees:palm_sapling", {
  58. description = "Palm Sapling\n\nWill not grow in deep caves.\nGrows coconuts.",
  59. drawtype = "plantlike",
  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_bronze2",
  146. "default:axe_diamond",
  147. "default:axe_mese",
  148. "default:axe_steel",
  149. "default:axe_stone",
  150. "gems:axe_amethyst",
  151. "gems:rf_axe_amethyst",
  152. "gems:axe_emerald",
  153. "gems:rf_axe_emerald",
  154. "gems:axe_ruby",
  155. "gems:rf_axe_ruby",
  156. "gems:axe_sapphire",
  157. "gems:rf_axe_sapphire",
  158. "moreores:axe_mithril",
  159. "moreores:axe_silver",
  160. }
  161. for i in ipairs(cutting_tools) do
  162. local tool = cutting_tools[i]
  163. minetest.register_craft({
  164. type = "shapeless",
  165. output = "moretrees:coconut_milk",
  166. recipe = {
  167. "moretrees:coconut",
  168. "vessels:drinking_glass",
  169. tool,
  170. },
  171. replacements = {
  172. { "moretrees:coconut", "moretrees:raw_coconut" },
  173. { tool, tool },
  174. }
  175. })
  176. end
  177. minetest.register_on_craft(function(...) moretrees.on_coconut_milk_craft(...) end)
  178. moretrees.on_coconut_milk_craft = function(itemstack, player, old_craft_grid, craft_inv)
  179. if itemstack:get_name() ~= "moretrees:coconut_milk" then
  180. return
  181. end
  182. local original
  183. local index
  184. for i = 1, player:get_inventory():get_size("craft") do
  185. for j in ipairs(cutting_tools) do
  186. local tool = cutting_tools[j]
  187. if old_craft_grid[i]:get_name() == tool then
  188. original = old_craft_grid[i]
  189. index = i
  190. end
  191. end
  192. end
  193. if not original then
  194. return
  195. end
  196. -- put the tool with metadata back in the craft grid
  197. craft_inv:set_stack("craft", index, original)
  198. end
  199. minetest.register_craft({
  200. output = 'moretrees:palm_wood 4',
  201. recipe = {
  202. {'moretrees:palm_tree'},
  203. }
  204. })
  205. minetest.register_craft({
  206. output = "default:fence_wood 4",
  207. recipe = {
  208. {"moretrees:palm_wood", 'group:stick', "moretrees:palm_wood"},
  209. {"moretrees:palm_wood", 'group:stick', "moretrees:palm_wood"},
  210. }
  211. })
  212. minetest.register_craft({
  213. output = "doors:gate_wood_closed",
  214. recipe = {
  215. {"techcrafts:hinge_wood", "moretrees:palm_wood", "group:stick"},
  216. {"group:stick", "moretrees:palm_wood", "group:stick"}
  217. }
  218. })
  219. stairs.register_stair_and_slab(
  220. "palm",
  221. "moretrees:palm_wood",
  222. moretrees.stair_groups,
  223. {"moretrees_palm_wood.png"},
  224. "Palm Plank",
  225. default.node_sound_wood_defaults()
  226. )