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