init.lua 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. firetree = firetree or {}
  2. firetree.modpath = minetest.get_modpath("firetree")
  3. local SAPLING_TIME_MIN = 5*60
  4. local SAPLING_TIME_MAX = 10*60
  5. -- Localize for performance.
  6. local math_random = math.random
  7. local FIRETREE_SCHEMATICS = {
  8. "firetree_tree1.mts",
  9. "firetree_tree2.mts",
  10. "firetree_tree3.mts",
  11. "firetree_tree4.mts",
  12. "firetree_tree5.mts",
  13. "firetree_tree6.mts",
  14. }
  15. minetest.register_node("firetree:leaves", {
  16. description = "Firetree Leaves",
  17. drawtype = "allfaces_optional",
  18. waving = 1,
  19. tiles = {"firetree_leaves.png"},
  20. paramtype = "light",
  21. groups = utility.dig_groups("leaves", {
  22. leafdecay = 3,
  23. flammable = 2,
  24. leaves = 1,
  25. }),
  26. drop = {
  27. max_items = 1,
  28. items = {
  29. -- You sometimes get a real apple.
  30. {items = {'basictrees:tree_apple'}, rarity = 22},
  31. {items = {'firetree:sapling'}, rarity = 18},
  32. {items = {"default:stick"}, rarity = 6},
  33. -- Player will get leaves only if he gets nothing else; this is because 'max_items' is 1.
  34. {items = {'firetree:leaves'}},
  35. }
  36. },
  37. sounds = default.node_sound_leaves_defaults(),
  38. movement_speed_multiplier = default.SLOW_SPEED,
  39. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  40. on_timer = enhanced_leafdecay.make_leaf_nodetimer({tree="firetree:trunk"}),
  41. })
  42. minetest.register_node("firetree:whitewood", {
  43. description = "Baked Firetree Planks",
  44. paramtype2 = "facedir",
  45. place_param2 = 0,
  46. tiles = {"firetree_whitewood.png"},
  47. groups = utility.dig_groups("wood", {flammable=2, wood=1, wood_light=1}),
  48. sounds = default.node_sound_wood_defaults(),
  49. })
  50. minetest.register_node("firetree:firewood", {
  51. description = "Raw Firetree Planks",
  52. paramtype2 = "facedir",
  53. place_param2 = 0,
  54. tiles = {"firetree_firewood.png"},
  55. groups = utility.dig_groups("wood", {flammable=2, wood=1, wood_dark=1}),
  56. sounds = default.node_sound_wood_defaults(),
  57. })
  58. minetest.register_craft({
  59. type = "cooking",
  60. output = "firetree:whitewood",
  61. recipe = "firetree:firewood",
  62. })
  63. stairs.register_stair_and_slab(
  64. "firetree_whitewood",
  65. "firetree:whitewood",
  66. {choppy=2, oddly_breakable_by_hand=2, flammable=2},
  67. {"firetree_whitewood.png"},
  68. "Baked Firewood",
  69. default.node_sound_wood_defaults()
  70. )
  71. stairs.register_stair_and_slab(
  72. "firetree_firewood",
  73. "firetree:firewood",
  74. {choppy=2, oddly_breakable_by_hand=2, flammable=2},
  75. {"firetree_firewood.png"},
  76. "Raw Firewood",
  77. default.node_sound_wood_defaults()
  78. )
  79. minetest.register_craft({
  80. output = "firetree:firewood 4",
  81. type = "shapeless",
  82. recipe = {"firetree:trunk"},
  83. })
  84. minetest.register_node("firetree:fruit", {
  85. description = "Fruit of the Firetree\n\nProtects from extreme heat when consumed.",
  86. drawtype = "plantlike",
  87. tiles = {"firetree_fruit.png"},
  88. inventory_image = "firetree_fruit.png",
  89. paramtype = "light",
  90. sunlight_propagates = true,
  91. walkable = false,
  92. selection_box = {
  93. type = "fixed",
  94. fixed = {-0.2, -0.5, -0.2, 0.2, 0, 0.2}
  95. },
  96. groups = utility.dig_groups("item", {flammable=2, leafdecay=3, leafdecay_drop=1, foodrot=1}),
  97. sounds = default.node_sound_leaves_defaults(),
  98. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  99. on_use = function(itemstack, user, pointed_thing)
  100. if user and user:is_player() then
  101. local name = user:get_player_name()
  102. if heatdamage then
  103. heatdamage.immunize_player(name, 10)
  104. --minetest.sound_play("hunger_eat", {to_player = name, gain = 0.7})
  105. ambiance.sound_play("hunger_eat", user:get_pos(), 0.7, 10)
  106. itemstack:take_item()
  107. return itemstack
  108. end
  109. end
  110. end,
  111. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  112. on_timer = enhanced_leafdecay.make_leaf_nodetimer({tree="firetree:trunk"}),
  113. after_dig_node = hb4.fruitregrow.after_dig_node(),
  114. after_place_node = hb4.fruitregrow.after_place_node(),
  115. on_finish_collapse = hb4.fruitregrow.on_finish_collapse(),
  116. })
  117. local can_grow = function(pos)
  118. -- Firetree does not grow in other dimensions.
  119. if rc.current_realm_at_pos(pos) ~= "overworld" then
  120. return false
  121. end
  122. -- Reduced chance to grow if cold/ice nearby.
  123. local below = {x=pos.x, y=pos.y-1, z=pos.z}
  124. local cold = minetest.find_nodes_in_area(vector.subtract(below, 3), vector.add(below, 3), "group:cold")
  125. if #cold > math_random(0, 196) then
  126. return false
  127. end
  128. local node_under = minetest.get_node_or_nil(below)
  129. if not node_under then
  130. return false
  131. end
  132. local name_under = node_under.name
  133. local is_soil = minetest.get_item_group(name_under, "nether_soil")
  134. if is_soil == 0 then
  135. return false
  136. end
  137. local light_level = minetest.get_node_light(pos)
  138. if not light_level or light_level < 11 then
  139. return false
  140. end
  141. return true
  142. end
  143. local on_place = function(itemstack, placer, pointed_thing)
  144. local n = "firetree:sapling"
  145. local minp = {x=-3, y=0, z=-3}
  146. local maxp = {x=3, y=5, z=3}
  147. itemstack = default.sapling_on_place(itemstack, placer, pointed_thing, n, minp, maxp, 4)
  148. return itemstack
  149. end
  150. local on_construct = function(pos)
  151. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  152. end
  153. local on_timer = function(pos, elapsed)
  154. if mtflower.can_grow(pos) then
  155. if mtflower.try_grow(pos, "firetree:trunk", "firetree:leaves", "glowstone:minerals", "glowstone:minerals") then
  156. return
  157. end
  158. end
  159. if not can_grow(pos) then
  160. minetest.get_node_timer(pos):start(math_random(SAPLING_TIME_MIN, SAPLING_TIME_MAX))
  161. return
  162. end
  163. minetest.set_node(pos, {name='air'}) -- Remove sapling first.
  164. local schempath = firetree.modpath .. "/schematics/"
  165. local path = schempath .. FIRETREE_SCHEMATICS[math_random(#FIRETREE_SCHEMATICS)]
  166. minetest.place_schematic(vector.add(pos, {x=-2, y=0, z=-2}), path, "random", nil, false)
  167. end
  168. firetree.create_firetree_on_vmanip = function(vm, pos)
  169. local schempath = firetree.modpath .. "/schematics/"
  170. local path = schempath .. FIRETREE_SCHEMATICS[math_random(#FIRETREE_SCHEMATICS)]
  171. minetest.place_schematic_on_vmanip(vm, vector.add(pos, {x=-2, y=0, z=-2}), path, "random", nil, false)
  172. end
  173. firetree.create_firetree = function(pos)
  174. local schempath = firetree.modpath .. "/schematics/"
  175. local path = schempath .. FIRETREE_SCHEMATICS[math_random(#FIRETREE_SCHEMATICS)]
  176. minetest.place_schematic(vector.add(pos, {x=-2, y=0, z=-2}), path, "0", nil, false)
  177. end
  178. minetest.register_node("firetree:sapling", {
  179. description = "Firetree Seedling\n\nMay grow in deep or hot places.\nWill also grow on the surface.\nGrows firefruit.",
  180. drawtype = "plantlike",
  181. tiles = {"firetree_sapling.png"},
  182. inventory_image = "firetree_sapling.png",
  183. wield_image = "firetree_sapling.png",
  184. paramtype = "light",
  185. sunlight_propagates = true,
  186. walkable = false,
  187. selection_box = {
  188. type = "fixed",
  189. fixed = {-0.3, -0.5, -0.3, 0.3, 0.35, 0.3}
  190. },
  191. groups = utility.dig_groups("plant", {flammable=2, attached_node=1, sapling=1}),
  192. sounds = default.node_sound_leaves_defaults(),
  193. on_timer = on_timer,
  194. on_place = on_place,
  195. on_construct = on_construct,
  196. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  197. })
  198. minetest.register_node("firetree:trunk", {
  199. drawtype = "nodebox",
  200. paramtype = "light",
  201. node_box = {
  202. type = "fixed",
  203. fixed = basictrees.trunk_nodebox,
  204. },
  205. description = "Firetree",
  206. tiles = {"firetree_trunktop.png", "firetree_trunktop.png", "firetree_trunkside.png"},
  207. paramtype2 = "facedir",
  208. groups = utility.dig_groups("tree", {tree=1, flammable=2}),
  209. sounds = default.node_sound_wood_defaults(),
  210. on_place = minetest.rotate_node,
  211. movement_speed_multiplier = default.NORM_SPEED,
  212. on_destruct = enhanced_leafdecay.make_tree_destructor({
  213. leaves = {
  214. "firetree:leaves",
  215. "firetree:fruit",
  216. "group:dry_leaves",
  217. },
  218. }),
  219. })
  220. minetest.register_alias("nethertree:tree", "firetree:trunk")
  221. minetest.register_alias("nethertree:leaves", "firetree:leaves")
  222. minetest.register_alias("nethertree:sapling", "firetree:sapling")
  223. minetest.register_alias("nethertree:firewood", "firetree:firewood")
  224. minetest.register_alias("nethertree:wood", "firetree:whitewood")
  225. minetest.register_alias("nethertree:fruit", "firetree:fruit")