init.lua 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. local FIRETREE_SCHEMATICS = {
  6. "firetree_tree1.mts",
  7. "firetree_tree2.mts",
  8. "firetree_tree3.mts",
  9. "firetree_tree4.mts",
  10. "firetree_tree5.mts",
  11. "firetree_tree6.mts",
  12. }
  13. minetest.register_node("firetree:leaves", {
  14. description = "Firetree Leaves",
  15. drawtype = "allfaces_optional",
  16. waving = 1,
  17. visual_scale = 1.3,
  18. tiles = {"firetree_leaves.png"},
  19. paramtype = "light",
  20. groups = utility.dig_groups("leaves", {
  21. leafdecay = 3,
  22. flammable = 2,
  23. leaves = 1,
  24. }),
  25. drop = {
  26. max_items = 1,
  27. items = {
  28. -- You sometimes get a real apple.
  29. {items = {'basictrees:tree_apple'}, rarity = 22},
  30. {items = {'firetree:sapling'}, rarity = 18},
  31. {items = {"default:stick"}, rarity = 6},
  32. -- Player will get leaves only if he gets nothing else; this is because 'max_items' is 1.
  33. {items = {'firetree:leaves'}},
  34. }
  35. },
  36. sounds = default.node_sound_leaves_defaults(),
  37. movement_speed_multiplier = default.SLOW_SPEED,
  38. on_construct = enhanced_leafdecay.make_leaf_constructor({}),
  39. on_timer = enhanced_leafdecay.make_leaf_nodetimer({tree="firetree:trunk"}),
  40. })
  41. minetest.register_node("firetree:whitewood", {
  42. description = "Baked Firetree Planks",
  43. paramtype2 = "facedir",
  44. place_param2 = 0,
  45. tiles = {"firetree_whitewood.png"},
  46. groups = utility.dig_groups("wood", {flammable=2, wood=1, wood_light=1}),
  47. sounds = default.node_sound_wood_defaults(),
  48. })
  49. minetest.register_node("firetree:firewood", {
  50. description = "Raw Firetree Planks",
  51. paramtype2 = "facedir",
  52. place_param2 = 0,
  53. tiles = {"firetree_firewood.png"},
  54. groups = utility.dig_groups("wood", {flammable=2, wood=1, wood_dark=1}),
  55. sounds = default.node_sound_wood_defaults(),
  56. })
  57. minetest.register_craft({
  58. type = "cooking",
  59. output = "firetree:whitewood",
  60. recipe = "firetree:firewood",
  61. })
  62. stairs.register_stair_and_slab(
  63. "firetree_whitewood",
  64. "firetree:whitewood",
  65. {choppy=2, oddly_breakable_by_hand=2, flammable=2},
  66. {"firetree_whitewood.png"},
  67. "Baked Firewood",
  68. default.node_sound_wood_defaults()
  69. )
  70. stairs.register_stair_and_slab(
  71. "firetree_firewood",
  72. "firetree:firewood",
  73. {choppy=2, oddly_breakable_by_hand=2, flammable=2},
  74. {"firetree_firewood.png"},
  75. "Raw Firewood",
  76. default.node_sound_wood_defaults()
  77. )
  78. minetest.register_craft({
  79. output = "firetree:firewood 4",
  80. type = "shapeless",
  81. recipe = {"firetree:trunk"},
  82. })
  83. minetest.register_node("firetree:fruit", {
  84. description = "Fruit of the Firetree\n\nProtects from extreme heat when consumed.",
  85. drawtype = "plantlike",
  86. --visual_scale = 1.0,
  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:getpos(), 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. visual_scale = 1.0,
  182. tiles = {"firetree_sapling.png"},
  183. inventory_image = "firetree_sapling.png",
  184. wield_image = "firetree_sapling.png",
  185. paramtype = "light",
  186. sunlight_propagates = true,
  187. walkable = false,
  188. selection_box = {
  189. type = "fixed",
  190. fixed = {-0.3, -0.5, -0.3, 0.3, 0.35, 0.3}
  191. },
  192. groups = utility.dig_groups("plant", {flammable=2, attached_node=1, sapling=1}),
  193. sounds = default.node_sound_leaves_defaults(),
  194. on_timer = on_timer,
  195. on_place = on_place,
  196. on_construct = on_construct,
  197. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  198. })
  199. minetest.register_node("firetree:trunk", {
  200. drawtype = "nodebox",
  201. paramtype = "light",
  202. node_box = {
  203. type = "fixed",
  204. fixed = basictrees.trunk_nodebox,
  205. },
  206. description = "Firetree",
  207. tiles = {"firetree_trunktop.png", "firetree_trunktop.png", "firetree_trunkside.png"},
  208. paramtype2 = "facedir",
  209. groups = utility.dig_groups("tree", {tree=1, flammable=2}),
  210. sounds = default.node_sound_wood_defaults(),
  211. on_place = minetest.rotate_node,
  212. movement_speed_multiplier = default.NORM_SPEED,
  213. on_destruct = enhanced_leafdecay.make_tree_destructor({
  214. leaves = {
  215. "firetree:leaves",
  216. "firetree:fruit",
  217. "group:dry_leaves",
  218. },
  219. }),
  220. })
  221. minetest.register_alias("nethertree:tree", "firetree:trunk")
  222. minetest.register_alias("nethertree:leaves", "firetree:leaves")
  223. minetest.register_alias("nethertree:sapling", "firetree:sapling")
  224. minetest.register_alias("nethertree:firewood", "firetree:firewood")
  225. minetest.register_alias("nethertree:wood", "firetree:whitewood")
  226. minetest.register_alias("nethertree:fruit", "firetree:fruit")