init.lua 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. if not minetest.global_exists("nethervine") then nethervine = {} end
  2. nethervine.modpath = minetest.get_modpath("nethervine")
  3. -- Localize for performance.
  4. local math_random = math.random
  5. dofile(nethervine.modpath .. "/functions.lua")
  6. nethervine.vine_on_construct = function(pos)
  7. local timer = minetest.get_node_timer(pos)
  8. timer:start(math_random(60*3, 60*6))
  9. end
  10. nethervine.vine_on_timer = function(pos, elapsed)
  11. return nethervine.grow(pos, minetest.get_node(pos))
  12. end
  13. nethervine.grow = function(pos, node)
  14. local timer = minetest.get_node_timer(pos)
  15. pos.y = pos.y + 1
  16. local name = minetest.get_node(pos).name
  17. if name ~= "rackstone:dauthsand_stable" and name ~= "rackstone:nether_grit" then
  18. return
  19. end
  20. local have_heat = false
  21. if minetest.find_node_near(pos, 4, "group:flame") or
  22. minetest.find_node_near(pos, 5, "group:lava") then
  23. have_heat = true
  24. end
  25. if not have_heat then
  26. return
  27. end
  28. local have_minerals = false
  29. if minetest.find_node_near(pos, 4, "glowstone:minerals") then
  30. have_minerals = true
  31. end
  32. pos.y = pos.y - 1
  33. local height = 0
  34. while node.name == "nethervine:vine" and height < 4 do
  35. height = height - 1
  36. pos.y = pos.y - 1
  37. node = minetest.get_node(pos)
  38. end
  39. if height == 4 or node.name ~= "air" then
  40. return
  41. end
  42. minetest.add_node(pos, {name = "nethervine:vine"})
  43. if have_minerals then
  44. timer:start(math_random(60*1, 60*2))
  45. else
  46. timer:start(math_random(60*3, 60*6))
  47. end
  48. end
  49. function nethervine.on_grass_timer(pos, elapsed)
  50. -- Dry out nethergrass if too near lava.
  51. if minetest.find_node_near(pos, 3, "group:lava") then
  52. minetest.swap_node(pos, {name="nether:grass_dried"})
  53. return false
  54. end
  55. return nethervine.on_flora_timer(pos, elapsed)
  56. end
  57. local eat_function = minetest.item_eat(0)
  58. function nethervine.eat_dried_grass(itemstack, user, pt)
  59. if not user or not user:is_player() then return end
  60. if user:get_hp() == 0 then return end
  61. -- Heal 5000 hp total.
  62. hunger.apply_hot(user:get_player_name(), "avysium", {heal=1000, time=5})
  63. return eat_function(itemstack, user, pt)
  64. end
  65. function nethervine.eat_grass(itemstack, user, pt)
  66. if not user or not user:is_player() then return end
  67. local pname = user:get_player_name()
  68. local msg = "# Server: <" .. rename.gpn(pname) .. "> ate Avysium. Desperate!"
  69. hb4.delayed_harm({name=pname, step=2, min=1*500, max=3*500, msg=msg, poison=true})
  70. return eat_function(itemstack, user, pt)
  71. end
  72. if not nethervine.registered then
  73. minetest.register_node("nethervine:vine", {
  74. description = "Wormroot",
  75. drawtype = "plantlike",
  76. tiles = {"nethervine_vine.png"},
  77. inventory_image = "nethervine_vine.png",
  78. wield_image = "nethervine_vine.png",
  79. paramtype = "light",
  80. sunlight_propagates = true,
  81. walkable = false,
  82. selection_box = {
  83. type = "fixed",
  84. fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
  85. },
  86. climbable = true,
  87. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  88. drop = "",
  89. shears_drop = true,
  90. flowerpot_drop = "nethervine:vine",
  91. -- Nethervines shall not be flammable. They often generate next to lava.
  92. groups = utility.dig_groups("plant", {
  93. hanging_node = 1,
  94. }),
  95. sounds = default.node_sound_leaves_defaults(),
  96. on_construct = function(...)
  97. return nethervine.vine_on_construct(...)
  98. end,
  99. on_timer = function(...)
  100. return nethervine.vine_on_timer(...)
  101. end,
  102. })
  103. for i = 1, 3 do
  104. minetest.register_node(":nether:grass_" .. i, {
  105. description = "Avysium Herb",
  106. drawtype = "plantlike",
  107. waving = 1,
  108. tiles = {"nethergrass_" .. i .. ".png"},
  109. inventory_image = "nethergrass_3.png",
  110. wield_image = "nethergrass_3.png",
  111. paramtype = "light",
  112. paramtype2 = "meshoptions",
  113. place_param2 = 2,
  114. sunlight_propagates = true,
  115. walkable = false,
  116. buildable_to = true,
  117. drop = "nether:grass",
  118. flowerpot_drop = "nether:grass",
  119. groups = utility.dig_groups("plant", {netherflora = 1, attached_node = 1, not_in_creative_inventory = 1, grass = 1, flammable = 1}),
  120. sounds = default.node_sound_leaves_defaults(),
  121. selection_box = {
  122. type = "fixed",
  123. fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
  124. },
  125. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  126. on_construct = function(...)
  127. return nethervine.on_flora_construct(...)
  128. end,
  129. on_destruct = function(...)
  130. return nethervine.on_flora_destruct(...)
  131. end,
  132. on_timer = function(...)
  133. -- Call custom function which adds the conversion to dried grass.
  134. return nethervine.on_grass_timer(...)
  135. end,
  136. on_punch = function(...)
  137. return nethervine.on_flora_punch(...)
  138. end,
  139. })
  140. end
  141. -- This node is not meant to be placed in the world.
  142. -- Instead, placing it causes 1 of several other nodetypes to be placed instead.
  143. minetest.register_node(":nether:grass", {
  144. description = "Avysium Herb",
  145. drawtype = "plantlike",
  146. waving = 1,
  147. tiles = {"nethergrass_3.png"},
  148. -- Use texture of a taller grass stage in inventory
  149. inventory_image = "nethergrass_3.png",
  150. wield_image = "nethergrass_3.png",
  151. paramtype = "light",
  152. paramtype2 = "meshoptions",
  153. place_param2 = 2,
  154. sounds = default.node_sound_leaves_defaults(),
  155. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  156. flowerpot_insert = {"nether:grass_1", "nether:grass_2", "nether:grass_3"},
  157. -- Zero-width selection box.
  158. selection_box = {
  159. type = "fixed",
  160. fixed = {-0.5, -0.5, -0.5, 0.5, -0.5, 0.5},
  161. },
  162. on_place = function(itemstack, placer, pt)
  163. -- place a random grass node
  164. local stack = ItemStack("nether:grass_" .. math_random(1,3))
  165. local ret = minetest.item_place(stack, placer, pt)
  166. return ItemStack("nether:grass " .. itemstack:get_count() - (1 - ret:get_count()))
  167. end,
  168. on_use = function(...)
  169. return nethervine.eat_grass(...)
  170. end,
  171. })
  172. -- Dried nethergrass has edible property!
  173. minetest.register_node(":nether:grass_dried", {
  174. description = "Clarified Avysium Herb",
  175. drawtype = "plantlike",
  176. waving = 1,
  177. tiles = {"nethergrass_dried.png"},
  178. -- Use texture of a taller grass stage in inventory
  179. inventory_image = "nethergrass_dried.png",
  180. wield_image = "nethergrass_dried.png",
  181. paramtype = "light",
  182. paramtype2 = "meshoptions",
  183. place_param2 = 2,
  184. walkable = false,
  185. sounds = default.node_sound_leaves_defaults(),
  186. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  187. groups = utility.dig_groups("plant", {netherflora = 1, attached_node = 1, not_in_creative_inventory = 1, grass = 1, flammable = 3}),
  188. selection_box = {
  189. type = "fixed",
  190. fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
  191. },
  192. on_use = function(...)
  193. return nethervine.eat_dried_grass(...)
  194. end,
  195. })
  196. -- This particular flower does not grow!
  197. minetest.register_node(":nether:glowflower", {
  198. description = "Nevermore Flower",
  199. drawtype = "plantlike",
  200. --waving = 1, -- Plant does not respond to wind.
  201. tiles = {"nether_glowflower.png"},
  202. inventory_image = "nether_glowflower.png",
  203. wield_image = "nether_glowflower.png",
  204. paramtype = "light",
  205. walkable = false,
  206. sounds = default.node_sound_leaves_defaults(),
  207. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  208. groups = utility.dig_groups("plant", {attached_node = 1, not_in_creative_inventory = 1, flammable = 3}),
  209. light_source = 10,
  210. drop = {
  211. max_items = 1,
  212. items = {
  213. {
  214. rarity = 3,
  215. tools = {"moreores:sword_silver"},
  216. items = {"farming:cotton 4", "farming:string"},
  217. },
  218. {
  219. rarity = 5,
  220. items = {"farming:cotton 2"},
  221. },
  222. {
  223. rarity = 1,
  224. items = {"farming:cotton"},
  225. },
  226. },
  227. },
  228. shears_drop = true, -- Drop self.
  229. flowerpot_drop = "nether:glowflower",
  230. selection_box = {
  231. type = "fixed",
  232. fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
  233. },
  234. })
  235. minetest.register_craft({
  236. type = "fuel",
  237. recipe = "nethervine:vine",
  238. burntime = 1,
  239. })
  240. local c = "nethervine:core"
  241. local f = nethervine.modpath .. "/init.lua"
  242. reload.register_file(c, f, false)
  243. nethervine.registered = true
  244. end